26 lines
823 B
C

/* C functions that return strings, for programs/cstr-return.flan. Each one is
* a way a real library hands text back, and each has a failure the copy at
* the boundary has to survive. */
#include <stddef.h>
#include <stdio.h>
#include <string.h>
/* The library's static buffer, overwritten by the next call: TextFormat and
* GetGamepadName's shape. */
const char *cret_count(int n) {
static char buf[32];
snprintf(buf, sizeof buf, "count %d", n);
return buf;
}
/* A pointer into the argument: GetFileName's shape. The argument is the
* wrapper's own NUL-terminated copy, which is gone once the wrapper returns. */
const char *cret_after_slash(const char *path) {
const char *s = strrchr(path, '/');
return s == NULL ? path : s + 1;
}
/* No text at all. */
const char *cret_nothing(void) { return NULL; }