Debian Codegraph @

templates/man3/fopencookie.3.pot

raw
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2026-06-05 06:24+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <[email protected]>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "fopencookie"
24 msgstr ""
25
26 #. type: TH
27 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
28 #: opensuse-tumbleweed
29 #, no-wrap
30 msgid "2025-09-21"
31 msgstr ""
32
33 #. type: TH
34 #: archlinux debian-unstable
35 #, no-wrap
36 msgid "Linux man-pages 6.18"
37 msgstr ""
38
39 #. type: SH
40 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
41 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
42 #, no-wrap
43 msgid "NAME"
44 msgstr ""
45
46 #. type: Plain text
47 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
48 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
49 msgid "fopencookie - open a custom stream"
50 msgstr ""
51
52 #. type: SH
53 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
54 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
55 #, no-wrap
56 msgid "LIBRARY"
57 msgstr ""
58
59 #. type: Plain text
60 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
61 #: opensuse-leap-16-1 opensuse-tumbleweed
62 msgid "Standard C library (I<libc>,\\ I<-lc>)"
63 msgstr ""
64
65 #. type: SH
66 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
67 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
68 #, no-wrap
69 msgid "SYNOPSIS"
70 msgstr ""
71
72 #. type: Plain text
73 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
74 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
75 #, no-wrap
76 msgid ""
77 "B<#define _GNU_SOURCE> /* See feature_test_macros(7) */\n"
78 "B<#define _FILE_OFFSET_BITS 64>\n"
79 "B<#include E<lt>stdio.hE<gt>>\n"
80 msgstr ""
81
82 #. type: Plain text
83 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
84 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
85 #, no-wrap
86 msgid ""
87 "B<FILE *fopencookie(void *restrict >I<cookie>B<, const char *restrict >I<mode>B<,>\n"
88 "B< cookie_io_functions_t >I<io_funcs>B<);>\n"
89 msgstr ""
90
91 #. type: SH
92 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
93 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
94 #, no-wrap
95 msgid "DESCRIPTION"
96 msgstr ""
97
98 #. type: Plain text
99 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
100 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
101 msgid ""
102 "The B<fopencookie>() function allows the programmer to create a custom "
103 "implementation for a standard I/O stream. This implementation can store the "
104 "stream's data at a location of its own choosing; for example, "
105 "B<fopencookie>() is used to implement B<fmemopen>(3), which provides a "
106 "stream interface to data that is stored in a buffer in memory."
107 msgstr ""
108
109 #. type: Plain text
110 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
111 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
112 msgid "In order to create a custom stream the programmer must:"
113 msgstr ""
114
115 #. type: IP
116 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
117 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
118 #, no-wrap
119 msgid "\\[bu]"
120 msgstr ""
121
122 #. type: Plain text
123 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
124 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
125 msgid ""
126 "Implement four \"hook\" functions that are used internally by the standard I/"
127 "O library when performing I/O on the stream."
128 msgstr ""
129
130 #. type: Plain text
131 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
132 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
133 msgid ""
134 "Define a \"cookie\" data type, a structure that provides bookkeeping "
135 "information (e.g., where to store data) used by the aforementioned hook "
136 "functions. The standard I/O package knows nothing about the contents of "
137 "this cookie (thus it is typed as I<void\\ *> when passed to "
138 "B<fopencookie>()), but automatically supplies the cookie as the first "
139 "argument when calling the hook functions."
140 msgstr ""
141
142 #. type: Plain text
143 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
144 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
145 msgid ""
146 "Call B<fopencookie>() to open a new stream and associate the cookie and "
147 "hook functions with that stream."
148 msgstr ""
149
150 #. type: Plain text
151 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
152 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
153 msgid ""
154 "The B<fopencookie>() function serves a purpose similar to B<fopen>(3): it "
155 "opens a new stream and returns a pointer to a I<FILE> object that is used to "
156 "operate on that stream."
157 msgstr ""
158
159 #. type: Plain text
160 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
161 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
162 msgid ""
163 "The I<cookie> argument is a pointer to the caller's cookie structure that is "
164 "to be associated with the new stream. This pointer is supplied as the first "
165 "argument when the standard I/O library invokes any of the hook functions "
166 "described below."
167 msgstr ""
168
169 #. type: Plain text
170 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
171 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
172 msgid ""
173 "The I<mode> argument serves the same purpose as for B<fopen>(3). The "
174 "following modes are supported: I<r>, I<w>, I<a>, I<r+>, I<w+>, and I<a+>. "
175 "See B<fopen>(3) for details."
176 msgstr ""
177
178 #. type: Plain text
179 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
180 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
181 msgid ""
182 "The I<io_funcs> argument is a structure that contains four fields pointing "
183 "to the programmer-defined hook functions that are used to implement this "
184 "stream. The structure is defined as follows"
185 msgstr ""
186
187 #. type: Plain text
188 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
189 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
190 #, no-wrap
191 msgid ""
192 "typedef struct {\n"
193 " cookie_read_function_t *read;\n"
194 " cookie_write_function_t *write;\n"
195 " cookie_seek_function_t *seek;\n"
196 " cookie_close_function_t *close;\n"
197 "} cookie_io_functions_t;\n"
198 msgstr ""
199
200 #. type: Plain text
201 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
202 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
203 msgid "The four fields are as follows:"
204 msgstr ""
205
206 #. type: TP
207 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
208 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
209 #, no-wrap
210 msgid "I<cookie_read_function_t *read>"
211 msgstr ""
212
213 #. type: Plain text
214 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
215 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
216 msgid ""
217 "This function implements read operations for the stream. When called, it "
218 "receives three arguments:"
219 msgstr ""
220
221 #. type: Plain text
222 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
223 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
224 #, no-wrap
225 msgid "ssize_t read(void *cookie, char *buf, size_t size);\n"
226 msgstr ""
227
228 #. type: Plain text
229 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
230 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
231 msgid ""
232 "The I<buf> and I<size> arguments are, respectively, a buffer into which "
233 "input data can be placed and the size of that buffer. As its function "
234 "result, the I<read> function should return the number of bytes copied into "
235 "I<buf>, 0 on end of file, or -1 on error. The I<read> function should "
236 "update the stream offset appropriately."
237 msgstr ""
238
239 #. type: Plain text
240 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
241 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
242 msgid ""
243 "If I<*read> is a null pointer, then reads from the custom stream always "
244 "return end of file."
245 msgstr ""
246
247 #. type: TP
248 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
249 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
250 #, no-wrap
251 msgid "I<cookie_write_function_t *write>"
252 msgstr ""
253
254 #. type: Plain text
255 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
256 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
257 msgid ""
258 "This function implements write operations for the stream. When called, it "
259 "receives three arguments:"
260 msgstr ""
261
262 #. type: Plain text
263 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
264 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
265 #, no-wrap
266 msgid "ssize_t write(void *cookie, const char *buf, size_t size);\n"
267 msgstr ""
268
269 #. type: Plain text
270 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
271 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
272 msgid ""
273 "The I<buf> and I<size> arguments are, respectively, a buffer of data to be "
274 "output to the stream and the size of that buffer. As its function result, "
275 "the I<write> function should return the number of bytes copied from I<buf>, "
276 "or 0 on error. (The function must not return a negative value.) The "
277 "I<write> function should update the stream offset appropriately."
278 msgstr ""
279
280 #. type: Plain text
281 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
282 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
283 msgid "If I<*write> is a null pointer, then output to the stream is discarded."
284 msgstr ""
285
286 #. type: TP
287 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
288 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
289 #, no-wrap
290 msgid "I<cookie_seek_function_t *seek>"
291 msgstr ""
292
293 #. type: Plain text
294 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
295 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
296 msgid ""
297 "This function implements seek operations on the stream. When called, it "
298 "receives three arguments:"
299 msgstr ""
300
301 #. type: Plain text
302 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
303 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
304 #, no-wrap
305 msgid "int seek(void *cookie, off_t *offset, int whence);\n"
306 msgstr ""
307
308 #. type: Plain text
309 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
310 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
311 msgid ""
312 "The I<*offset> argument specifies the new file offset depending on which of "
313 "the following three values is supplied in I<whence>:"
314 msgstr ""
315
316 #. type: TP
317 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
318 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
319 #, no-wrap
320 msgid "B<SEEK_SET>"
321 msgstr ""
322
323 #. type: Plain text
324 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
325 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
326 msgid ""
327 "The stream offset should be set I<*offset> bytes from the start of the "
328 "stream."
329 msgstr ""
330
331 #. type: TP
332 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
333 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
334 #, no-wrap
335 msgid "B<SEEK_CUR>"
336 msgstr ""
337
338 #. type: Plain text
339 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
340 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
341 msgid "I<*offset> should be added to the current stream offset."
342 msgstr ""
343
344 #. type: TP
345 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
346 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
347 #, no-wrap
348 msgid "B<SEEK_END>"
349 msgstr ""
350
351 #. type: Plain text
352 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
353 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
354 msgid ""
355 "The stream offset should be set to the size of the stream plus I<*offset>."
356 msgstr ""
357
358 #. type: Plain text
359 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
360 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
361 msgid ""
362 "Before returning, the I<seek> function should update I<*offset> to indicate "
363 "the new stream offset."
364 msgstr ""
365
366 #. type: Plain text
367 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
368 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
369 msgid ""
370 "As its function result, the I<seek> function should return 0 on success, and "
371 "-1 on error."
372 msgstr ""
373
374 #. type: Plain text
375 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
376 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
377 msgid ""
378 "If I<*seek> is a null pointer, then it is not possible to perform seek "
379 "operations on the stream."
380 msgstr ""
381
382 #. type: TP
383 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
384 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
385 #, no-wrap
386 msgid "I<cookie_close_function_t *close>"
387 msgstr ""
388
389 #. type: Plain text
390 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
391 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
392 msgid ""
393 "This function closes the stream. The hook function can do things such as "
394 "freeing buffers allocated for the stream. When called, it receives one "
395 "argument:"
396 msgstr ""
397
398 #. type: Plain text
399 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
400 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
401 #, no-wrap
402 msgid "int close(void *cookie);\n"
403 msgstr ""
404
405 #. type: Plain text
406 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
407 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
408 msgid ""
409 "The I<cookie> argument is the cookie that the programmer supplied when "
410 "calling B<fopencookie>()."
411 msgstr ""
412
413 #. type: Plain text
414 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
415 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
416 msgid ""
417 "As its function result, the I<close> function should return 0 on success, "
418 "and B<EOF> on error."
419 msgstr ""
420
421 #. type: Plain text
422 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
423 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
424 msgid ""
425 "If I<*close> is NULL, then no special action is performed when the stream is "
426 "closed."
427 msgstr ""
428
429 #. type: SH
430 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
431 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
432 #, no-wrap
433 msgid "RETURN VALUE"
434 msgstr ""
435
436 #. .SH ERRORS
437 #. It's not clear if errno ever gets set...
438 #. type: Plain text
439 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
440 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
441 msgid ""
442 "On success B<fopencookie>() returns a pointer to the new stream. On error, "
443 "NULL is returned."
444 msgstr ""
445
446 #. type: SH
447 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
448 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
449 #, no-wrap
450 msgid "ATTRIBUTES"
451 msgstr ""
452
453 #. type: Plain text
454 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
455 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
456 msgid ""
457 "For an explanation of the terms used in this section, see B<attributes>(7)."
458 msgstr ""
459
460 #. type: tbl table
461 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
462 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
463 #, no-wrap
464 msgid "Interface"
465 msgstr ""
466
467 #. type: tbl table
468 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
469 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
470 #, no-wrap
471 msgid "Attribute"
472 msgstr ""
473
474 #. type: tbl table
475 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
476 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
477 #, no-wrap
478 msgid "Value"
479 msgstr ""
480
481 #. type: tbl table
482 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
483 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
484 #, no-wrap
485 msgid ".na\n"
486 msgstr ""
487
488 #. type: tbl table
489 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
490 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
491 #, no-wrap
492 msgid ".nh\n"
493 msgstr ""
494
495 #. type: tbl table
496 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
497 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
498 #, no-wrap
499 msgid "B<fopencookie>()"
500 msgstr ""
501
502 #. type: tbl table
503 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
504 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
505 #, no-wrap
506 msgid "Thread safety"
507 msgstr ""
508
509 #. type: tbl table
510 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
511 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
512 #, no-wrap
513 msgid "MT-Safe"
514 msgstr ""
515
516 #. type: SH
517 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
518 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
519 #, no-wrap
520 msgid "STANDARDS"
521 msgstr ""
522
523 #. type: Plain text
524 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
525 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
526 msgid "GNU."
527 msgstr ""
528
529 #. type: SH
530 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
531 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
532 #, no-wrap
533 msgid "EXAMPLES"
534 msgstr ""
535
536 #. type: Plain text
537 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
538 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
539 msgid ""
540 "The program below implements a custom stream whose functionality is similar "
541 "(but not identical) to that available via B<fmemopen>(3). It implements a "
542 "stream whose data is stored in a memory buffer. The program writes its "
543 "command-line arguments to the stream, and then seeks through the stream "
544 "reading two out of every five characters and writing them to standard "
545 "output. The following shell session demonstrates the use of the program:"
546 msgstr ""
547
548 #. type: Plain text
549 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
550 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
551 #, no-wrap
552 msgid ""
553 "$B< ./a.out \\[aq]hello world\\[aq]>\n"
554 "/he/\n"
555 "/ w/\n"
556 "/d/\n"
557 "Reached end of file\n"
558 msgstr ""
559
560 #. type: Plain text
561 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
562 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
563 msgid ""
564 "Note that a more general version of the program below could be improved to "
565 "more robustly handle various error situations (e.g., opening a stream with a "
566 "cookie that already has an open stream; closing a stream that has already "
567 "been closed)."
568 msgstr ""
569
570 #. type: SS
571 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
572 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
573 #, no-wrap
574 msgid "Program source"
575 msgstr ""
576
577 #. type: Plain text
578 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
579 #: opensuse-tumbleweed
580 #, no-wrap
581 msgid ""
582 "#define _GNU_SOURCE\n"
583 "#include E<lt>stdio.hE<gt>\n"
584 "#include E<lt>stdlib.hE<gt>\n"
585 "#include E<lt>string.hE<gt>\n"
586 "#include E<lt>sys/types.hE<gt>\n"
587 "#include E<lt>unistd.hE<gt>\n"
588 "\\&\n"
589 "#define INIT_BUF_SIZE 4\n"
590 "\\&\n"
591 "struct memfile_cookie {\n"
592 " char *buf; /* Dynamically sized buffer for data */\n"
593 " size_t allocated; /* Size of buf */\n"
594 " size_t endpos; /* Number of characters in buf */\n"
595 " off_t offset; /* Current file offset in buf */\n"
596 "};\n"
597 "\\&\n"
598 "static ssize_t\n"
599 "memfile_write(void *c, const char *buf, size_t size)\n"
600 "{\n"
601 " char *new_buff;\n"
602 " struct memfile_cookie *cookie = c;\n"
603 "\\&\n"
604 " /* Buffer too small? Keep doubling size until big enough. */\n"
605 "\\&\n"
606 " while (size + cookie-E<gt>offset E<gt> cookie-E<gt>allocated) {\n"
607 " new_buff = realloc(cookie-E<gt>buf, cookie-E<gt>allocated * 2);\n"
608 " if (new_buff == NULL)\n"
609 " return -1;\n"
610 " cookie-E<gt>allocated *= 2;\n"
611 " cookie-E<gt>buf = new_buff;\n"
612 " }\n"
613 "\\&\n"
614 " memcpy(cookie-E<gt>buf + cookie-E<gt>offset, buf, size);\n"
615 "\\&\n"
616 " cookie-E<gt>offset += size;\n"
617 " if (cookie-E<gt>offset E<gt> cookie-E<gt>endpos)\n"
618 " cookie-E<gt>endpos = cookie-E<gt>offset;\n"
619 "\\&\n"
620 " return size;\n"
621 "}\n"
622 "\\&\n"
623 "static ssize_t\n"
624 "memfile_read(void *c, char *buf, size_t size)\n"
625 "{\n"
626 " ssize_t xbytes;\n"
627 " struct memfile_cookie *cookie = c;\n"
628 "\\&\n"
629 " /* Fetch minimum of bytes requested and bytes available. */\n"
630 "\\&\n"
631 " xbytes = size;\n"
632 " if (cookie-E<gt>offset + size E<gt> cookie-E<gt>endpos)\n"
633 " xbytes = cookie-E<gt>endpos - cookie-E<gt>offset;\n"
634 " if (xbytes E<lt> 0) /* offset may be past endpos */\n"
635 " xbytes = 0;\n"
636 "\\&\n"
637 " memcpy(buf, cookie-E<gt>buf + cookie-E<gt>offset, xbytes);\n"
638 "\\&\n"
639 " cookie-E<gt>offset += xbytes;\n"
640 " return xbytes;\n"
641 "}\n"
642 "\\&\n"
643 "static int\n"
644 "memfile_seek(void *c, off_t *offset, int whence)\n"
645 "{\n"
646 " off_t new_offset;\n"
647 " struct memfile_cookie *cookie = c;\n"
648 "\\&\n"
649 " if (whence == SEEK_SET)\n"
650 " new_offset = *offset;\n"
651 " else if (whence == SEEK_END)\n"
652 " new_offset = cookie-E<gt>endpos + *offset;\n"
653 " else if (whence == SEEK_CUR)\n"
654 " new_offset = cookie-E<gt>offset + *offset;\n"
655 " else\n"
656 " return -1;\n"
657 "\\&\n"
658 " if (new_offset E<lt> 0)\n"
659 " return -1;\n"
660 "\\&\n"
661 " cookie-E<gt>offset = new_offset;\n"
662 " *offset = new_offset;\n"
663 " return 0;\n"
664 "}\n"
665 "\\&\n"
666 "static int\n"
667 "memfile_close(void *c)\n"
668 "{\n"
669 " struct memfile_cookie *cookie = c;\n"
670 "\\&\n"
671 " free(cookie-E<gt>buf);\n"
672 " cookie-E<gt>allocated = 0;\n"
673 " cookie-E<gt>buf = NULL;\n"
674 "\\&\n"
675 " return 0;\n"
676 "}\n"
677 "\\&\n"
678 "int\n"
679 "main(int argc, char *argv[])\n"
680 "{\n"
681 " cookie_io_functions_t memfile_func = {\n"
682 " .read = memfile_read,\n"
683 " .write = memfile_write,\n"
684 " .seek = memfile_seek,\n"
685 " .close = memfile_close\n"
686 " };\n"
687 " FILE *stream;\n"
688 " struct memfile_cookie mycookie;\n"
689 " size_t nread;\n"
690 " char buf[1000];\n"
691 "\\&\n"
692 " /* Set up the cookie before calling fopencookie(). */\n"
693 "\\&\n"
694 " mycookie.buf = malloc(INIT_BUF_SIZE);\n"
695 " if (mycookie.buf == NULL) {\n"
696 " perror(\"malloc\");\n"
697 " exit(EXIT_FAILURE);\n"
698 " }\n"
699 "\\&\n"
700 " mycookie.allocated = INIT_BUF_SIZE;\n"
701 " mycookie.offset = 0;\n"
702 " mycookie.endpos = 0;\n"
703 "\\&\n"
704 " stream = fopencookie(&mycookie, \"w+\", memfile_func);\n"
705 " if (stream == NULL) {\n"
706 " perror(\"fopencookie\");\n"
707 " exit(EXIT_FAILURE);\n"
708 " }\n"
709 "\\&\n"
710 " /* Write command-line arguments to our file. */\n"
711 "\\&\n"
712 " for (size_t j = 1; j E<lt> argc; j++)\n"
713 " if (fputs(argv[j], stream) == EOF) {\n"
714 " perror(\"fputs\");\n"
715 " exit(EXIT_FAILURE);\n"
716 " }\n"
717 "\\&\n"
718 " /* Read two bytes out of every five, until EOF. */\n"
719 "\\&\n"
720 " for (long p = 0; ; p += 5) {\n"
721 " if (fseek(stream, p, SEEK_SET) == -1) {\n"
722 " perror(\"fseek\");\n"
723 " exit(EXIT_FAILURE);\n"
724 " }\n"
725 " nread = fread(buf, 1, 2, stream);\n"
726 " if (nread == 0) {\n"
727 " if (ferror(stream) != 0) {\n"
728 " fprintf(stderr, \"fread failed\\[rs]n\");\n"
729 " exit(EXIT_FAILURE);\n"
730 " }\n"
731 " printf(\"Reached end of file\\[rs]n\");\n"
732 " break;\n"
733 " }\n"
734 "\\&\n"
735 " printf(\"/%.*s/\\[rs]n\", (int) nread, buf);\n"
736 " }\n"
737 "\\&\n"
738 " free(mycookie.buf);\n"
739 "\\&\n"
740 " exit(EXIT_SUCCESS);\n"
741 "}\n"
742 msgstr ""
743
744 #. SRC END
745 #. type: SH
746 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
747 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
748 #, no-wrap
749 msgid "NOTES"
750 msgstr ""
751
752 #. type: Plain text
753 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
754 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
755 msgid ""
756 "B<_FILE_OFFSET_BITS> should be defined to be 64 in code that uses non-null "
757 "I<seek> or that takes the address of B<fopencookie>, if the code is intended "
758 "to be portable to traditional 32-bit x86 and ARM platforms where B<off_t>'s "
759 "width defaults to 32 bits."
760 msgstr ""
761
762 #. type: SH
763 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
764 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
765 #, no-wrap
766 msgid "SEE ALSO"
767 msgstr ""
768
769 #. type: Plain text
770 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
771 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
772 msgid "B<fclose>(3), B<fmemopen>(3), B<fopen>(3), B<fseek>(3)"
773 msgstr ""
774
775 #. type: TH
776 #: debian-trixie
777 #, no-wrap
778 msgid "2024-06-15"
779 msgstr ""
780
781 #. type: TH
782 #: debian-trixie
783 #, no-wrap
784 msgid "Linux man-pages 6.9.1"
785 msgstr ""
786
787 #. type: Plain text
788 #: debian-trixie
789 msgid "Standard C library (I<libc>, I<-lc>)"
790 msgstr ""
791
792 #. type: Plain text
793 #: debian-trixie fedora-44 fedora-rawhide
794 #, no-wrap
795 msgid ""
796 "#define _GNU_SOURCE\n"
797 "#include E<lt>stdio.hE<gt>\n"
798 "#include E<lt>stdlib.hE<gt>\n"
799 "#include E<lt>string.hE<gt>\n"
800 "#include E<lt>sys/types.hE<gt>\n"
801 "#include E<lt>unistd.hE<gt>\n"
802 "\\&\n"
803 "#define INIT_BUF_SIZE 4\n"
804 "\\&\n"
805 "struct memfile_cookie {\n"
806 " char *buf; /* Dynamically sized buffer for data */\n"
807 " size_t allocated; /* Size of buf */\n"
808 " size_t endpos; /* Number of characters in buf */\n"
809 " off_t offset; /* Current file offset in buf */\n"
810 "};\n"
811 "\\&\n"
812 "ssize_t\n"
813 "memfile_write(void *c, const char *buf, size_t size)\n"
814 "{\n"
815 " char *new_buff;\n"
816 " struct memfile_cookie *cookie = c;\n"
817 "\\&\n"
818 " /* Buffer too small? Keep doubling size until big enough. */\n"
819 "\\&\n"
820 " while (size + cookie-E<gt>offset E<gt> cookie-E<gt>allocated) {\n"
821 " new_buff = realloc(cookie-E<gt>buf, cookie-E<gt>allocated * 2);\n"
822 " if (new_buff == NULL)\n"
823 " return -1;\n"
824 " cookie-E<gt>allocated *= 2;\n"
825 " cookie-E<gt>buf = new_buff;\n"
826 " }\n"
827 "\\&\n"
828 " memcpy(cookie-E<gt>buf + cookie-E<gt>offset, buf, size);\n"
829 "\\&\n"
830 " cookie-E<gt>offset += size;\n"
831 " if (cookie-E<gt>offset E<gt> cookie-E<gt>endpos)\n"
832 " cookie-E<gt>endpos = cookie-E<gt>offset;\n"
833 "\\&\n"
834 " return size;\n"
835 "}\n"
836 "\\&\n"
837 "ssize_t\n"
838 "memfile_read(void *c, char *buf, size_t size)\n"
839 "{\n"
840 " ssize_t xbytes;\n"
841 " struct memfile_cookie *cookie = c;\n"
842 "\\&\n"
843 " /* Fetch minimum of bytes requested and bytes available. */\n"
844 "\\&\n"
845 " xbytes = size;\n"
846 " if (cookie-E<gt>offset + size E<gt> cookie-E<gt>endpos)\n"
847 " xbytes = cookie-E<gt>endpos - cookie-E<gt>offset;\n"
848 " if (xbytes E<lt> 0) /* offset may be past endpos */\n"
849 " xbytes = 0;\n"
850 "\\&\n"
851 " memcpy(buf, cookie-E<gt>buf + cookie-E<gt>offset, xbytes);\n"
852 "\\&\n"
853 " cookie-E<gt>offset += xbytes;\n"
854 " return xbytes;\n"
855 "}\n"
856 "\\&\n"
857 "int\n"
858 "memfile_seek(void *c, off_t *offset, int whence)\n"
859 "{\n"
860 " off_t new_offset;\n"
861 " struct memfile_cookie *cookie = c;\n"
862 "\\&\n"
863 " if (whence == SEEK_SET)\n"
864 " new_offset = *offset;\n"
865 " else if (whence == SEEK_END)\n"
866 " new_offset = cookie-E<gt>endpos + *offset;\n"
867 " else if (whence == SEEK_CUR)\n"
868 " new_offset = cookie-E<gt>offset + *offset;\n"
869 " else\n"
870 " return -1;\n"
871 "\\&\n"
872 " if (new_offset E<lt> 0)\n"
873 " return -1;\n"
874 "\\&\n"
875 " cookie-E<gt>offset = new_offset;\n"
876 " *offset = new_offset;\n"
877 " return 0;\n"
878 "}\n"
879 "\\&\n"
880 "int\n"
881 "memfile_close(void *c)\n"
882 "{\n"
883 " struct memfile_cookie *cookie = c;\n"
884 "\\&\n"
885 " free(cookie-E<gt>buf);\n"
886 " cookie-E<gt>allocated = 0;\n"
887 " cookie-E<gt>buf = NULL;\n"
888 "\\&\n"
889 " return 0;\n"
890 "}\n"
891 "\\&\n"
892 "int\n"
893 "main(int argc, char *argv[])\n"
894 "{\n"
895 " cookie_io_functions_t memfile_func = {\n"
896 " .read = memfile_read,\n"
897 " .write = memfile_write,\n"
898 " .seek = memfile_seek,\n"
899 " .close = memfile_close\n"
900 " };\n"
901 " FILE *stream;\n"
902 " struct memfile_cookie mycookie;\n"
903 " size_t nread;\n"
904 " char buf[1000];\n"
905 "\\&\n"
906 " /* Set up the cookie before calling fopencookie(). */\n"
907 "\\&\n"
908 " mycookie.buf = malloc(INIT_BUF_SIZE);\n"
909 " if (mycookie.buf == NULL) {\n"
910 " perror(\"malloc\");\n"
911 " exit(EXIT_FAILURE);\n"
912 " }\n"
913 "\\&\n"
914 " mycookie.allocated = INIT_BUF_SIZE;\n"
915 " mycookie.offset = 0;\n"
916 " mycookie.endpos = 0;\n"
917 "\\&\n"
918 " stream = fopencookie(&mycookie, \"w+\", memfile_func);\n"
919 " if (stream == NULL) {\n"
920 " perror(\"fopencookie\");\n"
921 " exit(EXIT_FAILURE);\n"
922 " }\n"
923 "\\&\n"
924 " /* Write command-line arguments to our file. */\n"
925 "\\&\n"
926 " for (size_t j = 1; j E<lt> argc; j++)\n"
927 " if (fputs(argv[j], stream) == EOF) {\n"
928 " perror(\"fputs\");\n"
929 " exit(EXIT_FAILURE);\n"
930 " }\n"
931 "\\&\n"
932 " /* Read two bytes out of every five, until EOF. */\n"
933 "\\&\n"
934 " for (long p = 0; ; p += 5) {\n"
935 " if (fseek(stream, p, SEEK_SET) == -1) {\n"
936 " perror(\"fseek\");\n"
937 " exit(EXIT_FAILURE);\n"
938 " }\n"
939 " nread = fread(buf, 1, 2, stream);\n"
940 " if (nread == 0) {\n"
941 " if (ferror(stream) != 0) {\n"
942 " fprintf(stderr, \"fread failed\\[rs]n\");\n"
943 " exit(EXIT_FAILURE);\n"
944 " }\n"
945 " printf(\"Reached end of file\\[rs]n\");\n"
946 " break;\n"
947 " }\n"
948 "\\&\n"
949 " printf(\"/%.*s/\\[rs]n\", (int) nread, buf);\n"
950 " }\n"
951 "\\&\n"
952 " free(mycookie.buf);\n"
953 "\\&\n"
954 " exit(EXIT_SUCCESS);\n"
955 "}\n"
956 msgstr ""
957
958 #. type: TH
959 #: fedora-44 fedora-rawhide
960 #, no-wrap
961 msgid "2024-07-23"
962 msgstr ""
963
964 #. type: TH
965 #: fedora-44 fedora-rawhide
966 #, no-wrap
967 msgid "Linux man-pages 6.13"
968 msgstr ""
969
970 #. type: TH
971 #: mageia-cauldron
972 #, no-wrap
973 msgid "Linux man-pages 6.17"
974 msgstr ""
975
976 #. type: TH
977 #: opensuse-leap-16-1 opensuse-tumbleweed
978 #, no-wrap
979 msgid "Linux man-pages (unreleased)"
980 msgstr ""