---
name: "fmt"
section: "3"
platform: "macos"
package: "ksh"
version: "42"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/fmt/3"
---

# fmt(3)

string formatting routines

## NAME

fmt - string formatting routines

## SYNOPSIS

```
#include <ast.h>
#include <ls.h>
char*      fmtbase(long number, int base, int prefix);
char*      fmtdev(struct stat* st);
char*      fmtelapsed(unsigned long count, int persec)
char*      fmterror(int errno);
char*      fmtesc(const char* string);
char*      fmtfs(struct stat* st);
char*      fmtgid(int gid);
char*      fmtmatch(const char* re);
char*      fmtmode(int mode, int external);
char*      fmtperm(int perm);
char*      fmtre(const char* pattern);
char*      fmtsignal(int sig);
char*      fmttime(const char* format, time_t tm);
char*      fmtuid(int uid);
```

## DESCRIPTION

*These routines return a pointer to a formatted string for various numeric* *and string entities.* *Some routines may cache information to speed up the next call.* *Most of the routines return a pointer to a private buffer, the* *contents of which are overwritten on the next call to that routine.* *Most* $1$2fmtfmtfmtfmtfmtfmtfmtfmt routines have a corresponding $1$2strstrstrstrstrstrstrstr routine that converts in the other direction. There is nothing spectacular about this collection other than that it provides a single place where the exact format is spelled out.

$1$2fmtbasefmtbasefmtbasefmtbasefmtbasefmtbasefmtbasefmtbase formats a base *base* representation for *number*. If *prefix != 0* then the base prefix is included in the formatted string. If *number == 0* or *base == 0* then the output is signed base 10.

$1$2fmtdevfmtdevfmtdevfmtdevfmtdevfmtdevfmtdevfmtdev returns the device handle name specified by the $1$2statstatstatstatstatstatstatstat structure *st*. This is the device information displayed by *ls -l*.

$1$2fmtelapsedfmtelapsedfmtelapsedfmtelapsedfmtelapsedfmtelapsedfmtelapsedfmtelapsed formats the elapsed time for *(count/persec)* seconds. The two largest time units are used, limiting the return value length to at most 6 characters. The units are:

- **s**

  seconds

- **m**

  minutes

- **h**

  hours

- **days**

  - **weeks**

  - **M**

  months

- **Y**

  years

- **S**

  scores

$1$2fmterrorfmterrorfmterrorfmterrorfmterrorfmterrorfmterrorfmterror returns the system error message text for the error number *errno*.

$1$2fmtescfmtescfmtescfmtescfmtescfmtescfmtescfmtesc formats non-ASCII characters in *string* into C-style **\\** sequences. These sequences are understood by $1$2chrescchrescchrescchrescchrescchrescchrescchresc and $1$2chrtoichrtoichrtoichrtoichrtoichrtoichrtoichrtoi

$1$2fmtfsfmtfsfmtfsfmtfsfmtfsfmtfsfmtfsfmtfs returns the file system type name corresponding to the $1$2statstatstatstatstatstatstatstat structure *st*.

$1$2fmtgidfmtgidfmtgidfmtgidfmtgidfmtgidfmtgidfmtgid returns the group name for *gid*.

$1$2fmtmatchfmtmatchfmtmatchfmtmatchfmtmatchfmtmatchfmtmatchfmtmatch returns the $1$2strmatchstrmatchstrmatchstrmatchstrmatchstrmatchstrmatchstrmatch equivalent pattern for the regular expression pattern *re*. 0 is returned for invalid *re*.

$1$2fmtmodefmtmodefmtmodefmtmodefmtmodefmtmodefmtmodefmtmode returns the *ls -l* mode string for the file mode bits in *mode*. If *external != 0* then  *mode* is [*modecanon*(3)](/modecanon/3.md) canonical.

$1$2fmtpermfmtpermfmtpermfmtpermfmtpermfmtpermfmtpermfmtperm returns the *chmod* permission string for the permission bits in *perm*.

$1$2fmtrefmtrefmtrefmtrefmtrefmtrefmtrefmtre returns the regular expression equivalent pattern for the $1$2strmatchstrmatchstrmatchstrmatchstrmatchstrmatchstrmatchstrmatch pattern *pattern*. 0 is returned for invalid *pattern*.

$1$2fmtsignalfmtsignalfmtsignalfmtsignalfmtsignalfmtsignalfmtsignalfmtsignal returns the signal name, sans $1$2SIGSIGSIGSIGSIGSIGSIGSIG for the signal number  *sig*. If *sig \< 0* then the description text for *-sig* is returned.

$1$2fmttimefmttimefmttimefmttimefmttimefmttimefmttimefmttime returns the results of *tmfmt(buf,sizeof(buf),format,tm)* in the private buffer *buf*.

$1$2fmtuidfmtuidfmtuidfmtuidfmtuidfmtuidfmtuidfmtuid returns the user name for *uid*.

## SEE ALSO

[modecanon(3)](/modecanon/3.md), str(3)
