SYSTEM_DATA_TYPES(7) Linux Programmer's Manual SYSTEM_DATA_TYPES(7) NAME system_data_types - overview of system data types DESCRIPTION aiocb Include: <aio.h>. struct aiocb { int aio_fildes; /* File descriptor */ off_t aio_offset; /* File offset */ volatile void *aio_buf; /* Location of buffer */ size_t aio_nbytes; /* Length of transfer */ int aio_reqprio; /* Request priority offset */ struct sigevent aio_sigevent; /* Signal number and value */ int aio_lio_opcode;/* Operation to be performed */ }; For further information about this structure, see aio(7). Conforming to: POSIX.1-2001 and later. See also: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3), aio_return(3), aio_suspend(3), aio_write(3), lio_listio(3) clock_t Include: <time.h> or <sys/types.h>. Alternatively, <sys/time.h>. Used for system time in clock ticks or CLOCKS_PER_SEC (defined in <time.h>). According to POSIX, it shall be an integer type or a real-floating type. Conforming to: C99 and later; POSIX.1-2001 and later. See also: times(2), clock(3) clockid_t Include: <sys/types.h>. Alternatively, <time.h>. Used for clock ID type in the clock and timer functions. Ac- cording to POSIX, it shall be defined as an arithmetic type. Conforming to: POSIX.1-2001 and later. See also: clock_adjtime(2), clock_getres(2), clock_nanosleep(2), timer_create(2), clock_getcpuclockid(3) dev_t Include: <sys/types.h>. Alternatively, <sys/stat.h>. Used for device IDs. According to POSIX, it shall be an integer type. For further details of this type, see makedev(3). Conforming to: POSIX.1-2001 and later. See also: mknod(2), stat(2) div_t Include: <stdlib.h>. typedef struct { int quot; /* Quotient */ int rem; /* Remainder */ } div_t; It is the type of the value returned by the div(3) function. Conforming to: C99 and later; POSIX.1-2001 and later. See also: div(3) double_t Include: <math.h>. The implementation's most efficient floating type at least as wide as double. Its type depends on the value of the macro FLT_EVAL_METHOD (defined in <float.h>): 0 double_t is double. 1 double_t is double. 2 double_t is long double. For other values of FLT_EVAL_METHOD, the type of double_t is im- plementation-defined. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the float_t type in this page. fd_set Include: <sys/select.h>. Alternatively, <sys/time.h>. A structure type that can represent a set of file descriptors. According to POSIX, the maximum number of file descriptors in an fd_set structure is the value of the macro FD_SETSIZE. Conforming to: POSIX.1-2001 and later. See also: select(2) fenv_t Include: <fenv.h>. This type represents the entire floating-point environment, in- cluding control modes and status flags; for further details, see fenv(3). Conforming to: C99 and later; POSIX.1-2001 and later. See also: fenv(3) fexcept_t Include: <fenv.h>. This type represents the floating-point status flags collec- tively; for further details see fenv(3). Conforming to: C99 and later; POSIX.1-2001 and later. See also: fenv(3) FILE Include: <stdio.h>. Alternatively, <wchar.h>. An object type used for streams. Conforming to: C99 and later; POSIX.1-2001 and later. See also: fclose(3), flockfile(3), fopen(3), fprintf(3), fread(3), fscanf(3), stdin(3), stdio(3) float_t Include: <math.h>. The implementation's most efficient floating type at least as wide as float. Its type depends on the value of the macro FLT_EVAL_METHOD (defined in <float.h>): 0 float_t is float. 1 float_t is double. 2 float_t is long double. For other values of FLT_EVAL_METHOD, the type of float_t is im- plementation-defined. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the double_t type in this page. gid_t Include: <sys/types.h>. Alternatively, <grp.h>, <pwd.h>, <sig- nal.h>, <stropts.h>, <sys/ipc.h>, <sys/stat.h>, or <unistd.h>. A type used to hold group IDs. According to POSIX, this shall be an integer type. Conforming to: POSIX.1-2001 and later. See also: chown(2), getgid(2), getegid(2), getgroups(2), getres- gid(2), getgrnam(2), credentials(7) id_t Include: <sys/types.h>. Alternatively, <sys/resource.h>. A type used to hold a general identifier. According to POSIX, this shall be an integer type that can be used to contain a pid_t, uid_t, or gid_t. Conforming to: POSIX.1-2001 and later. See also: getpriority(2), waitid(2) imaxdiv_t Include: <inttypes.h>. typedef struct { intmax_t quot; /* Quotient */ intmax_t rem; /* Remainder */ } imaxdiv_t; It is the type of the value returned by the imaxdiv(3) function. Conforming to: C99 and later; POSIX.1-2001 and later. See also: imaxdiv(3) intmax_t Include: <stdint.h>. Alternatively, <inttypes.h>. A signed integer type capable of representing any value of any signed integer type supported by the implementation. According to the C language standard, it shall be capable of storing val- ues in the range [INTMAX_MIN, INTMAX_MAX]. The macro INTMAX_C() expands its argument to an integer constant of type intmax_t. The length modifier for intmax_t for the printf(3) and the scanf(3) families of functions is j; resulting commonly in %jd or %ji for printing intmax_t values. Conforming to: C99 and later; POSIX.1-2001 and later. Bugs: intmax_t is not large enough to represent values of type __int128 in implementations where __int128 is defined and long long is less than 128 bits wide. See also: the uintmax_t type in this page. intN_t Include: <stdint.h>. Alternatively, <inttypes.h>. int8_t, int16_t, int32_t, int64_t A signed integer type of a fixed width of exactly N bits, N be- ing the value specified in its type name. According to the C language standard, they shall be capable of storing values in the range [INTN_MIN, INTN_MAX], substituting N by the appropri- ate number. According to POSIX, int8_t, int16_t, and int32_t are required; int64_t is only required in implementations that provide integer types with width 64; and all other types of this form are op- tional. The length modifiers for the intN_t types for the printf(3) fam- ily of functions are expanded by macros of the forms PRIdN and PRIiN (defined in <inttypes.h>); resulting for example in %"PRId64" or %"PRIi64" for printing int64_t values. The length modifiers for the intN_t types for the scanf(3) family of func- tions are expanded by macros of the forms SCNdN and SCNiN, (de- fined in <inttypes.h>); resulting for example in %"SCNd8" or %"SCNi8" for scanning int8_t values. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the intmax_t, uintN_t, and uintmax_t types in this page. intptr_t Include: <stdint.h>. Alternatively, <inttypes.h>. A signed integer type such that any valid (void *) value can be converted to this type and back. According to the C language standard, it shall be capable of storing values in the range [INTPTR_MIN, INTPTR_MAX]. The length modifier for intptr_t for the printf(3) family of functions is expanded by the macros PRIdPTR and PRIiPTR (defined in <inttypes.h>); resulting commonly in %"PRIdPTR" or %"PRIiPTR" for printing intptr_t values. The length modifier for intptr_t for the scanf(3) family of functions is expanded by the macros SCNdPTR and SCNiPTR, (defined in <inttypes.h>); resulting com- monly in %"SCNdPTR" or %"SCNiPTR" for scanning intptr_t values. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the uintptr_t and void * types in this page. lconv Include: <locale.h>. struct lconv { /* Values in the "C" locale: */ char *decimal_point; /* "." */ char *thousands_sep; /* "" */ char *grouping; /* "" */ char *mon_decimal_point; /* "" */ char *mon_thousands_sep; /* "" */ char *mon_grouping; /* "" */ char *positive_sign; /* "" */ char *negative_sign; /* "" */ char *currency_symbol; /* "" */ char frac_digits; /* CHAR_MAX */ char p_cs_precedes; /* CHAR_MAX */ char n_cs_precedes; /* CHAR_MAX */ char p_sep_by_space; /* CHAR_MAX */ char n_sep_by_space; /* CHAR_MAX */ char p_sign_posn; /* CHAR_MAX */ char n_sign_posn; /* CHAR_MAX */ char *int_curr_symbol; /* "" */ char int_frac_digits; /* CHAR_MAX */ char int_p_cs_precedes; /* CHAR_MAX */ char int_n_cs_precedes; /* CHAR_MAX */ char int_p_sep_by_space; /* CHAR_MAX */ char int_n_sep_by_space; /* CHAR_MAX */ char int_p_sign_posn; /* CHAR_MAX */ char int_n_sign_posn; /* CHAR_MAX */ }; Contains members related to the formatting of numeric values. In the "C" locale, its members have the values shown in the com- ments above. Conforming to: C11 and later; POSIX.1-2001 and later. See also: setlocale(3), localeconv(3), charsets(5), locale(7) ldiv_t Include: <stdlib.h>. typedef struct { long quot; /* Quotient */ long rem; /* Remainder */ } ldiv_t; It is the type of the value returned by the ldiv(3) function. Conforming to: C99 and later; POSIX.1-2001 and later. See also: ldiv(3) lldiv_t Include: <stdlib.h>. typedef struct { long long quot; /* Quotient */ long long rem; /* Remainder */ } lldiv_t; It is the type of the value returned by the lldiv(3) function. Conforming to: C99 and later; POSIX.1-2001 and later. See also: lldiv(3) off_t Include: <sys/types.h>. Alternatively, <aio.h>, <fcntl.h>, <stdio.h>, <sys/mman.h>, <sys/stat.h.h>, or <unistd.h>. Used for file sizes. According to POSIX, this shall be a signed integer type. Versions: <aio.h> and <stdio.h> define off_t since POSIX.1-2008. Conforming to: POSIX.1-2001 and later. Notes: On some architectures, the width of this type can be con- trolled with the feature test macro _FILE_OFFSET_BITS. See also: lseek(2), mmap(2), posix_fadvise(2), pread(2), trun- cate(2), fseeko(3), lockf(3), posix_fallocate(3), fea- ture_test_macros(7) pid_t Include: <sys/types.h>. Alternatively, <fcntl.h>, <sched.h>, <signal.h>, <spawn.h>, <sys/msg.h>, <sys/sem.h>, <sys/shm.h>, <sys/wait.h>, <termios.h>, <time.h>, <unistd.h>, or <utmpx.h>. This type is used for storing process IDs, process group IDs, and session IDs. According to POSIX, it shall be a signed inte- ger type, and the implementation shall support one or more pro- gramming environments where the width of pid_t is no greater than the width of the type long. Conforming to: POSIX.1-2001 and later. See also: fork(2), getpid(2), getppid(2), getsid(2), gettid(2), getpgid(2), kill(2), pidfd_open(2), sched_setscheduler(2), wait- pid(2), sigqueue(3), credentials(7), ptrdiff_t Include: <stddef.h>. Used for a count of elements, and array indices. It is the re- sult of subtracting two pointers. According to the C language standard, it shall be a signed integer type capable of storing values in the range [PTRDIFF_MIN, PTRDIFF_MAX]. The length modifier for ptrdiff_t for the printf(3) and the scanf(3) families of functions is t; resulting commonly in %td or %ti for printing ptrdiff_t values. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the size_t and ssize_t types in this page. regex_t Include: <regex.h>. typedef struct { size_t re_nsub; /* Number of parenthesized subexpressions. */ } regex_t; This is a structure type used in regular expression matching. It holds a compiled regular expression, compiled with reg- comp(3). Conforming to: POSIX.1-2001 and later. See also: regex(3) regmatch_t Include: <regex.h>. typedef struct { regoff_t rm_so; /* Byte offset from start of string to start of substring */ regoff_t rm_eo; /* Byte offset from start of string of the first character after the end of substring */ } regmatch_t; This is a structure type used in regular expression matching. Conforming to: POSIX.1-2001 and later. See also: regexec(3) regoff_t Include: <regex.h>. According to POSIX, it shall be a signed integer type capable of storing the largest value that can be stored in either a ptrdiff_t type or a ssize_t type. Versions: Prior to POSIX.1-2008, the type was capable of storing the largest value that can be stored in either an off_t type or a ssize_t type. Conforming to: POSIX.1-2001 and later. See also: the regmatch_t structure and the ptrdiff_t and ssize_t types in this page. sigevent Include: <signal.h>. Alternatively, <aio.h>, <mqueue.h>, or <time.h>. struct sigevent { int sigev_notify; /* Notification type */ int sigev_signo; /* Signal number */ union sigval sigev_value; /* Signal value */ void (*sigev_notify_function)(union sigval); /* Notification function */ pthread_attr_t *sigev_notify_attributes; /* Notification attributes */ }; For further details about this type, see sigevent(7). Versions: <aio.h> and <time.h> define sigevent since POSIX.1-2008. Conforming to: POSIX.1-2001 and later. See also: timer_create(2), getaddrinfo_a(3), lio_listio(3), mq_notify(3) See also the aiocb structure in this page. siginfo_t Include: <signal.h>. Alternatively, <sys/wait.h>. typedef struct { int si_signo; /* Signal number */ int si_code; /* Signal code */ pid_t si_pid; /* Sending process ID */ uid_t si_uid; /* Real user ID of sending process */ void *si_addr; /* Address of faulting instruction */ int si_status; /* Exit value or signal */ union sigval si_value; /* Signal value */ } siginfo_t; Information associated with a signal. For further details on this structure (including additional, Linux-specific fields), see sigaction(2). Conforming to: POSIX.1-2001 and later. See also: pidfd_send_signal(2), rt_sigqueueinfo(2), sigac- tion(2), sigwaitinfo(2), psiginfo(3) sigset_t Include: <signal.h>. Alternatively, <spawn.h>, or <sys/se- lect.h>. This is a type that represents a set of signals. According to POSIX, this shall be an integer or structure type. Conforming to: POSIX.1-2001 and later. See also: epoll_pwait(2), ppoll(2), pselect(2), sigaction(2), signalfd(2), sigpending(2), sigprocmask(2), sigsuspend(2), sig- waitinfo(2), signal(7) sigval Include: <signal.h>. union sigval { int sigval_int; /* Integer value */ void *sigval_ptr; /* Pointer value */ }; Data passed with a signal. Conforming to: POSIX.1-2001 and later. See also: pthread_sigqueue(3), sigqueue(3), sigevent(7) See also the sigevent structure and the siginfo_t type in this page. size_t Include: <stddef.h> or <sys/types.h>. Alternatively, <aio.h>, <glob.h>, <grp.h>, <iconv.h>, <monetary.h>, <mqueue.h>, <ndbm.h>, <pwd.h>, <regex.h>, <search.h>, <signal.h>, <stdio.h>, <stdlib.h>, <string.h>, <strings.h>, <sys/mman.h>, <sys/msg.h>, <sys/sem.h>, <sys/shm.h>, <sys/socket.h>, <sys/uio.h>, <time.h>, <unistd.h>, <wchar.h>, or <wordexp.h>. Used for a count of bytes. It is the result of the sizeof oper- ator. According to the C language standard, it shall be an un- signed integer type capable of storing values in the range [0, SIZE_MAX]. According to POSIX, the implementation shall support one or more programming environments where the width of size_t is no greater than the width of the type long. The length modifier for size_t for the printf(3) and the scanf(3) families of functions is z; resulting commonly in %zu or %zx for printing size_t values. Versions: <aio.h>, <glob.h>, <grp.h>, <iconv.h>, <mqueue.h>, <pwd.h>, <signal.h>, and <sys/socket.h> define size_t since POSIX.1-2008. Conforming to: C99 and later; POSIX.1-2001 and later. See also: read(2), write(2), fread(3), fwrite(3), memcmp(3), memcpy(3), memset(3), offsetof(3) See also the ptrdiff_t and ssize_t types in this page. ssize_t Include: <sys/types.h>. Alternatively, <aio.h>, <monetary.h>, <mqueue.h>, <stdio.h>, <sys/msg.h>, <sys/socket.h>, <sys/uio.h>, or <unistd.h>. Used for a count of bytes or an error indication. According to POSIX, it shall be a signed integer type capable of storing val- ues at least in the range [-1, SSIZE_MAX], and the implementa- tion shall support one or more programming environments where the width of ssize_t is no greater than the width of the type long. Glibc and most other implementations provide a length modifier for ssize_t for the printf(3) and the scanf(3) families of func- tions, which is z; resulting commonly in %zd or %zi for printing ssize_t values. Although z works for ssize_t on most implemen- tations, portable POSIX programs should avoid using it--for ex- ample, by converting the value to intmax_t and using its length modifier (j). Conforming to: POSIX.1-2001 and later. See also: read(2), readlink(2), readv(2), recv(2), send(2), write(2) See also the ptrdiff_t and size_t types in this page. suseconds_t Include: <sys/types.h>. Alternatively, <sys/select.h>, or <sys/time.h>. Used for time in microseconds. According to POSIX, it shall be a signed integer type capable of storing values at least in the range [-1, 1000000], and the implementation shall support one or more programming environments where the width of suseconds_t is no greater than the width of the type long. Conforming to: POSIX.1-2001 and later. See also: the timeval structure in this page. time_t Include: <time.h> or <sys/types.h>. Alternatively, <sched.h>, <sys/msg.h>, <sys/select.h>, <sys/sem.h>, <sys/shm.h>, <sys/stat.h>, <sys/time.h>, or <utime.h>. Used for time in seconds. According to POSIX, it shall be an integer type. Versions: <sched.h> defines time_t since POSIX.1-2008. Conforming to: C99 and later; POSIX.1-2001 and later. See also: stime(2), time(2), ctime(3), difftime(3) timer_t Include: <sys/types.h>. Alternatively, <time.h>. Used for timer ID returned by timer_create(2). According to POSIX, there are no defined comparison or assignment operators for this type. Conforming to: POSIX.1-2001 and later. See also: timer_create(2), timer_delete(2), timer_getoverrun(2), timer_settime(2) timespec Include: <time.h>. Alternatively, <aio.h>, <mqueue.h>, <sched.h>, <signal.h>, <sys/select.h>, or <sys/stat.h>. struct timespec { time_t tv_sec; /* Seconds */ long tv_nsec; /* Nanoseconds */ }; Describes times in seconds and nanoseconds. Conforming to: C11 and later; POSIX.1-2001 and later. See also: clock_gettime(2), clock_nanosleep(2), nanosleep(2), timerfd_gettime(2), timer_gettime(2) timeval Include: <sys/time.h>. Alternatively, <sys/resource.h>, <sys/select.h>, or <utmpx.h>. struct timeval { time_t tv_sec; /* Seconds */ suseconds_t tv_usec; /* Microseconds */ }; Describes times in seconds and microseconds. Conforming to: POSIX.1-2001 and later. See also: gettimeofday(2), select(2), utimes(2), adjtime(3), fu- times(3), timeradd(3) uid_t Include: <sys/types.h>. Alternatively, <pwd.h>, <signal.h>, <stropts.h>, <sys/ipc.h>, <sys/stat.h>, or <unistd.h>. A type used to hold user IDs. According to POSIX, this shall be an integer type. Conforming to: POSIX.1-2001 and later. See also: chown(2), getuid(2), geteuid(2), getresuid(2), getpw- nam(2), credentials(7) uintmax_t Include: <stdint.h>. Alternatively, <inttypes.h>. An unsigned integer type capable of representing any value of any unsigned integer type supported by the implementation. Ac- cording to the C language standard, it shall be capable of stor- ing values in the range [0, UINTMAX_MAX]. The macro UINTMAX_C() expands its argument to an integer con- stant of type uintmax_t. The length modifier for uintmax_t for the printf(3) and the scanf(3) families of functions is j; resulting commonly in %ju or %jx for printing uintmax_t values. Conforming to: C99 and later; POSIX.1-2001 and later. Bugs: uintmax_t is not large enough to represent values of type unsigned __int128 in implementations where unsigned __int128 is defined and unsigned long long is less than 128 bits wide. See also: the intmax_t type in this page. uintN_t Include: <stdint.h>. Alternatively, <inttypes.h>. uint8_t, uint16_t, uint32_t, uint64_t An unsigned integer type of a fixed width of exactly N bits, N being the value specified in its type name. According to the C language standard, they shall be capable of storing values in the range [0, UINTN_MAX], substituting N by the appropriate num- ber. According to POSIX, uint8_t, uint16_t, and uint32_t are re- quired; uint64_t is only required in implementations that pro- vide integer types with width 64; and all other types of this form are optional. The length modifiers for the uintN_t types for the printf(3) family of functions are expanded by macros of the forms PRIuN, PRIoN, PRIxN, and PRIXN (defined in <inttypes.h>); resulting for example in %"PRIu32" or %"PRIx32" for printing uint32_t values. The length modifiers for the uintN_t types for the scanf(3) fam- ily of functions are expanded by macros of the forms SCNuN, SC- NoN, SCNxN, and SCNXN (defined in <inttypes.h>); resulting for example in %"SCNu16" or %"SCNx16" for scanning uint16_t values. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the intmax_t, intN_t, and uintmax_t types in this page. uintptr_t Include: <stdint.h>. Alternatively, <inttypes.h>. An unsigned integer type such that any valid (void *) value can be converted to this type and back. According to the C language standard, it shall be capable of storing values in the range [0, UINTPTR_MAX]. The length modifier for uintptr_t for the printf(3) family of functions is expanded by the macros PRIuPTR, PRIoPTR, PRIxPTR, and PRIXPTR (defined in <inttypes.h>); resulting commonly in %"PRIuPTR" or %"PRIxPTR" for printing uintptr_t values. The length modifier for uintptr_t for the scanf(3) family of func- tions is expanded by the macros SCNuPTR, SCNoPTR, SCNxPTR, and SCNXPTR (defined in <inttypes.h>); resulting commonly in %"SC- NuPTR" or %"SCNxPTR" for scanning uintptr_t values. Conforming to: C99 and later; POSIX.1-2001 and later. See also: the intptr_t and void * types in this page. va_list Include: <stdarg>. Alternatively, <stdio.h>, or <wchar.h>. Used by functions with a varying number of arguments of varying types. The function must declare an object of type va_list which is used by the macros va_start(3), va_arg(3), va_copy(3), and va_end(3) to traverse the list of arguments. Conforming to: C99 and later; POSIX.1-2001 and later. See also: va_start(3), va_arg(3), va_copy(3), va_end(3) void * According to the C language standard, a pointer to any object type may be converted to a pointer to void and back. POSIX fur- ther requires that any pointer, including pointers to functions, may be converted to a pointer to void and back. Conversions from and to any other pointer type are done implic- itly, not requiring casts at all. Note that this feature pre- vents any kind of type checking: the programmer should be care- ful not to convert a void * value to a type incompatible to that of the underlying data, because that would result in undefined behavior. This type is useful in function parameters and return value to allow passing values of any type. The function will typically use some mechanism to know the real type of the data being passed via a pointer to void. A value of this type can't be dereferenced, as it would give a value of type void, which is not possible. Likewise, pointer arithmetic is not possible with this type. However, in GNU C, pointer arithmetic is allowed as an extension to the standard; this is done by treating the size of a void or of a function as 1. A consequence of this is that sizeof is also allowed on void and on function types, and returns 1. The conversion specifier for void * for the printf(3) and the scanf(3) families of functions is p. Versions: The POSIX requirement about compatibility between void * and function pointers was added in POSIX.1-2008 Technical Cor- rigendum 1 (2013). Conforming to: C99 and later; POSIX.1-2001 and later. See also: malloc(3), memcmp(3), memcpy(3), memset(3) See also the intptr_t and uintptr_t types in this page. NOTES The structures described in this manual page shall contain, at least, the members shown in their definition, in no particular order. Most of the integer types described in this page don't have a corre- sponding length modifier for the printf(3) and the scanf(3) families of functions. To print a value of an integer type that doesn't have a length modifier, it should be converted to intmax_t or uintmax_t by an explicit cast. To scan into a variable of an integer type that doesn't have a length modifier, an intermediate temporary variable of type int- max_t or uintmax_t should be used. When copying from the temporary variable to the destination variable, the value could overflow. If the type has upper and lower limits, the user should check that the value is within those limits, before actually copying the value. The example below shows how these conversions should be done. Conventions used in this page In "Conforming to" we only concern ourselves with C99 and later and POSIX.1-2001 and later. Some types may be specified in earlier ver- sions of one of these standards, but in the interests of simplicity we omit details from earlier standards. In "Include", we first note the "primary" header(s) that define the type according to either the C or POSIX.1 standards. Under "Alterna- tively", we note additional headers that the standards specify shall define the type. EXAMPLES The program shown below scans from a string and prints a value stored in a variable of an integer type that doesn't have a length modifier. The appropriate conversions from and to intmax_t, and the appropriate range checks, are used as explained in the notes section above. #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> int main (void) { static const char *const str = "500000 us in half a second"; suseconds_t us; intmax_t tmp; /* Scan the number from the string into the temporary variable */ sscanf(str, "%jd", &tmp); /* Check that the value is within the valid range of suseconds_t */ if (tmp < -1 || tmp > 1000000) { fprintf(stderr, "Scanned value outside valid range!\n"); exit(EXIT_FAILURE); } /* Copy the value to the suseconds_t variable 'us' */ us = tmp; /* Even though suseconds_t can hold the value -1, this isn't a sensible number of microseconds */ if (us < 0) { fprintf(stderr, "Scanned value shouldn't be negative!\n"); exit(EXIT_FAILURE); } /* Print the value */ printf("There are %jd microseconds in half a second.\n", (intmax_t) us); exit(EXIT_SUCCESS); } SEE ALSO feature_test_macros(7), standards(7) COLOPHON This page is part of release 5.10 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2020-12-21 SYSTEM_DATA_TYPES(7) FILE(1) BSD General Commands Manual FILE(1) NAME file -- determine file type SYNOPSIS file [-bcdEhiklLNnprsSvzZ0] [--apple] [--exclude-quiet] [--extension] [--mime-encoding] [--mime-type] [-e testname] [-F separator] [-f namefile] [-m magicfiles] [-P name=value] file ... file -C [-m magicfiles] file [--help] DESCRIPTION This manual page documents version 5.41 of the file command. file tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed. The type printed will usually contain one of the words text (the file contains only printing characters and a few common control characters and is probably safe to read on an ASCII terminal), executable (the file con- tains the result of compiling a program in a form understandable to some UNIX kernel or another), or data meaning anything else (data is usually "binary" or non-printable). Exceptions are well-known file formats (core files, tar archives) that are known to contain binary data. When modify- ing magic files or the program itself, make sure to preserve these keywords. Users depend on knowing that all the readable files in a di- rectory have the word "text" printed. Don't do as Berkeley did and change "shell commands text" to "shell script". The filesystem tests are based on examining the return from a stat(2) system call. The program checks to see if the file is empty, or if it's some sort of special file. Any known file types appropriate to the sys- tem you are running on (sockets, symbolic links, or named pipes (FIFOs) on those systems that implement them) are intuited if they are defined in the system header file <sys/stat.h>. The magic tests are used to check for files with data in particular fixed formats. The canonical example of this is a binary executable (compiled program) a.out file, whose format is defined in <elf.h>, <a.out.h> and possibly <exec.h> in the standard include directory. These files have a "magic number" stored in a particular place near the beginning of the file that tells the UNIX operating system that the file is a binary exe- cutable, and which of several types thereof. The concept of a "magic number" has been applied by extension to data files. Any file with some invariant identifier at a small fixed offset into the file can usually be described in this way. The information identifying these files is read from /etc/magic and the compiled magic file /usr/share/misc/magic.mgc, or the files in the directory /usr/share/misc/magic if the compiled file does not exist. In addition, if $HOME/.magic.mgc or $HOME/.magic exists, it will be used in preference to the system magic files. If a file does not match any of the entries in the magic file, it is ex- amined to see if it seems to be a text file. ASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets (such as those used on Macintosh and IBM PC systems), UTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC character sets can be distinguished by the different ranges and sequences of bytes that constitute printable text in each set. If a file passes any of these tests, its character set is reported. ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified as "text" be- cause they will be mostly readable on nearly any terminal; UTF-16 and EBCDIC are only "character data" because, while they contain text, it is text that will require translation before it can be read. In addition, file will attempt to determine other characteristics of text-type files. If the lines of a file are terminated by CR, CRLF, or NEL, instead of the Unix-standard LF, this will be reported. Files that contain embedded es- cape sequences or overstriking will also be identified. Once file has determined the character set used in a text-type file, it will attempt to determine in what language the file is written. The lan- guage tests look for particular strings (cf. <names.h>) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a troff(1) input file, just as the keyword struct indicates a C program. These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some miscellany (such as tar(1) archives, JSON files). Any file that cannot be identified as having been written in any of the character sets listed above is simply said to be "data". OPTIONS --apple Causes the file command to output the file type and creator code as used by older MacOS versions. The code consists of eight let- ters, the first describing the file type, the latter the creator. This option works properly only for file formats that have the apple-style output defined. -b, --brief Do not prepend filenames to output lines (brief mode). -C, --compile Write a magic.mgc output file that contains a pre-parsed version of the magic file or directory. -c, --checking-printout Cause a checking printout of the parsed form of the magic file. This is usually used in conjunction with the -m option to debug a new magic file before installing it. -d Prints internal debugging information to stderr. -E On filesystem errors (file not found etc), instead of handling the error as regular output as POSIX mandates and keep going, is- sue an error message and exit. -e, --exclude testname Exclude the test named in testname from the list of tests made to determine the file type. Valid test names are: apptype EMX application type (only on EMX). ascii Various types of text files (this test will try to guess the text encoding, irrespective of the setting of the 'encoding' option). encoding Different text encodings for soft magic tests. tokens Ignored for backwards compatibility. cdf Prints details of Compound Document Files. compress Checks for, and looks inside, compressed files. csv Checks Comma Separated Value files. elf Prints ELF file details, provided soft magic tests are enabled and the elf magic is found. json Examines JSON (RFC-7159) files by parsing them for com- pliance. soft Consults magic files. tar Examines tar files by verifying the checksum of the 512 byte tar header. Excluding this test can provide more detailed content description by using the soft magic method. text A synonym for 'ascii'. --exclude-quiet Like --exclude but ignore tests that file does not know about. This is intended for compatibility with older versions of file. --extension Print a slash-separated list of valid extensions for the file type found. -F, --separator separator Use the specified string as the separator between the filename and the file result returned. Defaults to ':'. -f, --files-from namefile Read the names of the files to be examined from namefile (one per line) before the argument list. Either namefile or at least one filename argument must be present; to test the standard input, use '-' as a filename argument. Please note that namefile is un- wrapped and the enclosed filenames are processed when this option is encountered and before any further options processing is done. This allows one to process multiple lists of files with different command line arguments on the same file invocation. Thus if you want to set the delimiter, you need to do it before you specify the list of files, like: "-F @ -f namefile", instead of: "-f namefile -F @". -h, --no-dereference This option causes symlinks not to be followed (on systems that support symbolic links). This is the default if the environment variable POSIXLY_CORRECT is not defined. -i, --mime Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say 'text/plain; charset=us-ascii' rather than "ASCII text". --mime-type, --mime-encoding Like -i, but print only the specified element(s). -k, --keep-going Don't stop at the first match, keep going. Subsequent matches will be have the string '\012- ' prepended. (If you want a new- line, see the -r option.) The magic pattern with the highest strength (see the -l option) comes first. -l, --list Shows a list of patterns and their strength sorted descending by magic(5) strength which is used for the matching (see also the -k option). -L, --dereference This option causes symlinks to be followed, as the like-named op- tion in ls(1) (on systems that support symbolic links). This is the default if the environment variable POSIXLY_CORRECT is de- fined. -m, --magic-file magicfiles Specify an alternate list of files and directories containing magic. This can be a single item, or a colon-separated list. If a compiled magic file is found alongside a file or directory, it will be used instead. -N, --no-pad Don't pad filenames so that they align in the output. -n, --no-buffer Force stdout to be flushed after checking each file. This is only useful if checking a list of files. It is intended to be used by programs that want filetype output from a pipe. -p, --preserve-date On systems that support utime(3) or utimes(2), attempt to pre- serve the access time of files analyzed, to pretend that file never read them. -P, --parameter name=value Set various parameter limits. Name Default Explanation bytes 1048576 max number of bytes to read from file elf_notes 256 max ELF notes processed elf_phnum 2048 max ELF program sections processed elf_shnum 32768 max ELF sections processed encoding 65536 max number of bytes to scan for encoding evaluation indir 50 recursion limit for indirect magic name 50 use count limit for name/use magic regex 8192 length limit for regex searches -r, --raw Don't translate unprintable characters to \ooo. Normally file translates unprintable characters to their octal representation. -s, --special-files Normally, file only attempts to read and determine the type of argument files which stat(2) reports are ordinary files. This prevents problems, because reading special files may have pecu- liar consequences. Specifying the -s option causes file to also read argument files which are block or character special files. This is useful for determining the filesystem types of the data in raw disk partitions, which are block special files. This op- tion also causes file to disregard the file size as reported by stat(2) since on some systems it reports a zero size for raw disk partitions. -S, --no-sandbox On systems where libseccomp (https://github.com/seccomp/libseccomp) is available, the -S op- tion disables sandboxing which is enabled by default. This op- tion is needed for file to execute external decompressing pro- grams, i.e. when the -z option is specified and the built-in de- compressors are not available. On systems where sandboxing is not available, this option has no effect. Note: This Debian version of file was built without seccomp sup- port, so this option has no effect. -v, --version Print the version of the program and exit. -z, --uncompress Try to look inside compressed files. -Z, --uncompress-noreport Try to look inside compressed files, but report information about the contents only not the compression. -0, --print0 Output a null character '\0' after the end of the filename. Nice to cut(1) the output. This does not affect the separator, which is still printed. If this option is repeated more than once, then file prints just the filename followed by a NUL followed by the description (or ERROR: text) followed by a second NUL for each entry. --help Print a help message and exit. ENVIRONMENT The environment variable MAGIC can be used to set the default magic file name. If that variable is set, then file will not attempt to open $HOME/.magic. file adds ".mgc" to the value of this variable as appro- priate. The environment variable POSIXLY_CORRECT controls (on systems that support symbolic links), whether file will attempt to follow sym- links or not. If set, then file follows symlink, otherwise it does not. This is also controlled by the -L and -h options. FILES /usr/share/misc/magic.mgc Default compiled list of magic. /usr/share/misc/magic Directory containing default magic files. EXIT STATUS file will exit with 0 if the operation was successful or >0 if an error was encountered. The following errors cause diagnostic messages, but don't affect the program exit code (as POSIX requires), unless -E is specified: o A file cannot be found o There is no permission to read a file o The file type cannot be determined EXAMPLES $ file file.c file /dev/{wd0a,hda} file.c: C program text file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped /dev/wd0a: block special (0/0) /dev/hda: block special (3/0) $ file -s /dev/wd0{b,d} /dev/wd0b: data /dev/wd0d: x86 boot sector $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10} /dev/hda: x86 boot sector /dev/hda1: Linux/i386 ext2 filesystem /dev/hda2: x86 boot sector /dev/hda3: x86 boot sector, extended partition table /dev/hda4: Linux/i386 ext2 filesystem /dev/hda5: Linux/i386 swap file /dev/hda6: Linux/i386 swap file /dev/hda7: Linux/i386 swap file /dev/hda8: Linux/i386 swap file /dev/hda9: empty /dev/hda10: empty $ file -i file.c file /dev/{wd0a,hda} file.c: text/x-c file: application/x-executable /dev/hda: application/x-not-regular-file /dev/wd0a: application/x-not-regular-file SEE ALSO hexdump(1), od(1), strings(1), magic(5) STANDARDS CONFORMANCE This program is believed to exceed the System V Interface Definition of FILE(CMD), as near as one can determine from the vague language contained therein. Its behavior is mostly compatible with the System V program of the same name. This version knows more magic, however, so it will pro- duce different (albeit more accurate) output in many cases. The one significant difference between this version and System V is that this version treats any white space as a delimiter, so that spaces in pattern strings must be escaped. For example, >10 string language impress (imPRESS data) in an existing magic file would have to be changed to >10 string language\ impress (imPRESS data) In addition, in this version, if a pattern string contains a backslash, it must be escaped. For example 0 string \begindata Andrew Toolkit document in an existing magic file would have to be changed to 0 string \\begindata Andrew Toolkit document SunOS releases 3.2 and later from Sun Microsystems include a file command derived from the System V one, but with some extensions. This version differs from Sun's only in minor ways. It includes the extension of the '&' operator, used as, for example, >16 long&0x7fffffff >0 not stripped SECURITY On systems where libseccomp (https://github.com/seccomp/libseccomp) is available, file is enforces limiting system calls to only the ones neces- sary for the operation of the program. This enforcement does not provide any security benefit when file is asked to decompress input files running external programs with the -z option. To enable execution of external decompressors, one needs to disable sandboxing using the -S option. MAGIC DIRECTORY The magic file entries have been collected from various sources, mainly USENET, and contributed by various authors. Christos Zoulas (address be- low) will collect additional or corrected magic file entries. A consoli- dation of magic file entries will be distributed periodically. The order of entries in the magic file is significant. Depending on what system you are using, the order that they are put together may be incor- rect. HISTORY There has been a file command in every UNIX since at least Research Version 4 (man page dated November, 1973). The System V version intro- duced one significant major change: the external list of magic types. This slowed the program down slightly but made it a lot more flexible. This program, based on the System V version, was written by Ian Darwin <ian AT darwinsys.com> without looking at anybody else's source code. John Gilmore revised the code extensively, making it better than the first version. Geoff Collyer found several inadequacies and provided some magic file entries. Contributions of the '&' operator by Rob McMa- hon, <cudcv AT warwick.uk>, 1989. Guy Harris, <guy AT netapp.com>, made many changes from 1993 to the present. Primary development and maintenance from 1990 to the present by Christos Zoulas <christos AT astron.com>. Altered by Chris Lowth <chris AT lowth.com>, 2000: handle the -i option to output mime type strings, using an alternative magic file and internal logic. Altered by Eric Fischer <enf AT pobox.com>, July, 2000, to identify charac- ter codes and attempt to identify the languages of non-ASCII files. Altered by Reuben Thomas <rrt AT sc3d.org>, 2007-2011, to improve MIME sup- port, merge MIME and non-MIME magic, support directories as well as files of magic, apply many bug fixes, update and fix a lot of magic, improve the build system, improve the documentation, and rewrite the Python bind- ings in pure Python. The list of contributors to the 'magic' directory (magic files) is too long to include here. You know who you are; thank you. Many contribu- tors are listed in the source files. LEGAL NOTICE Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999. Covered by the standard Berkeley Software Distribution copyright; see the file COPYING in the source distribution. The files tar.h and is_tar.c were written by John Gilmore from his pub- lic-domain tar(1) program, and are not covered by the above license. BUGS Please report bugs and send patches to the bug tracker at https://bugs.astron.com/ or the mailing list at <file AT astron.com> (visit https://mailman.astron.com/mailman/listinfo/file first to subscribe). TODO Fix output so that tests for MIME and APPLE flags are not needed all over the place, and actual output is only done in one place. This needs a de- sign. Suggestion: push possible outputs on to a list, then pick the last-pushed (most specific, one hopes) value at the end, or use a default if the list is empty. This should not slow down evaluation. The handling of MAGIC_CONTINUE and printing \012- between entries is clumsy and complicated; refactor and centralize. Some of the encoding logic is hard-coded in encoding.c and can be moved to the magic files if we had a !:charset annotation. Continue to squash all magic bugs. See Debian BTS for a good source. Store arbitrarily long strings, for example for %s patterns, so that they can be printed out. Fixes Debian bug #271672. This can be done by allo- cating strings in a string pool, storing the string pool at the end of the magic file and converting all the string pointers to relative offsets from the string pool. Add syntax for relative offsets after current level (Debian bug #466037). Make file -ki work, i.e. give multiple MIME types. Add a zip library so we can peek inside Office2007 documents to print more details about their contents. Add an option to print URLs for the sources of the file descriptions. Combine script searches and add a way to map executable names to MIME types (e.g. have a magic value for !:mime which causes the resulting string to be looked up in a table). This would avoid adding the same magic repeatedly for each new hash-bang interpreter. When a file descriptor is available, we can skip and adjust the buffer instead of the hacky buffer management we do now. Fix "name" and "use" to check for consistency at compile time (duplicate "name", "use" pointing to undefined "name" ). Make "name" / "use" more efficient by keeping a sorted list of names. Special-case ^ to flip en- dianness in the parser so that it does not have to be escaped, and docu- ment it. If the offsets specified internally in the file exceed the buffer size ( HOWMANY variable in file.h), then we don't seek to that offset, but we give up. It would be better if buffer managements was done when the file descriptor is available so we can seek around the file. One must be careful though because this has performance and thus security considera- tions, because one can slow down things by repeateadly seeking. There is support now for keeping separate buffers and having offsets from the end of the file, but the internal buffer management still needs an overhaul. AVAILABILITY You can obtain the original author's latest version by anonymous FTP on ftp.astron.com in the directory /pub/file/file-X.YZ.tar.gz. BSD February 5, 2021 BSD
Generated by phpMan v3.6.3-2-gc817beb Author: Che Dong Under GNU General Public License
2026-06-08 07:49 @216.73.217.65
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)