diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-02-04 17:12:49 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-02-04 17:12:49 -0500 |
commit | 6e9c7df2b4fc0b241b7a03c23aabbe820fb68b9f (patch) | |
tree | 950ac4f91c782bedb0e2be8e437ed826b9168549 | |
parent | 88ab03ef5d6530ccd9ec1d245a1836360e7e78f6 (diff) |
add READMEgetprogname
-rw-r--r-- | README.md | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..d445efb --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +getprogname +=========== + +This liblet includes two functions, `getprogname()` and `get_program_name()`. +The former is an implementation of the BSD function of the same name. The +latter is a variant that takes a buffer to fill along with its size as +arguments, rather than relying on a static variable. This makes it thread safe. + +SYNOPSIS +======== + + #include "getprogname.h" + + char *get_program_name(size_t n, char buf[static n]); + char *getprogname(void); + +DESCRIPTION +=========== + +These functions provide the current process's name as derived from the original +contents of `argv[0]`. + +`getprogname()` returns a pointer to a static buffer, which may overwritten by +future calls to `getprogname()`. + +`get_program_name()` will fill the buffer pointed to by `buf`, up to `n` bytes, +with the current process name. The declaration syntax requires a compiler +supporting at least C99, and allows the compiler to perform static analysis +on the size of `buf` to ensure that it is at least `n` bytes in size. + +RETURN VALUE +============ + +On failure, both functions return `NULL`. On success, `getprogname()` returns +a pointer to a static buffer containing the current program name; +`get_program_name()` returns a pointer to `buf`. |