]> pd.if.org Git - pdclib.old/blob - man3/unlocked_stdio.3
Add _cbprintf/_vcbprintf (callback based printf formatters)
[pdclib.old] / man3 / unlocked_stdio.3
1 .\" This file is part of the Public Domain C Library " "PDCLib).
2 .\" Permission is granted to use" "modify" "and / or redistribute at will.
3 .\"
4 .Dd
5 .Dt UNLOCKED_STDIO 3
6 .Os
7 .\"
8 .Sh NAME
9 .Nm *_unlocked
10 .Nd unlocked stdio routnes
11 .\"
12 .Sh SYNOPSIS
13 .Sy #define _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || _SVID_SOURCE || _BSD_SOURCE
14 .In stdio.h
15 .Fn "int getc_unlocked" "FILE *stream"
16 .Fn "int getchar_unlocked" "void"
17 .Fn "int putc_unlocked" "int c" "FILE *stream"
18 .Fn "int putchar_unlocked" "int c"
19 .Pp
20 .Sy #define _SVID_SOURCE || _BSD_SOURCE
21 .In stdio.h
22 .Fn "void clearerr_unlocked" "FILE *stream" 
23 .Fn "int feof_unlocked" "FILE *stream"
24 .Fn "int ferror_unlocked" "FILE *stream"
25 .Fn "int fflush_unlocked" "FILE *stream"
26 .Fn "int fgetc_unlocked" "FILE *stream"
27 .Fn "int fputc_unlocked" "int c" "FILE *stream"
28 .Fn "size_t fread_unlocked" "void *ptr" "size_t size" "size_t n" "FILE *stream"
29 .Fn "size_t fwrite_unlocked" "const void *ptr" "size_t size" "size_t n" "FILE *stream"
30 .Pp
31 .Sy #define _GNU_SOURCE
32 .In stdio.h
33 .Fn "char *fgets_unlocked" "char *s" "int n" "FILE *stream"
34 .Fn "int fputs_unlocked" "const char *s" "FILE *stream"
35 .Pp
36 .Sy #define _PDCLIB_EXTENSIONS
37 .In stdio.h
38 .Fn "int fgetpos_unlocked" "FILE * restrict stream" "fpos_t * restrict pos"
39 .Fn "int fsetpos_unlocked" "FILE * stream" "const fpos_t * pos"
40 .Fn "long int ftell_unlocked" "FILE * stream"
41 .Fn "int fseek_unlocked" "FILE * stream" "long int offset" "int whence"
42 .Fn "void rewind_unlocked" "FILE * stream"
43 .Fn "int puts_unlocked" "const char * s"
44 .Fn "int ungetc_unlocked" "int c" "FILE * stream"
45 .Fn "int printf_unlocked" "const char * restrict format" "..."
46 .Fn "int vprintf_unlocked" "const char * restrict format" "va_list arg"
47 .Fn "int fprintf_unlocked" "FILE * restrict stream" "const char * restrict format" "..."
48 .Fn "int vfprintf_unlocked" "FILE * restrict stream" "const char * restrict format" "va_list arg"
49 .Fn "int scanf_unlocked" "const char * restrict format" "..."
50 .Fn "int vscanf_unlocked" "const char * restrict format" "va_list arg"
51 .Fn "int fscanf_unlocked" "FILE * restrict stream" "const char * restrict format" "..."
52 .Fn "int vfscanf_unlocked" "FILE * restrict stream" "const char * restrict format" "va_list arg"
53 .\"
54 .Sh DESCRIPTION
55 Functions with analogous purposes to the same functions named without the 
56 .Li _unlocked 
57 prefix, excepting that they must be called with the stream already locked (they
58 do not lock the stream themself)
59 .Pp
60 Befor calling these functions, callers must lock the stream upon which they wish
61 to operate on with the
62 .Fn flockfile
63 or
64 .Fn ftrylockfile
65 function. Once they are done operating on the stream, they should unlock the 
66 stream using the
67 .Fn funlockfile
68 to allow other threads to use the stream
69 .Pp
70 It is undefined behaviour to operate on a stream using one of these functions
71 without previously locking the stream appropriately, even in a single threaded
72 application.
73 .\"
74 .Sh IMPLEMENTATION NOTES
75 PDCLib implements the locked variants of most functions using the following 
76 template:
77 .Bd -literal -offset indent -compact 
78 type function(FILE* file, other arguments...)
79 {
80     flockfile(file);
81     type rv = function_unlocked(file, other arguments...)
82     funlockfile(file);
83     return rv;
84 }
85 .Ed
86 .\"
87 .Sh SEE ALSO
88 .Xr fopen 3
89 .Xr fclose 3
90 .Xr flockfile 3
91 .Xr mtx_t 3
92 .\"
93 .Sh STANDARDS
94 The most basic I/O routines (getc/getchar/putc/putchar_unlocked) are from
95 .St -p1003.1-2001 .
96 A more complete set of routines comes from
97 .St -svid4 
98 and
99 .Bx .
100 .Fn fgets_unlocked 
101 and 
102 .Fn fputs_unlocked
103 are extensions originating from glibc. Finally, PDCLib extends the set to 
104 encompass the entirety of the C standard I/o library.