AmendHub

Download:

jcs

/

subtext

/

amendments

/

23

util: Add ordinal


jcs made amendment 23 over 2 years ago
--- util.c Wed Dec 8 14:37:59 2021 +++ util.c Fri Dec 10 16:43:36 2021 @@ -167,6 +167,24 @@ strlcpy(char *dst, const char *src, size_t dsize) return (src - osrc - 1); } +char * +ordinal(unsigned short n) +{ + static char ordbuf[8]; + + switch (n) { + case 1: + return "1st"; + case 2: + return "2nd"; + case 3: + return "3rd"; + default: + sprintf(ordbuf, "%dth", n); + return ordbuf; + } +} + /* * BSD err(3) and warn(3) functions, must call err_init() before using */ --- util.h Wed Dec 8 14:35:51 2021 +++ util.h Fri Dec 10 16:43:59 2021 @@ -63,6 +63,7 @@ char *xstrdup(const char *); short getline(char *str, size_t len, char **ret); size_t strlcpy(char *dst, const char *src, size_t dsize); +char *ordinal(unsigned short n); #if 0 /* from strnatcmp.c */ int strnatcmp(char const *a, char const *b);