stdio.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU Lesser General Public
  4. License version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details.
  6. Module Name:
  7. stdio.h
  8. Abstract:
  9. This header contains standard C input and output definitions.
  10. Author:
  11. Evan Green 4-Mar-2013
  12. --*/
  13. #ifndef _STDIO_H
  14. #define _STDIO_H
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. #include <libcbase.h>
  19. #include <sys/types.h>
  20. #include <stdarg.h>
  21. #include <stddef.h>
  22. //
  23. // ---------------------------------------------------------------- Definitions
  24. //
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. //
  29. // Define the End Of File value returned by some file operation functions.
  30. //
  31. #define EOF (-1)
  32. //
  33. // Define the size of the standard I/O file stream buffers.
  34. //
  35. #define BUFSIZ 8192
  36. //
  37. // Define file buffering modes.
  38. //
  39. //
  40. // In this mode files are fully buffered, meaning they will use the internal
  41. // stream buffer to batch calls to the operating system as much as possible.
  42. //
  43. #define _IOFBF 1
  44. //
  45. // In this mode files are line buffered, which is the same as fully buffered
  46. // except a flush occurs whenever a newline is output.
  47. //
  48. #define _IOLBF 2
  49. //
  50. // In this mode files are not buffered, all reads and writes go directly to the
  51. // low level file interface.
  52. //
  53. #define _IONBF 3
  54. //
  55. // Define seek reference locations.
  56. //
  57. //
  58. // Specify this value to indicate that an offset starts from the beginning of
  59. // the file (the offset is set directly as the file pointer).
  60. //
  61. #define SEEK_SET 0
  62. //
  63. // Specify this value to indicate that the offset should be added to the
  64. // current file position.
  65. //
  66. #define SEEK_CUR 1
  67. //
  68. // Specify this value to indicate that the offset should be added to the end
  69. // of the file.
  70. //
  71. #define SEEK_END 2
  72. //
  73. // Define the maximum number of streams which the implementation guarantees
  74. // can be open simultaneously. It's effectively limitless, but a value is
  75. // presented here for compatibility.
  76. //
  77. #define FOPEN_MAX 16
  78. //
  79. // Define the maximum size of a temporary file name.
  80. //
  81. #define L_tmpnam 20
  82. //
  83. // Define the maximum size of the controlling terminal.
  84. //
  85. #define L_ctermid 256
  86. //
  87. // Define the location of a temporary directory.
  88. //
  89. #define P_tmpdir "/tmp"
  90. //
  91. // Define the number of times an application can call the temporary file name
  92. // functions reliably.
  93. //
  94. #define TMP_MAX 60466176
  95. //
  96. // Define the maximum reliable length of a file name.
  97. //
  98. #define FILENAME_MAX 4096
  99. //
  100. // ------------------------------------------------------ Data Type Definitions
  101. //
  102. //
  103. // Define the opaque file type.
  104. //
  105. typedef struct _FILE FILE;
  106. //
  107. // Define the multibyte state in here as opposed to wchar.h to avoid a nasty
  108. // circular dependency where stdio.h needs mbstate_t, but wchar.h needs FILE.
  109. //
  110. /*++
  111. Structure Description:
  112. This structure stores the current shift state for a multibyte character
  113. conversion.
  114. Members:
  115. Data - Stores the opaque multibyte state data.
  116. --*/
  117. typedef struct {
  118. long Data[6];
  119. } mbstate_t;
  120. /*++
  121. Structure Description:
  122. This structure defines the type used for completely specifying a file type.
  123. Users must treat this as an opaque type, as its contents may change without
  124. notice.
  125. Members:
  126. Offset - Storees the file offset.
  127. ShiftState - Stores the multi-byte shift state at the given offset.
  128. --*/
  129. typedef struct {
  130. off_t Offset;
  131. mbstate_t ShiftState;
  132. } fpos_t;
  133. //
  134. // -------------------------------------------------------------------- Globals
  135. //
  136. //
  137. // Define the standard file pointers.
  138. //
  139. LIBC_API extern FILE *stdin;
  140. LIBC_API extern FILE *stdout;
  141. LIBC_API extern FILE *stderr;
  142. //
  143. // -------------------------------------------------------- Function Prototypes
  144. //
  145. LIBC_API
  146. char *
  147. ctermid (
  148. char *Buffer
  149. );
  150. /*++
  151. Routine Description:
  152. This routine returns the null-terminated path of the controlling terminal
  153. for the current process. Access to the terminal path returned by this
  154. function is not guaranteed.
  155. Arguments:
  156. Buffer - Supplies an optional pointer to a buffer of at least length
  157. L_ctermid where the path to the terminal will be returned. If this is
  158. NULL, static storage will be used and returned, in which case the
  159. caller should not modify or free the buffer.
  160. Return Value:
  161. Returns a pointer to the string containing the path of the controlling
  162. terminal on success.
  163. NULL on failure.
  164. --*/
  165. LIBC_API
  166. char *
  167. ctermid_r (
  168. char *Buffer
  169. );
  170. /*++
  171. Routine Description:
  172. This routine returns the null-terminated path of the controlling terminal
  173. for the current process.
  174. Arguments:
  175. Buffer - Supplies a pointer to a buffer of at least length L_ctermid where
  176. the path to the terminal will be returned.
  177. Return Value:
  178. Returns a pointer to the supplied buffer on success.
  179. NULL on failure.
  180. --*/
  181. LIBC_API
  182. int
  183. rename (
  184. const char *SourcePath,
  185. const char *DestinationPath
  186. );
  187. /*++
  188. Routine Description:
  189. This routine attempts to rename the object at the given path. This routine
  190. operates on symbolic links themselves, not the destinations of symbolic
  191. links. If the source and destination paths are equal, this routine will do
  192. nothing and return successfully. If the source path is not a directory, the
  193. destination path must not be a directory. If the destination file exists,
  194. it will be deleted. The caller must have write access in both the old and
  195. new directories. If the source path is a directory, the destination path
  196. must not exist or be an empty directory. The destination path must not have
  197. a path prefix of the source (ie it's illegal to move /my/path into
  198. /my/path/stuff).
  199. Arguments:
  200. SourcePath - Supplies a pointer to a null terminated string containing the
  201. name of the file or directory to rename.
  202. DestinationPath - Supplies a pointer to a null terminated string
  203. containing the path to rename the file or directory to. This path
  204. cannot span file systems.
  205. Return Value:
  206. 0 on success.
  207. -1 on failure, and the errno variable will be set to contain more
  208. information.
  209. --*/
  210. LIBC_API
  211. int
  212. renameat (
  213. int SourceDirectory,
  214. const char *SourcePath,
  215. int DestinationDirectory,
  216. const char *DestinationPath
  217. );
  218. /*++
  219. Routine Description:
  220. This routine operates the same as the rename function, except it allows
  221. relative source and/or destination paths to begin from a directory
  222. specified by the given file descriptors.
  223. Arguments:
  224. SourceDirectory - Supplies a file descriptor to the directory to start
  225. source path searches from. If the source path is absolute, this value
  226. is ignored. If this is AT_FDCWD, then source path searches will
  227. start from the current working directory.
  228. SourcePath - Supplies a pointer to a null terminated string containing the
  229. name of the file or directory to rename.
  230. DestinationPath - Supplies a pointer to a null terminated string
  231. containing the path to rename the file or directory to. This path
  232. cannot span file systems.
  233. DestinationDirectory - Supplies an optional file descriptor to the
  234. directory to start destination path searches from. If the destination
  235. path is absolute, this value is ignored. If this is AT_FDCWD, then
  236. destination path searches will start from the current working directory.
  237. Return Value:
  238. 0 on success.
  239. -1 on failure, and the errno variable will be set to contain more
  240. information.
  241. --*/
  242. LIBC_API
  243. int
  244. remove (
  245. const char *Path
  246. );
  247. /*++
  248. Routine Description:
  249. This routine attempts to delete the object at the given path. If the
  250. object pointed to by the given path is a directory, the behavior of remove
  251. is identical to rmdir. Otherwise, the behavior of remove is identical to
  252. unlink.
  253. Arguments:
  254. Path - Supplies a pointer to a null terminated string containing the path
  255. of the entry to remove.
  256. Return Value:
  257. 0 on success.
  258. -1 on failure, and errno will be set to provide more details. In failure
  259. cases, the directory will not be removed.
  260. --*/
  261. LIBC_API
  262. FILE *
  263. fopen (
  264. const char *FileName,
  265. const char *Mode
  266. );
  267. /*++
  268. Routine Description:
  269. This routine opens the given file and associates a stream with it.
  270. Arguments:
  271. FileName - Supplies a pointer to a string containing the path to the file
  272. to open.
  273. Mode - Supplies a pointer to a null terminated string specifying the mode
  274. to open the file with. Valid value are "r", "w", "a", and may optionally
  275. have a + or b appended to it. The + symbol opens the file for updating,
  276. meaning that the system does not flush immediately after writes. The "b"
  277. option has no effect.
  278. Return Value:
  279. Returns a pointer to the file stream on success.
  280. NULL on failure, and errno contains more information.
  281. --*/
  282. LIBC_API
  283. FILE *
  284. fdopen (
  285. int OpenFileDescriptor,
  286. const char *Mode
  287. );
  288. /*++
  289. Routine Description:
  290. This routine associates a stream with the given file descriptor. The mode
  291. argument must agree with the flags the original descriptor was opened with.
  292. On success, the stream now "owns" the file descriptor, a call to fclose
  293. on the stream will also call close on the underlying descriptor.
  294. Arguments:
  295. OpenFileDescriptor - Supplies the open file descriptor to create a stream
  296. around.
  297. Mode - Supplies a pointer to a null terminated string specifying the mode
  298. to open the file with. Valid value are "r", "w", "a", and may optionally
  299. have a + or b appended to it. The + symbol opens the file for updating,
  300. meaning that the system does not flush immediately after writes. The "b"
  301. option has no effect.
  302. Return Value:
  303. Returns a pointer to the file stream on success.
  304. NULL on failure, and errno contains more information.
  305. --*/
  306. LIBC_API
  307. FILE *
  308. freopen (
  309. const char *FileName,
  310. const char *Mode,
  311. FILE *Stream
  312. );
  313. /*++
  314. Routine Description:
  315. This routine attempts to flush the given stream and close any file
  316. descriptor associated with the stream. Failure to flush or close the
  317. file descriptor is ignored. The error and end-of-file indicators are
  318. cleared. This routine then attempts to open the given file with the given
  319. mode and associate it with the stream. The previous file descriptor
  320. associated with this stream is closed whether or not the new descriptor
  321. could be opened.
  322. The standard says that passing in NULL for the file name will change the
  323. permissions of the existing descriptor. This implementation currently does
  324. not support that and sets errno to EBADF if attempted.
  325. Arguments:
  326. FileName - Supplies a pointer to the path to open and associate with this
  327. stream.
  328. Mode - Supplies a pointer to the string describing the desired access to
  329. this path. This takes the same format as the fopen mode string.
  330. Stream - Supplies a pointer to the open stream.
  331. Return Value:
  332. Returns a pointer to the given stream on success, now with a different
  333. file descriptor.
  334. NULL on failure, and errno will be set to contain more information.
  335. --*/
  336. LIBC_API
  337. int
  338. fclose (
  339. FILE *Stream
  340. );
  341. /*++
  342. Routine Description:
  343. This routine closes an open file stream.
  344. Arguments:
  345. Stream - Supplies a pointer to the open stream.
  346. Return Value:
  347. 0 on success.
  348. Returns EOF if there was an error flushing or closing the stream.
  349. --*/
  350. LIBC_API
  351. size_t
  352. fread (
  353. void *Buffer,
  354. size_t Size,
  355. size_t ItemCount,
  356. FILE *Stream
  357. );
  358. /*++
  359. Routine Description:
  360. This routine reads from a file stream.
  361. Arguments:
  362. Buffer - Supplies a pointer to the buffer where the data will be returned.
  363. Size - Supplies the size of each element to read.
  364. ItemCount - Supplies the number of elements to read.
  365. Stream - Supplies a pointer to the file stream object to read from.
  366. Return Value:
  367. Returns the number of elements successfully read from the file. On failure,
  368. the error indicator for the stream will be set, and errno will set to
  369. provide details on the error that occurred.
  370. --*/
  371. LIBC_API
  372. size_t
  373. fread_unlocked (
  374. void *Buffer,
  375. size_t Size,
  376. size_t ItemCount,
  377. FILE *Stream
  378. );
  379. /*++
  380. Routine Description:
  381. This routine reads from a file stream without acquiring the internal file
  382. lock.
  383. Arguments:
  384. Buffer - Supplies a pointer to the buffer where the data will be returned.
  385. Size - Supplies the size of each element to read.
  386. ItemCount - Supplies the number of elements to read.
  387. Stream - Supplies a pointer to the file stream object to read from.
  388. Return Value:
  389. Returns the number of elements successfully read from the file. On failure,
  390. the error indicator for the stream will be set, and errno will set to
  391. provide details on the error that occurred.
  392. --*/
  393. LIBC_API
  394. size_t
  395. fwrite (
  396. const void *Buffer,
  397. size_t Size,
  398. size_t ItemCount,
  399. FILE *Stream
  400. );
  401. /*++
  402. Routine Description:
  403. This routine writes to a file stream.
  404. Arguments:
  405. Buffer - Supplies a pointer to the buffer containing the data to write.
  406. Size - Supplies the size of each element to write.
  407. ItemCount - Supplies the number of elements to write.
  408. Stream - Supplies a pointer to the file stream object to write to.
  409. Return Value:
  410. Returns the number of elements successfully written to the file. On failure,
  411. the error indicator for the stream will be set, and errno will set to
  412. provide details on the error that occurred.
  413. --*/
  414. LIBC_API
  415. size_t
  416. fwrite_unlocked (
  417. const void *Buffer,
  418. size_t Size,
  419. size_t ItemCount,
  420. FILE *Stream
  421. );
  422. /*++
  423. Routine Description:
  424. This routine writes to a file stream without acquiring the internal file
  425. lock.
  426. Arguments:
  427. Buffer - Supplies a pointer to the buffer containing the data to write.
  428. Size - Supplies the size of each element to write.
  429. ItemCount - Supplies the number of elements to write.
  430. Stream - Supplies a pointer to the file stream object to write to.
  431. Return Value:
  432. Returns the number of elements successfully written to the file. On failure,
  433. the error indicator for the stream will be set, and errno will set to
  434. provide details on the error that occurred.
  435. --*/
  436. LIBC_API
  437. int
  438. fflush (
  439. FILE *Stream
  440. );
  441. /*++
  442. Routine Description:
  443. This routine flushes any data sitting in the file stream that has not yet
  444. made it out to the operating system. This is only relevant for output
  445. streams.
  446. Arguments:
  447. Stream - Supplies a pointer to the open file stream to flush.
  448. Return Value:
  449. 0 on success.
  450. EOF on failure, and errno will be set to contain more information.
  451. --*/
  452. LIBC_API
  453. int
  454. fflush_unlocked (
  455. FILE *Stream
  456. );
  457. /*++
  458. Routine Description:
  459. This routine flushes any data sitting in the file stream that has not yet
  460. made it out to the operating system. This routine does not acquire the
  461. internal stream lock. This is only relevant for output streams.
  462. Arguments:
  463. Stream - Supplies a pointer to the open file stream to flush.
  464. Return Value:
  465. 0 on success.
  466. EOF on failure, and errno will be set to contain more information.
  467. --*/
  468. LIBC_API
  469. long
  470. ftell (
  471. FILE *Stream
  472. );
  473. /*++
  474. Routine Description:
  475. This routine returns the given stream's file position.
  476. Arguments:
  477. Stream - Supplies a pointer to the open file stream.
  478. Return Value:
  479. Returns the current file position on success.
  480. -1 on failure, and errno will be set to contain more information.
  481. --*/
  482. LIBC_API
  483. off_t
  484. ftello (
  485. FILE *Stream
  486. );
  487. /*++
  488. Routine Description:
  489. This routine returns the given stream's file position.
  490. Arguments:
  491. Stream - Supplies a pointer to the open file stream.
  492. Return Value:
  493. Returns the current file position on success.
  494. -1 on failure, and errno will be set to contain more information.
  495. --*/
  496. LIBC_API
  497. off64_t
  498. ftello64 (
  499. FILE *Stream
  500. );
  501. /*++
  502. Routine Description:
  503. This routine returns the given stream's file position.
  504. Arguments:
  505. Stream - Supplies a pointer to the open file stream.
  506. Return Value:
  507. Returns the current file position on success.
  508. -1 on failure, and errno will be set to contain more information.
  509. --*/
  510. LIBC_API
  511. off_t
  512. ftello_unlocked (
  513. FILE *Stream
  514. );
  515. /*++
  516. Routine Description:
  517. This routine returns the given stream's file position.
  518. Arguments:
  519. Stream - Supplies a pointer to the open file stream.
  520. Return Value:
  521. Returns the current file position on success.
  522. -1 on failure, and errno will be set to contain more information.
  523. --*/
  524. LIBC_API
  525. int
  526. fseek (
  527. FILE *Stream,
  528. long Offset,
  529. int Whence
  530. );
  531. /*++
  532. Routine Description:
  533. This routine sets the file position indicator for the given stream. If a
  534. read or write error occurs, the error indicator will be set for the stream
  535. and fseek fails. This routine will undo any effects of a previous call to
  536. unget.
  537. Arguments:
  538. Stream - Supplies a pointer to the open file stream.
  539. Offset - Supplies the offset from the reference point given in the Whence
  540. argument.
  541. Whence - Supplies the reference location to base the offset off of. Valid
  542. value are:
  543. SEEK_SET - The offset will be added to the the beginning of the file.
  544. SEEK_CUR - The offset will be added to the current file position.
  545. SEEK_END - The offset will be added to the end of the file.
  546. Return Value:
  547. 0 on success.
  548. -1 on failure, and errno will be set to contain more information.
  549. --*/
  550. LIBC_API
  551. int
  552. fseeko (
  553. FILE *Stream,
  554. off_t Offset,
  555. int Whence
  556. );
  557. /*++
  558. Routine Description:
  559. This routine sets the file position indicator for the given stream. If a
  560. read or write error occurs, the error indicator will be set for the stream
  561. and fseek fails. This routine will undo any effects of a previous call to
  562. unget.
  563. Arguments:
  564. Stream - Supplies a pointer to the open file stream.
  565. Offset - Supplies the offset from the reference point given in the Whence
  566. argument.
  567. Whence - Supplies the reference location to base the offset off of. Valid
  568. value are:
  569. SEEK_SET - The offset will be added to the the beginning of the file.
  570. SEEK_CUR - The offset will be added to the current file position.
  571. SEEK_END - The offset will be added to the end of the file.
  572. Return Value:
  573. 0 on success.
  574. -1 on failure, and errno will be set to contain more information.
  575. --*/
  576. LIBC_API
  577. int
  578. fseeko64 (
  579. FILE *Stream,
  580. off64_t Offset,
  581. int Whence
  582. );
  583. /*++
  584. Routine Description:
  585. This routine sets the file position indicator for the given stream. If a
  586. read or write error occurs, the error indicator will be set for the stream
  587. and fseek fails. This routine will undo any effects of a previous call to
  588. unget.
  589. Arguments:
  590. Stream - Supplies a pointer to the open file stream.
  591. Offset - Supplies the offset from the reference point given in the Whence
  592. argument.
  593. Whence - Supplies the reference location to base the offset off of. Valid
  594. value are:
  595. SEEK_SET - The offset will be added to the the beginning of the file.
  596. SEEK_CUR - The offset will be added to the current file position.
  597. SEEK_END - The offset will be added to the end of the file.
  598. Return Value:
  599. 0 on success.
  600. -1 on failure, and errno will be set to contain more information.
  601. --*/
  602. LIBC_API
  603. int
  604. fseeko_unlocked (
  605. FILE *Stream,
  606. off_t Offset,
  607. int Whence
  608. );
  609. /*++
  610. Routine Description:
  611. This routine sets the file position indicator for the given stream. If a
  612. read or write error occurs, the error indicator will be set for the stream
  613. and fseek fails. This routine does not acquire the internal stream lock.
  614. Arguments:
  615. Stream - Supplies a pointer to the open file stream.
  616. Offset - Supplies the offset from the reference point given in the Whence
  617. argument.
  618. Whence - Supplies the reference location to base the offset off of. Valid
  619. value are:
  620. SEEK_SET - The offset will be added to the the beginning of the file.
  621. SEEK_CUR - The offset will be added to the current file position.
  622. SEEK_END - The offset will be added to the end of the file.
  623. Return Value:
  624. 0 on success.
  625. -1 on failure, and errno will be set to contain more information.
  626. --*/
  627. LIBC_API
  628. int
  629. fgetpos (
  630. FILE *Stream,
  631. fpos_t *Position
  632. );
  633. /*++
  634. Routine Description:
  635. This routine returns an opaque structure representing the current absolute
  636. position within the given stream.
  637. Arguments:
  638. Stream - Supplies a pointer to the open file stream.
  639. Position - Supplies a pointer where the opaque position will be returned.
  640. Callers must not presume that they can cast this type to an integer or
  641. compare these types in any way, they only serve as possible inputs to
  642. fsetpos to restore a file position to its current location.
  643. Return Value:
  644. 0 on success.
  645. -1 on failure, and errno will contain more information.
  646. --*/
  647. LIBC_API
  648. int
  649. fsetpos (
  650. FILE *Stream,
  651. const fpos_t *Position
  652. );
  653. /*++
  654. Routine Description:
  655. This routine sets the current file position.
  656. Arguments:
  657. Stream - Supplies a pointer to the open file stream.
  658. Position - Supplies a pointer where the opaque position that was returned
  659. by a previous call to fgetpos.
  660. Return Value:
  661. 0 on success.
  662. -1 on failure, and errno will contain more information.
  663. --*/
  664. LIBC_API
  665. void
  666. rewind (
  667. FILE *Stream
  668. );
  669. /*++
  670. Routine Description:
  671. This routine positions the file indicator back to the beginning. It shall
  672. be equivalent to fseek(Stream, 0, SEEK_SET) except that it also clears
  673. the error indicator.
  674. Arguments:
  675. Stream - Supplies a pointer to the open file stream.
  676. Return Value:
  677. None. Applications wishing to detect an error occurring during this
  678. function should set errno 0, call the function, and then check errno.
  679. --*/
  680. LIBC_API
  681. int
  682. fileno (
  683. FILE *Stream
  684. );
  685. /*++
  686. Routine Description:
  687. This routine returns the integer file descriptor associated with the given
  688. stream.
  689. Arguments:
  690. Stream - Supplies a pointer to the open file stream.
  691. Return Value:
  692. Returns the integer value of the file descriptor associated with the given
  693. stream on success.
  694. -1 on failure, and errno will contain more information.
  695. --*/
  696. LIBC_API
  697. int
  698. fgetc (
  699. FILE *Stream
  700. );
  701. /*++
  702. Routine Description:
  703. This routine reads one byte from the given file stream.
  704. Arguments:
  705. Stream - Supplies a pointer to the open file stream.
  706. Return Value:
  707. Returns the byte on success.
  708. EOF on failure or the end of the file, and errno will contain more
  709. information.
  710. --*/
  711. LIBC_API
  712. int
  713. fgetc_unlocked (
  714. FILE *Stream
  715. );
  716. /*++
  717. Routine Description:
  718. This routine reads one byte from the given file stream without acquiring
  719. the internal stream lock.
  720. Arguments:
  721. Stream - Supplies a pointer to the open file stream.
  722. Return Value:
  723. Returns the byte on success.
  724. EOF on failure or the end of the file, and errno will contain more
  725. information.
  726. --*/
  727. LIBC_API
  728. int
  729. getchar (
  730. void
  731. );
  732. /*++
  733. Routine Description:
  734. This routine reads one byte from stdin.
  735. Arguments:
  736. None.
  737. Return Value:
  738. Returns the byte from stdin on success.
  739. -1 on failure, and errno will contain more information.
  740. --*/
  741. LIBC_API
  742. int
  743. getchar_unlocked (
  744. void
  745. );
  746. /*++
  747. Routine Description:
  748. This routine reads one byte from stdin without acquiring the file lock.
  749. Arguments:
  750. None.
  751. Return Value:
  752. Returns the byte from stdin on success.
  753. -1 on failure, and errno will contain more information.
  754. --*/
  755. LIBC_API
  756. int
  757. getc (
  758. FILE *Stream
  759. );
  760. /*++
  761. Routine Description:
  762. This routine reads one byte from the given file stream. It is equivalent to
  763. the fgetc function.
  764. Arguments:
  765. Stream - Supplies a pointer to the open file stream.
  766. Return Value:
  767. Returns the byte on success.
  768. EOF on failure or the end of the file, and errno will contain more
  769. information.
  770. --*/
  771. LIBC_API
  772. int
  773. getc_unlocked (
  774. FILE *Stream
  775. );
  776. /*++
  777. Routine Description:
  778. This routine reads one byte from the given file stream, without acquiring
  779. the internal file lock. It is equivalent to the fgetc_unlocked function.
  780. Arguments:
  781. Stream - Supplies a pointer to the open file stream.
  782. Return Value:
  783. Returns the byte on success.
  784. EOF on failure or the end of the file, and errno will contain more
  785. information.
  786. --*/
  787. LIBC_API
  788. char *
  789. gets (
  790. char *Line
  791. );
  792. /*++
  793. Routine Description:
  794. This routine gets a line of input from standard in, writing bytes to the
  795. supplied line until a newline or end of file is reached. The newline (if
  796. found) will be discarded and the string null terminated.
  797. Use of this function is highly discouraged, as there is no bound on the
  798. size of text the user can put on one line. Any use of this function is a
  799. security hole. Use fgets instead.
  800. Arguments:
  801. Line - Supplies a pointer where the line will be returned on success.
  802. Return Value:
  803. Returns a pointer to the supplied line buffer on success.
  804. NULL if EOF was encountered.
  805. --*/
  806. LIBC_API
  807. char *
  808. fgets (
  809. char *Buffer,
  810. int BufferSize,
  811. FILE *Stream
  812. );
  813. /*++
  814. Routine Description:
  815. This routine reads bytes from the given stream and places them in the
  816. given buffer until the buffer fills up, a newline is read and transferred,
  817. or the end of the file is reached. The string is then terminated with a
  818. null byte.
  819. Arguments:
  820. Buffer - Supplies a pointer to the buffer where the read characters should
  821. be returned.
  822. BufferSize - Supplies the size of the supplied buffer in bytes.
  823. Stream - Supplies a pointer to the file stream to read out of.
  824. Return Value:
  825. Returns the given buffer on success. If the stream is at end-of-file, the
  826. end-of-file indicator shall be set and this routine returns NULL. If a
  827. read error occurs, the error indicator for the stream shall be set, and
  828. this routine returns NULL. The errno variable may also be set to contain
  829. more information.
  830. --*/
  831. LIBC_API
  832. char *
  833. fgets_unlocked (
  834. char *Buffer,
  835. int BufferSize,
  836. FILE *Stream
  837. );
  838. /*++
  839. Routine Description:
  840. This routine reads bytes from the given stream and places them in the
  841. given buffer until the buffer fills up, a newline is read and transferred,
  842. or the end of the file is reached. The string is then terminated with a
  843. null byte.
  844. Arguments:
  845. Buffer - Supplies a pointer to the buffer where the read characters should
  846. be returned.
  847. BufferSize - Supplies the size of the supplied buffer in bytes.
  848. Stream - Supplies a pointer to the file stream to read out of.
  849. Return Value:
  850. Returns the given buffer on success. If the stream is at end-of-file, the
  851. end-of-file indicator shall be set and this routine returns NULL. If a
  852. read error occurs, the error indicator for the stream shall be set, and
  853. this routine returns NULL. The errno variable may also be set to contain
  854. more information.
  855. --*/
  856. LIBC_API
  857. int
  858. fputc (
  859. int Character,
  860. FILE *Stream
  861. );
  862. /*++
  863. Routine Description:
  864. This routine writes a byte to the given file stream.
  865. Arguments:
  866. Character - Supplies the character (converted to an unsigned char) to
  867. write.
  868. Stream - Supplies the stream to write the character to.
  869. Return Value:
  870. Returns the byte it has written on success.
  871. EOF on failure, and errno will contain more information.
  872. --*/
  873. LIBC_API
  874. int
  875. fputc_unlocked (
  876. int Character,
  877. FILE *Stream
  878. );
  879. /*++
  880. Routine Description:
  881. This routine writes a byte to the given file stream without acquiring the
  882. internal stream lock.
  883. Arguments:
  884. Character - Supplies the character (converted to an unsigned char) to
  885. write.
  886. Stream - Supplies the stream to write the character to.
  887. Return Value:
  888. Returns the byte it has written on success.
  889. EOF on failure, and errno will contain more information.
  890. --*/
  891. LIBC_API
  892. int
  893. putc (
  894. int Character,
  895. FILE *Stream
  896. );
  897. /*++
  898. Routine Description:
  899. This routine writes a byte to the given file stream. It is equivalent to
  900. the fputc function.
  901. Arguments:
  902. Character - Supplies the character (converted to an unsigned char) to
  903. write.
  904. Stream - Supplies the stream to write the character to.
  905. Return Value:
  906. Returns the byte it has written on success.
  907. EOF on failure, and errno will contain more information.
  908. --*/
  909. LIBC_API
  910. int
  911. putc_unlocked (
  912. int Character,
  913. FILE *Stream
  914. );
  915. /*++
  916. Routine Description:
  917. This routine writes a byte to the given file stream without acquiring the
  918. stream lock. It is equivalent to the fputc_unlocked function.
  919. Arguments:
  920. Character - Supplies the character (converted to an unsigned char) to
  921. write.
  922. Stream - Supplies the stream to write the character to.
  923. Return Value:
  924. Returns the byte it has written on success.
  925. EOF on failure, and errno will contain more information.
  926. --*/
  927. LIBC_API
  928. int
  929. putchar (
  930. int Character
  931. );
  932. /*++
  933. Routine Description:
  934. This routine writes a byte to standard out. This routine is equivalent to
  935. fputc(Character, stdout).
  936. Arguments:
  937. Character - Supplies the character (converted to an unsigned char) to
  938. write.
  939. Return Value:
  940. Returns the byte it has written on success.
  941. EOF on failure, and errno will contain more information.
  942. --*/
  943. LIBC_API
  944. int
  945. putchar_unlocked (
  946. int Character
  947. );
  948. /*++
  949. Routine Description:
  950. This routine writes a byte to standard out, without acquiring the stream
  951. lock. This routine is equivalent to fputc_unlocked(Character, stdout).
  952. Arguments:
  953. Character - Supplies the character (converted to an unsigned char) to
  954. write.
  955. Return Value:
  956. Returns the byte it has written on success.
  957. EOF on failure, and errno will contain more information.
  958. --*/
  959. LIBC_API
  960. int
  961. puts (
  962. const char *String
  963. );
  964. /*++
  965. Routine Description:
  966. This routine writes the given string to standard out. The null terminating
  967. byte is not written.
  968. Arguments:
  969. String - Supplies a pointer to the null terminated string to write to.
  970. Stream - Supplies the stream to write the character to.
  971. Return Value:
  972. Returns a non-negative number on success.
  973. Returns EOF on failure, and the error indicator will be set for the stream.
  974. The errno variable will also be set to provide more information.
  975. --*/
  976. LIBC_API
  977. int
  978. fputs (
  979. const char *String,
  980. FILE *Stream
  981. );
  982. /*++
  983. Routine Description:
  984. This routine writes the given string to the given file stream. The null
  985. terminating byte is not written.
  986. Arguments:
  987. String - Supplies a pointer to the null terminated string to write to.
  988. Stream - Supplies the stream to write the character to.
  989. Return Value:
  990. Returns a non-negative number on success.
  991. Returns EOF on failure, and the error indicator will be set for the stream.
  992. The errno variable will also be set to provide more information.
  993. --*/
  994. LIBC_API
  995. int
  996. fputs_unlocked (
  997. const char *String,
  998. FILE *Stream
  999. );
  1000. /*++
  1001. Routine Description:
  1002. This routine writes the given string to the given file stream. The null
  1003. terminating byte is not written. This routine does not acquire the stream
  1004. lock.
  1005. Arguments:
  1006. String - Supplies a pointer to the null terminated string to write to.
  1007. Stream - Supplies the stream to write the character to.
  1008. Return Value:
  1009. Returns a non-negative number on success.
  1010. Returns EOF on failure, and the error indicator will be set for the stream.
  1011. The errno variable will also be set to provide more information.
  1012. --*/
  1013. LIBC_API
  1014. int
  1015. ungetc (
  1016. int Character,
  1017. FILE *Stream
  1018. );
  1019. /*++
  1020. Routine Description:
  1021. This routine pushes the specified character back onto the input stream. The
  1022. pushed back character shall be returned by subsequent reads on that stream
  1023. in the reverse order of their pushing. A successful intervening call to
  1024. seek or flush will discard any pushed back bytes for the stream. One byte
  1025. of push back is provided.
  1026. Arguments:
  1027. Character - Supplies the character (converted to an unsigned char) to
  1028. push back.
  1029. Stream - Supplies the stream to push the character on to.
  1030. Return Value:
  1031. Returns the byte pushed back on success.
  1032. EOF on failure, and errno will contain more information.
  1033. --*/
  1034. LIBC_API
  1035. int
  1036. ungetc_unlocked (
  1037. int Character,
  1038. FILE *Stream
  1039. );
  1040. /*++
  1041. Routine Description:
  1042. This routine pushes the specified character back onto the input stream. The
  1043. pushed back character shall be returned by subsequent reads on that stream
  1044. in the reverse order of their pushing. A successful intervening call to
  1045. seek or flush will discard any pushed back bytes for the stream. One byte
  1046. of push back is provided. This routine does not acquire the internal
  1047. stream lock.
  1048. Arguments:
  1049. Character - Supplies the character (converted to an unsigned char) to
  1050. push back.
  1051. Stream - Supplies the stream to push the character on to.
  1052. Return Value:
  1053. Returns the byte pushed back on success.
  1054. EOF on failure, and errno will contain more information.
  1055. --*/
  1056. LIBC_API
  1057. int
  1058. setvbuf (
  1059. FILE *Stream,
  1060. char *Buffer,
  1061. int Mode,
  1062. size_t BufferSize
  1063. );
  1064. /*++
  1065. Routine Description:
  1066. This routine sets the buffering mode and buffer (optionally) for the given
  1067. file stream.
  1068. Arguments:
  1069. Stream - Supplies a pointer to the file stream whose buffering
  1070. characteristics should be altered.
  1071. Buffer - Supplies an optional pointer to the buffer to use for fully
  1072. buffered or line buffered mode. If either of those two modes are
  1073. supplied and this buffer is not supplied, one will be malloced.
  1074. Mode - Supplies the buffering mode to set for this file stream. Valid
  1075. value are:
  1076. _IONBF - Disable buffering on this file stream. All reads and writes
  1077. will go straight to the low level I/O interface.
  1078. _IOFBF - Fully buffered mode. The stream interface will batch reads
  1079. and writes to the low level I/O interface to optimize performance.
  1080. _IOLBF - Line buffered mode. This mode behaves the same as fully
  1081. buffered mode, except that the buffer is flushed automatically when
  1082. a newline character is written to the stream. For input buffers,
  1083. the behavior is no different from fully buffered mode.
  1084. BufferSize - Supplies the size of the supplied buffer in bytes.
  1085. Return Value:
  1086. 0 on success.
  1087. -1 on failure, and errno will contain more information.
  1088. --*/
  1089. LIBC_API
  1090. void
  1091. setbuf (
  1092. FILE *Stream,
  1093. char *Buffer
  1094. );
  1095. /*++
  1096. Routine Description:
  1097. This routine sets the internal buffer on a stream. If the given buffer is
  1098. not NULL, this routine shall be equivalent to:
  1099. setvbuf(Stream, Buffer, _IOFBF, BUFSIZ);
  1100. or,
  1101. setvbuf(Stream, Buffer, _IONBF, BUFSIZ);
  1102. if the given buffer is a NULL pointer.
  1103. Arguments:
  1104. Stream - Supplies a pointer to the file stream.
  1105. Buffer - Supplies the optional buffer to use.
  1106. Return Value:
  1107. None.
  1108. --*/
  1109. LIBC_API
  1110. void
  1111. clearerr (
  1112. FILE *Stream
  1113. );
  1114. /*++
  1115. Routine Description:
  1116. This routine clears the error and end-of-file indicators for the given
  1117. stream.
  1118. Arguments:
  1119. Stream - Supplies a pointer to the file stream.
  1120. Return Value:
  1121. None.
  1122. --*/
  1123. LIBC_API
  1124. void
  1125. clearerr_unlocked (
  1126. FILE *Stream
  1127. );
  1128. /*++
  1129. Routine Description:
  1130. This routine clears the error and end-of-file indicators for the given
  1131. stream. This routine does not acquire the file lock.
  1132. Arguments:
  1133. Stream - Supplies a pointer to the file stream.
  1134. Return Value:
  1135. None.
  1136. --*/
  1137. LIBC_API
  1138. int
  1139. feof (
  1140. FILE *Stream
  1141. );
  1142. /*++
  1143. Routine Description:
  1144. This routine returns whether or not the current stream has attempted to
  1145. read beyond the end of the file.
  1146. Arguments:
  1147. Stream - Supplies a pointer to the file stream.
  1148. Return Value:
  1149. Returns non-zero if the end of file indicator is set for the given stream.
  1150. --*/
  1151. LIBC_API
  1152. int
  1153. feof_unlocked (
  1154. FILE *Stream
  1155. );
  1156. /*++
  1157. Routine Description:
  1158. This routine returns whether or not the current stream has attempted to
  1159. read beyond the end of the file, without acquiring the file lock.
  1160. Arguments:
  1161. Stream - Supplies a pointer to the file stream.
  1162. Return Value:
  1163. Returns non-zero if the end of file indicator is set for the given stream.
  1164. --*/
  1165. LIBC_API
  1166. int
  1167. ferror (
  1168. FILE *Stream
  1169. );
  1170. /*++
  1171. Routine Description:
  1172. This routine returns whether or not the error indicator is set for the
  1173. current stream.
  1174. Arguments:
  1175. Stream - Supplies a pointer to the file stream.
  1176. Return Value:
  1177. Returns non-zero if the error indicator is set for the given stream.
  1178. --*/
  1179. LIBC_API
  1180. int
  1181. ferror_unlocked (
  1182. FILE *Stream
  1183. );
  1184. /*++
  1185. Routine Description:
  1186. This routine returns whether or not the error indicator is set for the
  1187. current stream, without acquiring the file lock.
  1188. Arguments:
  1189. Stream - Supplies a pointer to the file stream.
  1190. Return Value:
  1191. Returns non-zero if the error indicator is set for the given stream.
  1192. --*/
  1193. LIBC_API
  1194. void
  1195. flockfile (
  1196. FILE *Stream
  1197. );
  1198. /*++
  1199. Routine Description:
  1200. This routine explicitly locks a file stream. It can be used on the standard
  1201. I/O streams to group a batch of I/O together.
  1202. Arguments:
  1203. Stream - Supplies a pointer to the file stream.
  1204. Return Value:
  1205. None.
  1206. --*/
  1207. LIBC_API
  1208. int
  1209. ftrylockfile (
  1210. FILE *Stream
  1211. );
  1212. /*++
  1213. Routine Description:
  1214. This routine attempts to acquire the lock for a given stream.
  1215. Arguments:
  1216. Stream - Supplies a pointer to the file stream.
  1217. Return Value:
  1218. 0 if the lock was successfully acquired.
  1219. Non-zero if the file lock could not be acquired.
  1220. --*/
  1221. LIBC_API
  1222. void
  1223. funlockfile (
  1224. FILE *Stream
  1225. );
  1226. /*++
  1227. Routine Description:
  1228. This routine explicitly unlocks a file stream that had been previously
  1229. locked with flockfile or ftrylockfile (on a successful attempt).
  1230. Arguments:
  1231. Stream - Supplies a pointer to the file stream.
  1232. Return Value:
  1233. None.
  1234. --*/
  1235. LIBC_API
  1236. FILE *
  1237. popen (
  1238. const char *Command,
  1239. const char *Mode
  1240. );
  1241. /*++
  1242. Routine Description:
  1243. This routine executes the command specified by the given string. It shall
  1244. create a pipe between the calling program and the executed command, and
  1245. shall return a pointer to a stream that can be used to either read from or
  1246. write to the pipe. Streams returned by this function should be closed with
  1247. the pclose function.
  1248. Arguments:
  1249. Command - Supplies a pointer to a null terminated string containing the
  1250. command to execute.
  1251. Mode - Supplies a pointer to a null terminated string containing the mode
  1252. information of the returned string. If the first character of the
  1253. given string is 'r', then the file stream returned can be read to
  1254. retrieve the standard output of the executed process. Otherwise, the
  1255. file stream returned can be written to to send data to the standard
  1256. input of the executed process.
  1257. Return Value:
  1258. Returns a pointer to a stream wired up to the standard in or standard out
  1259. of the executed process.
  1260. NULL on failure, and errno will be set to contain more information.
  1261. --*/
  1262. LIBC_API
  1263. int
  1264. pclose (
  1265. FILE *Stream
  1266. );
  1267. /*++
  1268. Routine Description:
  1269. This routine closes a stream opened by the popen function, wait for the
  1270. command to terminate, and return the termination status of the process
  1271. that was running the command language interpreter.
  1272. Arguments:
  1273. Stream - Supplies a pointer to the stream opened with popen.
  1274. Return Value:
  1275. Returns the execution status of the opened process.
  1276. 127 if the command language intepreter cannot be executed.
  1277. -1 if an intervening call to wait or waitpid caused the termination status
  1278. to be unavailable. In this case, errno will be set to ECHLD.
  1279. --*/
  1280. LIBC_API
  1281. char *
  1282. tmpnam (
  1283. char *Buffer
  1284. );
  1285. /*++
  1286. Routine Description:
  1287. This routine generates a string that is a valid filename and is not the
  1288. name of an existing file. This routine returns a different name each time
  1289. it is called. Note that between the time the name is returned and when an
  1290. application goes to create the file, the file may already be created.
  1291. Applications may find the tmpfile function more robust and useful.
  1292. Arguments:
  1293. Buffer - Supplies an optional pointer to a buffer where the name will be
  1294. returned. This buffer is assumed to be at least L_tmpnam bytes large.
  1295. If this buffer is not supplied, then a pointer to a global buffer will
  1296. be returned. Subsequent calls to this routine will overwrite the
  1297. contents of that returned buffer.
  1298. Return Value:
  1299. Returns a pointer to a string containing the name of a temporary file. This
  1300. returns the buffer if it is supplied, or a pointer to a global buffer
  1301. otherwise.
  1302. --*/
  1303. LIBC_API
  1304. char *
  1305. tempnam (
  1306. const char *Directory,
  1307. const char *Prefix
  1308. );
  1309. /*++
  1310. Routine Description:
  1311. This routine generates path name that may be used for a temporary file.
  1312. Arguments:
  1313. Directory - Supplies an optional pointer to a string containing the name of
  1314. the directory in which the temporary file is to be created. If the
  1315. directory is not supplied or is not an appropriate directory, then the
  1316. path prefix defined as P_tmpdir in stdio.h shall be used.
  1317. Prefix - Supplies a pointer to a string containing up to a five character
  1318. prefix on the temporary file name.
  1319. Return Value:
  1320. Returns a pointer to a string containing the name of a temporary file. The
  1321. caller must call free when finished with this buffer to reclaim the memory
  1322. allocated by this routine.
  1323. NULL on failure, and errno will be set to contain more information.
  1324. --*/
  1325. LIBC_API
  1326. FILE *
  1327. tmpfile (
  1328. void
  1329. );
  1330. /*++
  1331. Routine Description:
  1332. This routine creates a file and opens a corresponding stream. The file
  1333. shall be automatically deleted when all references to the file are closed.
  1334. The file is opened as in fopen for update ("w+").
  1335. Arguments:
  1336. None.
  1337. Return Value:
  1338. Returns an open file stream on success.
  1339. NULL if a temporary file could not be created.
  1340. --*/
  1341. LIBC_API
  1342. void
  1343. perror (
  1344. const char *String
  1345. );
  1346. /*++
  1347. Routine Description:
  1348. This routine maps the error number accessed through the symbol errno to
  1349. a language-dependent error message, and prints that out to standard error
  1350. with the given parameter.
  1351. Arguments:
  1352. String - Supplies an optional pointer to a string to print before the
  1353. error message. If this is supplied and of non-zero length, the format
  1354. will be "<string>: <errno string>\n". Otherwise, the format will be
  1355. "<errno string>\n".
  1356. Return Value:
  1357. None.
  1358. --*/
  1359. LIBC_API
  1360. int
  1361. printf (
  1362. const char *Format,
  1363. ...
  1364. );
  1365. /*++
  1366. Routine Description:
  1367. This routine prints a formatted string to the standard output file stream.
  1368. Arguments:
  1369. Format - Supplies the printf format string.
  1370. ... - Supplies a variable number of arguments, as required by the printf
  1371. format string argument.
  1372. Return Value:
  1373. Returns the number of bytes successfully converted, not including the null
  1374. terminator.
  1375. Returns a negative number if an error was encountered.
  1376. --*/
  1377. LIBC_API
  1378. int
  1379. fprintf (
  1380. FILE *Stream,
  1381. const char *Format,
  1382. ...
  1383. );
  1384. /*++
  1385. Routine Description:
  1386. This routine prints a formatted string to the given file stream.
  1387. Arguments:
  1388. Stream - Supplies the file stream to print to.
  1389. Format - Supplies the printf format string.
  1390. ... - Supplies a variable number of arguments, as required by the printf
  1391. format string argument.
  1392. Return Value:
  1393. Returns the number of bytes successfully converted, not including the null
  1394. terminator.
  1395. Returns a negative number if an error was encountered.
  1396. --*/
  1397. LIBC_API
  1398. int
  1399. fprintf_unlocked (
  1400. FILE *Stream,
  1401. const char *Format,
  1402. ...
  1403. );
  1404. /*++
  1405. Routine Description:
  1406. This routine prints a formatted string to the given file stream. This
  1407. routine does not acquire the stream lock.
  1408. Arguments:
  1409. Stream - Supplies the file stream to print to.
  1410. Format - Supplies the printf format string.
  1411. ... - Supplies a variable number of arguments, as required by the printf
  1412. format string argument.
  1413. Return Value:
  1414. Returns the number of bytes successfully converted, not including the null
  1415. terminator.
  1416. Returns a negative number if an error was encountered.
  1417. --*/
  1418. LIBC_API
  1419. int
  1420. vfprintf (
  1421. FILE *File,
  1422. const char *Format,
  1423. va_list Arguments
  1424. );
  1425. /*++
  1426. Routine Description:
  1427. This routine prints a formatted string to the given file pointer.
  1428. Arguments:
  1429. File - Supplies a pointer to the file stream to output to.
  1430. Format - Supplies the printf format string.
  1431. Arguments - Supplies the argument list to the format string. The va_end
  1432. macro is not invoked on this list.
  1433. Return Value:
  1434. Returns the number of bytes successfully converted. A null terminator is
  1435. not written.
  1436. Returns a negative number if an error was encountered.
  1437. --*/
  1438. LIBC_API
  1439. int
  1440. vfprintf_unlocked (
  1441. FILE *File,
  1442. const char *Format,
  1443. va_list Arguments
  1444. );
  1445. /*++
  1446. Routine Description:
  1447. This routine prints a formatted string to the given file pointer. This
  1448. routine does not acquire the stream lock.
  1449. Arguments:
  1450. File - Supplies a pointer to the file stream to output to.
  1451. Format - Supplies the printf format string.
  1452. Arguments - Supplies the argument list to the format string. The va_end
  1453. macro is not invoked on this list.
  1454. Return Value:
  1455. Returns the number of bytes successfully converted. A null terminator is
  1456. not written.
  1457. Returns a negative number if an error was encountered.
  1458. --*/
  1459. LIBC_API
  1460. int
  1461. vprintf (
  1462. const char *Format,
  1463. va_list Arguments
  1464. );
  1465. /*++
  1466. Routine Description:
  1467. This routine prints a formatted string to the standard output file stream.
  1468. Arguments:
  1469. Format - Supplies the printf format string.
  1470. Arguments - Supplies the argument list to the format string. The va_end
  1471. macro is not invoked on this list.
  1472. Return Value:
  1473. Returns the number of bytes successfully converted, not including the null
  1474. terminator.
  1475. Returns a negative number if an error was encountered.
  1476. --*/
  1477. LIBC_API
  1478. int
  1479. dprintf (
  1480. int FileDescriptor,
  1481. const char *Format,
  1482. ...
  1483. );
  1484. /*++
  1485. Routine Description:
  1486. This routine prints a formatted string to the given file descriptor.
  1487. Arguments:
  1488. FileDescriptor - Supplies the file descriptor to print to.
  1489. Format - Supplies the printf format string.
  1490. ... - Supplies a variable number of arguments, as required by the printf
  1491. format string argument.
  1492. Return Value:
  1493. Returns the number of bytes successfully converted, not including the null
  1494. terminator.
  1495. Returns a negative number if an error was encountered.
  1496. --*/
  1497. LIBC_API
  1498. int
  1499. vdprintf (
  1500. int FileDescriptor,
  1501. const char *Format,
  1502. va_list Arguments
  1503. );
  1504. /*++
  1505. Routine Description:
  1506. This routine prints a formatted string to the given file descriptor.
  1507. Arguments:
  1508. FileDescriptor - Supplies the file descriptor to print to.
  1509. Format - Supplies the printf format string.
  1510. Arguments - Supplies the argument list to the format string. The va_end
  1511. macro is not invoked on this list.
  1512. Return Value:
  1513. Returns the number of bytes successfully converted. A null terminator is
  1514. not written.
  1515. Returns a negative number if an error was encountered.
  1516. --*/
  1517. LIBC_API
  1518. int
  1519. sprintf (
  1520. char *OutputString,
  1521. const char *Format,
  1522. ...
  1523. );
  1524. /*++
  1525. Routine Description:
  1526. This routine prints a formatted string to the given buffer. This routine
  1527. should be avoided if possible as it can be the cause of buffer overflow
  1528. issues. Use snprintf instead, a function that explicitly bounds the output
  1529. buffer.
  1530. Arguments:
  1531. OutputString - Supplies the buffer where the formatted string will be
  1532. returned. It is the caller's responsibility to ensure this buffer is
  1533. large enough to hold the formatted string.
  1534. Format - Supplies the printf format string.
  1535. ... - Supplies a variable number of arguments, as required by the printf
  1536. format string argument.
  1537. Return Value:
  1538. Returns the number of bytes successfully converted, not including the null
  1539. terminator.
  1540. Returns a negative number if an error was encountered.
  1541. --*/
  1542. LIBC_API
  1543. int
  1544. snprintf (
  1545. char *OutputString,
  1546. size_t OutputStringSize,
  1547. const char *Format,
  1548. ...
  1549. );
  1550. /*++
  1551. Routine Description:
  1552. This routine prints a formatted string to the given bounded buffer.
  1553. Arguments:
  1554. OutputString - Supplies the buffer where the formatted string will be
  1555. returned.
  1556. OutputStringSize - Supplies the number of bytes in the output buffer.
  1557. Format - Supplies the printf format string.
  1558. ... - Supplies a variable number of arguments, as required by the printf
  1559. format string argument.
  1560. Return Value:
  1561. Returns the number of bytes that would have been converted had
  1562. OutputStringSize been large enough, not including the null terminator.
  1563. Returns a negative number if an error was encountered.
  1564. --*/
  1565. LIBC_API
  1566. int
  1567. vsnprintf (
  1568. char *OutputString,
  1569. size_t OutputStringSize,
  1570. const char *Format,
  1571. va_list Arguments
  1572. );
  1573. /*++
  1574. Routine Description:
  1575. This routine implements the core string print format function.
  1576. Arguments:
  1577. OutputString - Supplies a pointer to the buffer where the resulting string
  1578. will be written.
  1579. OutputStringSize - Supplies the size of the output string buffer, in bytes.
  1580. If the format is too long for the output buffer, the resulting string
  1581. will be truncated and the last byte will always be a null terminator.
  1582. Format - Supplies the printf format string.
  1583. Arguments - Supplies the argument list to the format string. The va_end
  1584. macro is not invoked on this list.
  1585. Return Value:
  1586. Returns the number of bytes that would have been converted had
  1587. OutputStringSize been large enough, not including the null terminator.
  1588. Returns a negative number if an error was encountered.
  1589. --*/
  1590. LIBC_API
  1591. int
  1592. vsprintf (
  1593. char *OutputString,
  1594. const char *Format,
  1595. va_list Arguments
  1596. );
  1597. /*++
  1598. Routine Description:
  1599. This routine implements the core string print format function.
  1600. Arguments:
  1601. OutputString - Supplies a pointer to the buffer where the resulting string
  1602. will be written.
  1603. Format - Supplies the printf format string.
  1604. Arguments - Supplies the argument list to the format string. The va_end
  1605. macro is not invoked on this list.
  1606. Return Value:
  1607. Returns the number of bytes successfully converted, not including the null
  1608. terminator.
  1609. Returns a negative number if an error was encountered.
  1610. --*/
  1611. LIBC_API
  1612. int
  1613. asprintf (
  1614. char **OutputString,
  1615. const char *Format,
  1616. ...
  1617. );
  1618. /*++
  1619. Routine Description:
  1620. This routine prints a formatting string to a string similar to vsnprintf,
  1621. except the destination string is allocated by this function using malloc.
  1622. Arguments:
  1623. OutputString - Supplies a pointer where a pointer to a newly allocated
  1624. buffer containing the formatted string result (including the null
  1625. terminator) will be returned. The caller is reponsible for freeing this
  1626. string.
  1627. Format - Supplies the printf format string.
  1628. ... - Supplies the argument list to the format string.
  1629. Return Value:
  1630. Returns the number of bytes successfully converted, not including the null
  1631. terminator.
  1632. Returns a negative number if an error was encountered.
  1633. --*/
  1634. LIBC_API
  1635. int
  1636. vasprintf (
  1637. char **OutputString,
  1638. const char *Format,
  1639. va_list Arguments
  1640. );
  1641. /*++
  1642. Routine Description:
  1643. This routine prints a formatting string to a string similar to vsnprintf,
  1644. except the destination string is allocated by this function using malloc.
  1645. Arguments:
  1646. OutputString - Supplies a pointer where a pointer to a newly allocated
  1647. buffer containing the formatted string result (including the null
  1648. terminator) will be returned. The caller is reponsible for freeing this
  1649. string.
  1650. Format - Supplies the printf format string.
  1651. Arguments - Supplies the argument list to the format string. The va_end
  1652. macro is not invoked on this list.
  1653. Return Value:
  1654. Returns the number of bytes successfully converted, not including the null
  1655. terminator.
  1656. Returns a negative number if an error was encountered.
  1657. --*/
  1658. LIBC_API
  1659. int
  1660. sscanf (
  1661. const char *Input,
  1662. const char *Format,
  1663. ...
  1664. );
  1665. /*++
  1666. Routine Description:
  1667. This routine scans in a string and converts it to a number of arguments
  1668. based on a format string.
  1669. Arguments:
  1670. Input - Supplies a pointer to the input string to scan.
  1671. Format - Supplies the format string that specifies how to convert the input
  1672. to the arguments.
  1673. ... - Supplies the remaining pointer arguments where the scanned data will
  1674. be returned.
  1675. Return Value:
  1676. Returns the number of successfully matched items on success. If the input
  1677. ends before the first matching failure or conversion, EOF is returned. If
  1678. a read error occurs, EOF shall be returned and errno shall be set to
  1679. indicate the error.
  1680. --*/
  1681. LIBC_API
  1682. int
  1683. vsscanf (
  1684. const char *String,
  1685. const char *Format,
  1686. va_list ArgumentList
  1687. );
  1688. /*++
  1689. Routine Description:
  1690. This routine scans in a string and converts it to a number of arguments
  1691. based on a format string.
  1692. Arguments:
  1693. String - Supplies a pointer to the input string to scan.
  1694. Format - Supplies the format string that specifies how to convert the input
  1695. to the arguments.
  1696. ArgumentList - Supplies the remaining arguments, which are all pointers to
  1697. various types to be scanned.
  1698. Return Value:
  1699. Returns the number of successfully matched items on success. If the input
  1700. ends before the first matching failure or conversion, EOF is returned. If
  1701. a read error occurs, EOF shall be returned and errno shall be set to
  1702. indicate the error.
  1703. --*/
  1704. LIBC_API
  1705. int
  1706. fscanf (
  1707. FILE *Stream,
  1708. const char *Format,
  1709. ...
  1710. );
  1711. /*++
  1712. Routine Description:
  1713. This routine scans in a string from a stream and converts it to a number of
  1714. arguments based on a format string.
  1715. Arguments:
  1716. Stream - Supplies a pointer to the input stream.
  1717. Format - Supplies the format string that specifies how to convert the input
  1718. to the arguments.
  1719. ... - Supplies the remaining arguments, which are all pointers to
  1720. various types to be scanned.
  1721. Return Value:
  1722. Returns the number of successfully matched items on success. If the input
  1723. ends before the first matching failure or conversion, EOF is returned. If
  1724. a read error occurs, EOF shall be returned and errno shall be set to
  1725. indicate the error.
  1726. --*/
  1727. LIBC_API
  1728. int
  1729. vfscanf (
  1730. FILE *Stream,
  1731. const char *Format,
  1732. va_list ArgumentList
  1733. );
  1734. /*++
  1735. Routine Description:
  1736. This routine scans in a string from a stream and converts it to a number
  1737. of arguments based on a format string.
  1738. Arguments:
  1739. Stream - Supplies a pointer to the input stream.
  1740. Format - Supplies the format string that specifies how to convert the input
  1741. to the arguments.
  1742. ArgumentList - Supplies the remaining arguments, which are all pointers to
  1743. various types to be scanned.
  1744. Return Value:
  1745. Returns the number of successfully matched items on success. If the input
  1746. ends before the first matching failure or conversion, EOF is returned. If
  1747. a read error occurs, EOF shall be returned and errno shall be set to
  1748. indicate the error.
  1749. --*/
  1750. LIBC_API
  1751. int
  1752. vfscanf_unlocked (
  1753. FILE *Stream,
  1754. const char *Format,
  1755. va_list ArgumentList
  1756. );
  1757. /*++
  1758. Routine Description:
  1759. This routine scans in a string from a stream and converts it to a number
  1760. of arguments based on a format string. This routine does not acquire the
  1761. stream's lock.
  1762. Arguments:
  1763. Stream - Supplies a pointer to the input stream.
  1764. Format - Supplies the format string that specifies how to convert the input
  1765. to the arguments.
  1766. ArgumentList - Supplies the remaining arguments, which are all pointers to
  1767. various types to be scanned.
  1768. Return Value:
  1769. Returns the number of successfully matched items on success. If the input
  1770. ends before the first matching failure or conversion, EOF is returned. If
  1771. a read error occurs, EOF shall be returned and errno shall be set to
  1772. indicate the error.
  1773. --*/
  1774. LIBC_API
  1775. int
  1776. scanf (
  1777. const char *Format,
  1778. ...
  1779. );
  1780. /*++
  1781. Routine Description:
  1782. This routine scans in a string from standard in and converts it to a number
  1783. of arguments based on a format string.
  1784. Arguments:
  1785. Format - Supplies the format string that specifies how to convert the input
  1786. to the arguments.
  1787. ... - Supplies the remaining arguments, which are all pointers to
  1788. various types to be scanned.
  1789. Return Value:
  1790. Returns the number of successfully matched items on success. If the input
  1791. ends before the first matching failure or conversion, EOF is returned. If
  1792. a read error occurs, EOF shall be returned and errno shall be set to
  1793. indicate the error.
  1794. --*/
  1795. LIBC_API
  1796. int
  1797. vscanf (
  1798. const char *Format,
  1799. va_list ArgumentList
  1800. );
  1801. /*++
  1802. Routine Description:
  1803. This routine scans in a string from standard in and converts it to a number
  1804. of arguments based on a format string.
  1805. Arguments:
  1806. Format - Supplies the format string that specifies how to convert the input
  1807. to the arguments.
  1808. ArgumentList - Supplies the remaining arguments, which are all pointers to
  1809. various types to be scanned.
  1810. Return Value:
  1811. Returns the number of successfully matched items on success. If the input
  1812. ends before the first matching failure or conversion, EOF is returned. If
  1813. a read error occurs, EOF shall be returned and errno shall be set to
  1814. indicate the error.
  1815. --*/
  1816. LIBC_API
  1817. ssize_t
  1818. getline (
  1819. char **LinePointer,
  1820. size_t *Size,
  1821. FILE *Stream
  1822. );
  1823. /*++
  1824. Routine Description:
  1825. This routine reads an entire line from the given stream. This routine will
  1826. allocate or reallocate the given buffer so that the buffer is big enough.
  1827. Arguments:
  1828. LinePointer - Supplies a pointer that on input contains an optional pointer
  1829. to a buffer to use to read the line. If the buffer ends up being not
  1830. big enough, it will be reallocated. If no buffer is supplied, one will
  1831. be allocated. On output, contains a pointer to the buffer containing
  1832. the read line on success.
  1833. Size - Supplies a pointer that on input contains the size in bytes of the
  1834. supplied line pointer. On output, this value will be updated to contain
  1835. the size of the buffer returned in the line buffer parameter.
  1836. Stream - Supplies the stream to read the line from.
  1837. Return Value:
  1838. On success, returns the number of characters read, including the delimiter
  1839. character, but not including the null terminator.
  1840. Returns -1 on failure (including an end of file condition), and errno will
  1841. be set to contain more information.
  1842. --*/
  1843. LIBC_API
  1844. ssize_t
  1845. getdelim (
  1846. char **LinePointer,
  1847. size_t *Size,
  1848. int Delimiter,
  1849. FILE *Stream
  1850. );
  1851. /*++
  1852. Routine Description:
  1853. This routine reads an entire line from the given stream, delimited by the
  1854. given delimiter character. This routine will allocate or reallocate the
  1855. given buffer so that the buffer is big enough.
  1856. Arguments:
  1857. LinePointer - Supplies a pointer that on input contains an optional pointer
  1858. to a buffer to use to read the line. If the buffer ends up being not
  1859. big enough, it will be reallocated. If no buffer is supplied, one will
  1860. be allocated. On output, contains a pointer to the buffer containing
  1861. the read line on success.
  1862. Size - Supplies a pointer that on input contains the size in bytes of the
  1863. supplied line pointer. On output, this value will be updated to contain
  1864. the size of the buffer returned in the line buffer parameter.
  1865. Delimiter - Supplies the delimiter to split the line on.
  1866. Stream - Supplies the stream to read the line from.
  1867. Return Value:
  1868. On success, returns the number of characters read, including the delimiter
  1869. character, but not including the null terminator.
  1870. Returns -1 on failure (including an end of file condition), and errno will
  1871. be set to contain more information.
  1872. --*/
  1873. #ifdef __cplusplus
  1874. }
  1875. #endif
  1876. #endif