home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c495 / 5.ddi / WATCM955.ARJ / WATCOMC.HPK / WATCOMC.INF (.txt)
Encoding:
OS/2 Help File  |  1993-02-16  |  407.8 KB  |  18,321 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Overview ΓòÉΓòÉΓòÉ
  3.  
  4. The C library provides much of the power usually associated with the C 
  5. language.  This chapter introduces the individual functions (and macros) that 
  6. comprise the WATCOM C library for DOS, Microsoft Windows, and OS/2. The chapter 
  7. Library Functions and Macros  describes each function and macro in complete 
  8. detail. 
  9.  
  10. Library functions are called as if they had been defined within the program. 
  11. When the program is linked, the code for these routines is incorporated into 
  12. the program by the linker. 
  13.  
  14. Strictly speaking, it is not necessary to declare most library functions since 
  15. they return int values for the most part.  It is preferred, however, to declare 
  16. all functions by including the header files found in the synopsis section with 
  17. each function.  Not only does this declare the return value, but also the type 
  18. expected for each of the arguments as well as the number of arguments. This 
  19. enables the WATCOM C compiler to check the arguments coded with each function 
  20. call. 
  21.  
  22.  
  23. ΓòÉΓòÉΓòÉ 1.1. Classes of Functions ΓòÉΓòÉΓòÉ
  24.  
  25. The functions in the WATCOM C library can be organized into a number of 
  26. classes: 
  27.  
  28. Character Manipulation Functions These functions deal with single characters. 
  29.  
  30. Memory Manipulation Functions These functions manipulate blocks of memory. 
  31.  
  32. String Manipulation Functions These functions manipulate strings of characters. 
  33.           A character string is an array of zero or more adjacent characters 
  34.           followed by a null character ('\0') which marks the end of the 
  35.           string. 
  36.  
  37. Multibyte Character Functions These ANSI C functions provide capabilities for 
  38.           processing multibyte and wide characters. 
  39.  
  40. Conversion Functions These functions convert values from one representation to 
  41.           another. Numeric values, for example, can be converted to strings. 
  42.  
  43. Memory Allocation Functions These functions are concerned with allocating and 
  44.           deallocating memory. 
  45.  
  46. Heap Functions These functions provide the ability to shrink and grow the heap, 
  47.           as well as, find heap related problems. 
  48.  
  49. Math Functions The mathematical functions perform mathematical computations 
  50.           such as the common trigonometric calculations.  These functions 
  51.           operate on double values, also known as floating-point values. 
  52.  
  53. Searching Functions These functions provide searching and sorting capabilities. 
  54.  
  55. Time Functions These functions provide facilities to obtain and manipulate 
  56.           times and dates. 
  57.  
  58. Variable-length Argument Lists These functions provide the capability to 
  59.           process a variable number of arguments to a function. 
  60.  
  61. Stream I/O Functions These functions provide the "standard" functions to read 
  62.           and write files. Data can be transmitted as characters, strings, 
  63.           blocks of memory or under format control. 
  64.  
  65. Process Primitive Functions These functions deal with process creation, 
  66.           execution and termination, signal handling, and timer operations. 
  67.  
  68. Process Environment These functions deal with process identification, user 
  69.           identification, process groups, system identification, system time 
  70.           and process time, environment variables, terminal identification, and 
  71.           configurable system variables. 
  72.  
  73. Directory Functions These functions provide directory services. 
  74.  
  75. Operating System I/O Functions These "non-standard" file operations are more 
  76.           primitive than the "standard" functions in that they are directly 
  77.           interfaced to the operating system.  They are included to provide 
  78.           compatibility with other C implementations and to provide the 
  79.           capability to directly use operating-system file operations. 
  80.  
  81. File Manipulation Functions These functions operate directly on files, 
  82.           providing facilities such as deletion of files. 
  83.  
  84. Console I/O Functions These functions provide the capability to directly read 
  85.           and write characters from the console. 
  86.  
  87. BIOS Functions This set of functions allows access to services provided by the 
  88.           BIOS. 
  89.  
  90. DOS-Specific Functions This set of functions allows access to DOS-specific 
  91.           functions. 
  92.  
  93. Intel 80x86 Architecture-Specific Functions This set of functions allows access 
  94.           to Intel 80x86 processor-related functions. 
  95.  
  96. Miscellaneous Functions This collection consists of the remaining functions. 
  97.  
  98. The following subsections describe these function classes in more detail. Each 
  99. function in the class is noted with a brief description of its purpose. The 
  100. chapter Library Functions and Macros  provides a complete description of each 
  101. function and macro. 
  102.  
  103.  
  104. ΓòÉΓòÉΓòÉ 1.1.1. Character Manipulation Functions ΓòÉΓòÉΓòÉ
  105.  
  106. These functions operate upon single characters of type char. The functions test 
  107. characters in various ways and convert them between upper and lower-case.  The 
  108. following functions are defined: 
  109.  
  110. isalnum       test for letter or digit 
  111. isalpha       test for letter 
  112. isascii       test for ASCII character 
  113. iscntrl       test for control character 
  114. isdigit       test for digit 
  115. isgraph       test for printable character, except space 
  116. islower       test for letter in lower-case 
  117. isprint       test for printable character, including space 
  118. ispunct       test for punctuation characters 
  119. isspace       test for white space characters 
  120. isupper       test for letter in upper-case 
  121. isxdigit      test for hexadecimal digit 
  122. tolower       convert character to lower-case 
  123. toupper       convert character to upper-case 
  124.  
  125.  
  126. ΓòÉΓòÉΓòÉ 1.1.2. Memory Manipulation Functions ΓòÉΓòÉΓòÉ
  127.  
  128. These functions manipulate blocks of memory.  In each case, the address of the 
  129. memory block and its size is passed to the function.  The functions that begin 
  130. with "_f" accept far pointers as their arguments allowing manipulation of any 
  131. memory location regardless of which memory model your program has been compiled 
  132. for.  The following functions are defined: 
  133.  
  134. _fmemccpy     copy far memory block up to a certain character 
  135. _fmemchr      search far memory block for a character value 
  136. _fmemcmp      compare any two memory blocks (near or far) 
  137. _fmemcpy      copy far memory block, overlap not allowed 
  138. _fmemicmp     compare far memory, case insensitive 
  139. _fmemmove     copy far memory block, overlap allowed 
  140. _fmemset      set any memory block (near of far) to a character 
  141. memccpy       copy memory block up to a certain character 
  142. memchr        search memory block for a character value 
  143. memcmp        compare memory blocks 
  144. memcpy        copy memory block, overlap not allowed 
  145. memicmp       compare memory, case insensitive 
  146. memmove       copy memory block, overlap allowed 
  147. memset        set memory block to a character 
  148. movedata      copy memory block, with segment information 
  149. swab          swap bytes of a memory block 
  150.  
  151. See the section "String Manipulation Functions"  for descriptions of functions 
  152. that manipulate strings of data. 
  153.  
  154.  
  155. ΓòÉΓòÉΓòÉ 1.1.3. String Manipulation Functions ΓòÉΓòÉΓòÉ
  156.  
  157. A string  is an array of characters (with type char ) that is terminated with 
  158. an extra null character ('\0'). Functions are passed only the address of the 
  159. string since the size can be determined by searching for the terminating 
  160. character.  The functions that begin with "_f" accept far pointers as their 
  161. arguments allowing manipulation of any memory location regardless of which 
  162. memory model your program has been compiled for.  The following functions are 
  163. defined: 
  164.  
  165. _fstrcat      concatenate two far strings 
  166. _fstrchr      locate character in far string 
  167. _fstrcmp      compare two far strings 
  168. _fstrcpy      copy far string 
  169. _fstrcspn     get number of string characters not from a set of characters 
  170. _fstricmp     compare two far strings with case insensitivity 
  171. _fstrlen      length of a far string 
  172. _fstrlwr      convert far string to lower-case 
  173. _fstrncat     concatenate two far strings, up to a maximum length 
  174. _fstrncmp     compare two far strings up to maximum length 
  175. _fstrncpy     copy a far string, up to a maximum length 
  176. _fstrnicmp    compare two far strings with case insensitivity up to a maximum 
  177.               length 
  178. _fstrnset     fill far string with character to a maximum length 
  179. _fstrpbrk     locate occurrence of a string within a second string 
  180. _fstrrchr     locate last occurrence of character from a character set 
  181. _fstrrev      reverse a far string in place 
  182. _fstrset      fill far string with a character 
  183. _fstrspn      find number of characters at start of string which are also in a 
  184.               second string 
  185. _fstrstr      find first occurrence of string in second string 
  186. _fstrtok      get next token from a far string 
  187. _fstrupr      convert far string to upper-case 
  188. sprintf       formatted transmission to string 
  189. sscanf        scan from string under format control 
  190. strcat        concatenate string 
  191. strchr        locate character in string 
  192. strcmp        compare two strings 
  193. strcmpi       compare two strings with case insensitivity 
  194. strcoll       compare two strings using locale collating sequence 
  195. strcpy        copy a string 
  196. strcspn       get number of string characters not from a set of characters 
  197. strdup        allocate and duplicate a string 
  198. strerror      get error message as string 
  199. stricmp       compare two strings with case insensitivity 
  200. strlen        string length 
  201. strlwr        convert string to lower-case 
  202. strncat       concatenate two strings, up to a maximum length 
  203. strncmp       compare two strings up to maximum length 
  204. strncpy       copy a string, up to a maximum length 
  205. strnicmp      compare two strings with case insensitivity up to a maximum 
  206.               length 
  207. strnset       fill string with character to a maximum length 
  208. strpbrk       locate occurrence of a string within a second string 
  209. strrchr       locate last occurrence of character from a character set 
  210. strrev        reverse a string in place 
  211. strset        fill string with a character 
  212. strspn        find number of characters at start of string which are also in a 
  213.               second string 
  214. strstr        find first occurrence of string in second string 
  215. strtok        get next token from string 
  216. strupr        convert string to upper-case 
  217. strxfrm       transform string to locale's collating sequence 
  218. vsprintf      same as sprintf but with variable arguments 
  219. vsscanf       same as sscanf but with variable arguments 
  220.  
  221. For related functions see the sections Conversion Functions (conversions to and 
  222. from strings), Time Functions  (formatting of dates and times), and Memory 
  223. Manipulation Functions  (operate on arrays without terminating null character). 
  224.  
  225.  
  226. ΓòÉΓòÉΓòÉ 1.1.4. Multibyte Character Functions ΓòÉΓòÉΓòÉ
  227.  
  228. These ANSI C functions provide capabilities for processing multibyte 
  229. characters.  The following functions are defined: 
  230.  
  231. mblen         determine length of next multibyte character 
  232. mbstowcs      convert multibyte character string to wide character string 
  233. mbtowc        convert multibyte character to wide character 
  234. wcstombs      convert wide character string to multibyte character string 
  235. wctomb        convert wide character to multibyte character 
  236.  
  237.  
  238. ΓòÉΓòÉΓòÉ 1.1.5. Conversion Functions ΓòÉΓòÉΓòÉ
  239.  
  240. These functions perform conversions between objects of various types and 
  241. strings.  The following functions are defined: 
  242.  
  243. atof          string to double 
  244. atoi          string to int 
  245. atol          string to long int 
  246. ecvt          double to E-format string 
  247. fcvt          double to F-format string 
  248. gcvt          double to string 
  249. itoa          int to string 
  250. ltoa          long int to string 
  251. strtod        string to double 
  252. strtol        string to long int 
  253. strtoul       string to unsigned long int 
  254. ultoa         unsigned long int to string 
  255. utoa          unsigned int to string 
  256.  
  257. See also tolower, toupper, strlwr, and strupr which convert the cases of 
  258. characters and strings. 
  259.  
  260.  
  261. ΓòÉΓòÉΓòÉ 1.1.6. Memory Allocation Functions ΓòÉΓòÉΓòÉ
  262.  
  263. These functions allocate and de-allocate blocks of memory. 
  264.  
  265. Unless you are running your program in 32-bit protect mode, where segments have 
  266. a limit of 4 gigabytes, the default data segment has a maximum size of 64K 
  267. bytes.  It may be less in a machine with insufficient memory or when other 
  268. programs in the computer already occupy some of the memory.  The _nmalloc 
  269. function allocates space within this area while the _fmalloc function allocates 
  270. space outside the area (if it is available). 
  271.  
  272. In a small data model, the malloc, calloc and realloc functions use the 
  273. _nmalloc function to acquire memory; in a large data model, the _fmalloc 
  274. function is used. 
  275.  
  276. It is also possible to allocate memory from a based heap using _bmalloc. Based 
  277. heaps are similar to far heaps in that they are located outside the normal data 
  278. segment.  Based pointers only store the offset portion of the full address, so 
  279. they behave much like near pointers. The selector portion of the full address 
  280. specifies which based heap a based pointer belongs to, and must be passed to 
  281. the various based heap functions. 
  282.  
  283. It is important to use the appropriate memory-deallocation function to free 
  284. memory blocks.  The _nfree function should be used to free space acquired by 
  285. the _ncalloc, _nmalloc, or _nrealloc functions; the _ffree function should be 
  286. used to free space acquired by the _fcalloc, _fmalloc, or _frealloc functions. 
  287. The _bfree function should be used to free space acquired by the _bcalloc, 
  288. _bmalloc, or _brealloc functions.  The free function will use the _nfree 
  289. function when the small data memory model is used; it will use the _ffree 
  290. function when the large data memory model is being used. 
  291.  
  292. It should be noted that the _fmalloc and _nmalloc functions can both be used in 
  293. either data memory model.  The following functions are defined: 
  294.  
  295. alloca        allocate auto storage from stack 
  296. _bcalloc      allocate and zero memory from a based heap 
  297. _bexpand      expand a block of memory in a based heap 
  298. _bfree        free a block of memory in a based heap 
  299. _bfreeseg     free a based heap 
  300. _bheapseg     allocate a based heap 
  301. _bmalloc      allocate a memory block from a based heap 
  302. _bmsize       return the size of a memory block 
  303. _brealloc     re-allocate a memory block in a based heap 
  304. calloc        allocate and zero memory 
  305. _expand       expand a block of memory 
  306. _fcalloc      allocate and zero a memory block (outside default data segment) 
  307. _fexpand      expand a block of memory (outside default data segment) 
  308. _ffree        free a block allocated using _fmalloc 
  309. _fmalloc      allocate a memory block (outside default data segment) 
  310. _fmsize       return the size of a memory block 
  311. _frealloc     re-allocate a memory block (outside default data segment) 
  312. free          free a block allocated using malloc", "calloc or realloc 
  313. _freect       return number of objects that can be allocated 
  314. halloc        allocate huge array 
  315. hfree         free huge array 
  316. malloc        allocate a memory block (using current memory model) 
  317. _memavl       return amount of available memory 
  318. _memmax       return largest block of memory available 
  319. _msize        return the size of a memory block 
  320. _ncalloc      allocate and zero a memory block (inside default data segment) 
  321. _nexpand      expand a block of memory (inside default data segment) 
  322. _nfree        free a block allocated using _nmalloc 
  323. _nmalloc      allocate a memory block (inside default data segment) 
  324. _nmsize       return the size of a memory block 
  325. _nrealloc     re-allocate a memory block (inside default data segment) 
  326. realloc       re-allocate a block of memory 
  327. sbrk          set allocation break position 
  328. stackavail    determine available amount of stack space 
  329.  
  330.  
  331. ΓòÉΓòÉΓòÉ 1.1.7. Heap Functions ΓòÉΓòÉΓòÉ
  332.  
  333. These functions provide the ability to shrink and grow the heap, as well as, 
  334. find heap related problems.  The following functions are defined: 
  335.  
  336. _heapchk          perform consistency check on the heap 
  337. _bheapchk         perform consistency check on a based heap 
  338. _fheapchk         perform consistency check on the far heap 
  339. _nheapchk         perform consistency check on the near heap 
  340. _heapgrow         grow the heap 
  341. _fheapgrow        grow the far heap 
  342. _nheapgrow        grow the near heap up to its limit of 64K 
  343. _heapmin          shrink the heap as small as possible 
  344. _bheapmin         shrink a based heap as small as possible 
  345. _fheapmin         shrink the far heap as small as possible 
  346. _nheapmin         shrink the near heap as small as possible 
  347. _heapset          fill unallocated sections of heap with pattern 
  348. _bheapset         fill unallocated sections of based heap with pattern 
  349. _fheapset         fill unallocated sections of far heap with pattern 
  350. _nheapset         fill unallocated sections of near heap with pattern 
  351. _heapshrink       shrink the heap as small as possible 
  352. _fheapshrink      shrink the far heap as small as possible 
  353. _bheapshrink      shrink a based heap as small as possible 
  354. _nheapshrink      shrink the near heap as small as possible 
  355. _heapwalk         walk through each entry in the heap 
  356. _bheapwalk        walk through each entry in a based heap 
  357. _fheapwalk        walk through each entry in the far heap 
  358. _nheapwalk        walk through each entry in the near heap 
  359.  
  360.  
  361. ΓòÉΓòÉΓòÉ 1.1.8. Math Functions ΓòÉΓòÉΓòÉ
  362.  
  363. These functions operate with objects of type double, also known as 
  364. floating-point numbers.  The Intel 8087 processor (and its successor chips) is 
  365. commonly used to implement floating-point operations on personal computers. 
  366. Functions ending in "87" pertain to this specific hardware and should be 
  367. isolated in programs when portability is a consideration.  The following 
  368. functions are defined: 
  369.  
  370. abs           absolute value of an object of type int 
  371. acos          arccosine 
  372. acosh         inverse hyperbolic cosine 
  373. asin          arcsine 
  374. asinh         inverse hyperbolic sine 
  375. atan          arctangent of one argument 
  376. atan2         arctangent of two arguments 
  377. atanh         inverse hyperbolic tangent 
  378. bessel        bessel functions j0, j1, jn, y0, y1, and yn 
  379. cabs          absolute value of complex number 
  380. ceil          ceiling function 
  381. _clear87      clears floating-point status 
  382. _control87    sets new floating-point control word 
  383. cos           cosine 
  384. cosh          hyperbolic cosine 
  385. div           compute quotient, remainder from division of an int object 
  386. exp           exponential function 
  387. fabs          absolute value of double 
  388. floor         floor function 
  389. fmod          modulus function 
  390. _fpreset      initializes for floating-point operations 
  391. frexp         fractional exponent 
  392. hypot         compute hypotenuse 
  393. j0            return Bessel functions of the first kind (described under 
  394.               "bessel Functions") 
  395. j1            return Bessel functions of the first kind (described under 
  396.               "bessel Functions") 
  397. jn            return Bessel functions of the first kind (described under 
  398.               "bessel Functions") 
  399. labs          absolute value of an object of type long int 
  400. ldexp         multiply by a power of two 
  401. ldiv          get quotient, remainder from division of object of type long int 
  402. log           natural logarithm 
  403. log10         logarithm, base 10 
  404. log2          logarithm, base 2 
  405. matherr       handles error from math functions 
  406. max           return maximum of two arguments 
  407. min           return minimum of two arguments 
  408. modf          get integral, fractional parts of double 
  409. pow           raise to power 
  410. rand          random integer 
  411. sin           sine 
  412. sinh          hyperbolic sine 
  413. sqrt          square root 
  414. srand         set starting point for generation of random numbers using rand 
  415.               function 
  416. _status87     gets floating-point status 
  417. tan           tangent 
  418. tanh          hyperbolic tangent 
  419. y0            return Bessel functions of the second kind (described under 
  420.               "bessel") 
  421. y1            return Bessel functions of the second kind (described under 
  422.               "bessel") 
  423. yn            return Bessel functions of the second kind (described under 
  424.               "bessel") 
  425.  
  426.  
  427. ΓòÉΓòÉΓòÉ 1.1.9. Searching Functions ΓòÉΓòÉΓòÉ
  428.  
  429. These functions provide searching and sorting capabilities.  The following 
  430. functions are defined: 
  431.  
  432. bsearch       find a data item in an array using binary search 
  433. lfind         find a data item in an array using linear search 
  434. lsearch       linear search array, add item if not found 
  435. qsort         sort an array 
  436.  
  437.  
  438. ΓòÉΓòÉΓòÉ 1.1.10. Time Functions ΓòÉΓòÉΓòÉ
  439.  
  440. These functions are concerned with dates and times.  The following functions 
  441. are defined: 
  442.  
  443. _asctime      makes time string from time structure 
  444. asctime       makes time string from time structure 
  445. clock         gets time since program start 
  446. _ctime        gets calendar time string 
  447. ctime         gets calendar time string 
  448. difftime      calculate difference between two times 
  449. ftime         returns the current time in a timeb structure 
  450. _gmtime       convert calendar time to Coordinated Universal Time (UTC) 
  451. gmtime        convert calendar time to Coordinated Universal Time (UTC) 
  452. _localtime    convert calendar time to local time 
  453. localtime     convert calendar time to local time 
  454. mktime        make calendar time from local time 
  455. strftime      format date and time 
  456. tzset         set global variables to reflect the local time zone 
  457.  
  458.  
  459. ΓòÉΓòÉΓòÉ 1.1.11. Variable-length Argument Lists ΓòÉΓòÉΓòÉ
  460.  
  461. Variable-length argument lists are used when a function does not have a fixed 
  462. number of arguments.  These macros provide the capability to access these 
  463. arguments.  The following functions are defined: 
  464.  
  465. va_arg        get next variable argument 
  466. va_end        complete access of variable arguments 
  467. va_start      start access of variable arguments 
  468.  
  469.  
  470. ΓòÉΓòÉΓòÉ 1.1.12. Stream I/O Functions ΓòÉΓòÉΓòÉ
  471.  
  472. A stream  is the name given to a file or device which has been opened for data 
  473. transmission.  When a stream is opened, a pointer to a FILE structure is 
  474. returned.  This pointer is used to reference the stream when other functions 
  475. are subsequently invoked. 
  476.  
  477. There are two modes by which data can be transmitted: 
  478.  
  479. binary    Data is transmitted unchanged. 
  480.  
  481. text      On input, carriage-return characters are removed before following 
  482.           linefeed characters.  On output, carriage-return characters are 
  483.           inserted before linefeed characters. 
  484.  
  485. These modes are required since text files are stored with the two characters 
  486. delimiting a line of text, while the C convention is for only the linefeed 
  487. character to delimit a text line. 
  488.  
  489. When a program begins execution, there are a number of streams already open for 
  490. use: 
  491.  
  492. stdin     Standard Input:  input from the console 
  493. stdout    Standard Output:  output to the console 
  494. stderr    Standard Error:  output to the console (used for error messages) 
  495. stdaux    Standard Auxiliary:  auxiliary port, available for use by a program 
  496. stdprn    Standard Printer:  available for use by a program 
  497.  
  498. These standard streams may be re-directed by use of the freopen function. 
  499.  
  500. See also the section File Manipulation Functions  for other functions which 
  501. operate upon files. 
  502.  
  503. The functions referenced in the section Operating System I/O Functions  may 
  504. also be invoked (use the fileno function to obtain the file handle).  Since the 
  505. stream functions may buffer input and output, these functions should be used 
  506. with caution to avoid unexpected results. 
  507.  
  508. The following functions are defined: 
  509.  
  510. clearerr      clear end-of-file and error indicators for stream 
  511. fclose        close stream 
  512. fcloseall     close all open streams 
  513. fdopen        open stream, given handle 
  514. feof          test for end of file 
  515. ferror        test for file error 
  516. fflush        flush output buffer 
  517. fgetc         get next character from file 
  518. fgetchar      equivalent to fgetc with the argument stdin 
  519. fgetpos       get current file position 
  520. fgets         get a string 
  521. flushall      flush output buffers for all streams 
  522. fopen         open a stream 
  523. fprintf       format output 
  524. fputc         write a character 
  525. fputchar      write a character to the stdout stream 
  526. fputs         write a string 
  527. fread         read a number of objects 
  528. freopen       re-opens a stream 
  529. fscanf        scan input according to format 
  530. fseek         set current file position, relative 
  531. fsetpos       set current file position, absolute 
  532. ftell         get current file position 
  533. fwrite        write a number of objects 
  534. getc          read character 
  535. getchar       get next character from stdin 
  536. gets          get string from stdin 
  537. perror        write error message to stderr stream 
  538. printf        format output to stdout 
  539. putc          write character to file 
  540. putchar       write character to stdout 
  541. puts          write string to stdout 
  542. rewind        position to start of file 
  543. scanf         scan input from stdin under format control 
  544. setbuf        set buffer 
  545. setvbuf       set buffering 
  546. tmpfile       create temporary file 
  547. ungetc        push character back on input stream 
  548. vfprintf      same as fprintf but with variable arguments 
  549. vfscanf       same as fscanf but with variable arguments 
  550. vprintf       same as printf but with variable arguments 
  551. vscanf        same as scanf but with variable arguments 
  552.  
  553. See the section Directory Functions  for functions which are related to 
  554. directories. 
  555.  
  556.  
  557. ΓòÉΓòÉΓòÉ 1.1.13. Process Primitive Functions ΓòÉΓòÉΓòÉ
  558.  
  559. These functions deal with process creation, execution and termination, signal 
  560. handling, and timer operations. 
  561.  
  562. When a new process is started, it may replace the existing process 
  563.  
  564. o P_OVERLAY is specified with the spawn... functions 
  565.  
  566. o the exec... routines are invoked 
  567.  
  568. or the existing process may be suspended while the new process executes 
  569. (control continues at the point following the place where the new process was 
  570. started) 
  571.  
  572. o P_WAIT is specified with the spawn... functions 
  573.  
  574. o system is used 
  575.  
  576. The following functions are defined: 
  577.  
  578. abort           immediate termination of process, return code 3 
  579. atexit          register exit routine 
  580. _beginthread    start a new thread of execution 
  581. cwait           wait for a child process to terminate 
  582. delay           delay for number of milliseconds 
  583. _endthread      end the current thread 
  584. execl           chain to program 
  585. execle          chain to program, pass environment 
  586. execlp          chain to program 
  587. execlpe         chain to program, pass environment 
  588. execv           chain to program 
  589. execve          chain to program, pass environment 
  590. execvp          chain to program 
  591. execvpe         chain to program, pass environment 
  592. exit            exit process, set return code 
  593. _exit           exit process, set return code 
  594. onexit          register exit routine 
  595. raise           signal an exceptional condition 
  596. signal          set handling for exceptional condition 
  597. sleep           delay for number of seconds 
  598. spawnl          create process 
  599. spawnle         create process, set environment 
  600. spawnlp         create process 
  601. spawnlpe        create process, set environment 
  602. spawnv          create process 
  603. spawnve         create process, set environment 
  604. spawnvp         create process 
  605. spawnvpe        create process, set environment 
  606. system          execute system command 
  607. wait            wait for any child process to terminate 
  608.  
  609. There are eight spawn... and exec... functions each. The "..." is one to three 
  610. letters: 
  611.  
  612. o "l" or "v" (one is required) to indicate the way the process parameters are 
  613.   passed 
  614.  
  615. o "p" (optional) to indicate whether the PATH environment variable is searched 
  616.   to locate the program for the process 
  617.  
  618. o "e" (optional) to indicate that the environment variables are being passed 
  619.  
  620.  
  621. ΓòÉΓòÉΓòÉ 1.1.14. Process Environment ΓòÉΓòÉΓòÉ
  622.  
  623. These functions deal with process identification, process groups, system 
  624. identification, system time, environment variables, and terminal 
  625. identification.  The following functions are defined: 
  626.  
  627. clearenv      delete environment variables 
  628. getcmd        get command line 
  629. getpid        return process ID of calling process 
  630. getenv        get environment variable value 
  631. isatty        determine if file descriptor associated with a terminal 
  632. putenv        add, change or delete environment variable 
  633. _searchenv    search for a file in list of directories 
  634. setenv        add, change or delete environment variable 
  635. time          get current calendar time 
  636.  
  637.  
  638. ΓòÉΓòÉΓòÉ 1.1.15. Directory Functions ΓòÉΓòÉΓòÉ
  639.  
  640. These functions pertain to directory manipulation.  The following functions are 
  641. defined: 
  642.  
  643. chdir         change current working directory 
  644. closedir      close opened directory file 
  645. getcwd        get current working directory 
  646. mkdir         make a new directory 
  647. opendir       open directory file 
  648. readdir       read file name from directory 
  649. rmdir         remove a directory 
  650.  
  651.  
  652. ΓòÉΓòÉΓòÉ 1.1.16. Operating System I/O Functions ΓòÉΓòÉΓòÉ
  653.  
  654. These functions operate at the operating-system level and are included for 
  655. compatibility with other C implementations.  It is recommended that the 
  656. functions used in the section File Manipulation Functions be used for new 
  657. programs, as these functions are defined portably and are part of the ANSI 
  658. standard for the C language. 
  659.  
  660. The functions in this section reference opened files and devices using a file 
  661. handle which is returned when the file is opened.  The file handle is passed to 
  662. the other functions. 
  663.  
  664. The following functions are defined: 
  665.  
  666. chsize        change the size of a file 
  667. close         close file 
  668. creat         create a file 
  669. dup           duplicate file handle, get unused handle number 
  670. dup2          duplicate file handle, supply new handle number 
  671. eof           test for end of file 
  672. filelength    get file size 
  673. fileno        get file handle for stream file 
  674. fstat         get file status 
  675. lock          lock a section of a file 
  676. locking       lock/unlock a section of a file 
  677. lseek         set current file position 
  678. open          open a file 
  679. read          read a record 
  680. setmode       set file mode 
  681. sopen         open a file for shared access 
  682. tell          get current file position 
  683. umask         set file permission mask 
  684. unlink        delete a file 
  685. unlock        unlock a section of a file 
  686. write         write a record 
  687.  
  688.  
  689. ΓòÉΓòÉΓòÉ 1.1.17. File Manipulation Functions ΓòÉΓòÉΓòÉ
  690.  
  691. These functions operate directly with files.  The following functions are 
  692. defined: 
  693.  
  694. access        test file or directory for mode of access 
  695. chmod         change permissions for a file 
  696. remove        delete a file 
  697. rename        rename a file 
  698. stat          get file status 
  699. tmpnam        create name for temporary file 
  700. utime         set modification time for a file 
  701.  
  702.  
  703. ΓòÉΓòÉΓòÉ 1.1.18. Console I/O Functions ΓòÉΓòÉΓòÉ
  704.  
  705. These functions provide the capability to read and write data from the console. 
  706. Data is read or written without any special initialization (devices are not 
  707. opened or closed), since the functions operate at the hardware level. 
  708.  
  709. The following functions are defined: 
  710.  
  711. cgets         get a string from the console 
  712. cprintf       print formatted string to the console 
  713. cputs         write a string to the console 
  714. cscanf        scan formatted data from the console 
  715. getch         get character from console, no echo 
  716. getche        get character from console, echo it 
  717. kbhit         test if keystroke available 
  718. putch         write a character to the console 
  719. ungetch       push back next character from console 
  720.  
  721.  
  722. ΓòÉΓòÉΓòÉ 1.1.19. BIOS Functions ΓòÉΓòÉΓòÉ
  723.  
  724. This set of functions allows access to services provided by the BIOS.  The 
  725. following functions are defined: 
  726.  
  727. _bios_disk          provide disk access functions 
  728. _bios_equiplist     determine equipment list 
  729. _bios_keybrd        provide low-level keyboard access 
  730. _bios_memsize       determine amount of system board memory 
  731. _bios_printer       provide access to printer services 
  732. _bios_serialcom     provide access to serial services 
  733. _bios_timeofday     get and set system clock 
  734.  
  735.  
  736. ΓòÉΓòÉΓòÉ 1.1.20. DOS-Specific Functions ΓòÉΓòÉΓòÉ
  737.  
  738. These functions provide the capability to invoke DOS functions directly from a 
  739. program.  The following functions are defined: 
  740.  
  741. bdos                DOS call (short form) 
  742. dosexterr           extract DOS error information 
  743. _dos_allocmem       allocate a block of memory 
  744. _dos_close          close a file 
  745. _dos_creat          create a file 
  746. _dos_creatnew       create a new file 
  747. _dos_findclose      close find file matching 
  748. _dos_findfirst      find first file matching a specified pattern 
  749. _dos_findnext       find the next file matching a specified pattern 
  750. _dos_freemem        free a block of memory 
  751. _dos_getdate        get current system date 
  752. _dos_getdiskfree    get information about disk 
  753. _dos_getdrive       get the current drive 
  754. _dos_getfileattr    get file attributes 
  755. _dos_getftime       get file's last modification time 
  756. _dos_gettime        get the current system time 
  757. _dos_getvect        get contents of interrupt vector 
  758. _dos_keep           install a terminate-and-stay-resident program 
  759. _dos_open           open a file 
  760. _dos_read           read data from a file 
  761. _dos_setblock       change the size of allocated block 
  762. _dos_setdate        change current system date 
  763. _dos_setdrive       change the current default drive 
  764. _dos_setfileattr    set the attributes of a file 
  765. _dos_setftime       set a file's last modification time 
  766. _dos_settime        set the current system time 
  767. _dos_setvect        set an interrupt vector 
  768. _dos_write          write data to a file 
  769. intdos              cause DOS interrupt 
  770. intdosx             cause DOS interrupt, with segment registers 
  771.  
  772.  
  773. ΓòÉΓòÉΓòÉ 1.1.21. Intel 80x86 Architecture-Specific Functions ΓòÉΓòÉΓòÉ
  774.  
  775. These functions provide the capability to invoke Intel 80x86 processor-related 
  776. functions directly from a program.  Functions that apply to the Intel 8086 CPU 
  777. apply to that family including the 80286, 80386 and 80486 processors.  The 
  778. following functions are defined: 
  779.  
  780. _chain_intr   chain to the previous interrupt handler 
  781. _disable      disable interrupts 
  782. _enable       enable interrupts 
  783. FP_OFF        get offset part of far pointer 
  784. FP_SEG        get segment part of far pointer 
  785. inp           get one byte from hardware port 
  786. inpw          get two bytes (one word) from hardware port 
  787. int386        cause 386/486 CPU interrupt 
  788. int386x       cause 386/486 CPU interrupt, with segment registers 
  789. int86         cause 8086 CPU interrupt 
  790. int86x        cause 8086 CPU interrupt, with segment registers 
  791. intr          cause 8086 CPU interrupt, with segment registers 
  792. MK_FP         make a far pointer from the segment and offset values 
  793. nosound       turn off the speaker 
  794. outp          write one byte to hardware port 
  795. outpw         write two bytes (one word) to hardware port 
  796. segread       read segment registers 
  797. sound         turn on the speaker at specified frequency 
  798.  
  799.  
  800. ΓòÉΓòÉΓòÉ 1.1.22. Miscellaneous Functions ΓòÉΓòÉΓòÉ
  801.  
  802. The following functions are defined: 
  803.  
  804. assert          test an assertion 
  805. _fullpath       return full path specification for file 
  806. _harderr        critical error handler 
  807. _hardresume     critical error handler resume 
  808. localeconv      obtain locale specific conversion information 
  809. longjmp         return and restore environment saved by setjmp 
  810. _lrotl          rotate an unsigned long left 
  811. _lrotr          rotate an unsigned long right 
  812. main            the main program (user written) 
  813. offsetof        get offset of field in structure 
  814. _rotl           rotate an unsigned int left 
  815. _rotr           rotate an unsigned int right 
  816. setjmp          save environment for use with longjmp function 
  817. _makepath       make a full filename from specified components 
  818. setlocale       set locale category 
  819. _splitpath      split a filename into its components 
  820.  
  821.  
  822. ΓòÉΓòÉΓòÉ 1.2. Header Files ΓòÉΓòÉΓòÉ
  823.  
  824. The following header files are supplied with the C library.  As has been 
  825. previously noted, when a library function is referenced in a source file, the 
  826. related header files (shown in the synopsis for that function) should be 
  827. included into that source file.  The header files provide the proper 
  828. declarations for the functions and for the number and types of arguments used 
  829. with them.  Constant values used in conjunction with the functions are also 
  830. declared.  The files can be included in any order. 
  831.  
  832. The following header files are provided with the software.  The header files 
  833. that are located in the \H directory are described first. 
  834.  
  835. assert.h  This ANSI header file is required when an assert macro is used. These 
  836.           assertions will be ignored when the identifier NDEBUG is defined. 
  837.  
  838. bios.h    This header file contains structure definitions and function 
  839.           prototypes for all of the BIOS related functions. 
  840.  
  841. conio.h   This header file provides the declarations for console and Intel 
  842.           80x86 port input/output functions. 
  843.  
  844. ctype.h   This ANSI header file provides the declarations for functions which 
  845.           manipulate characters. 
  846.  
  847. direct.h  This header file provides the declarations for functions related to 
  848.           directories and for the type DIR which describes an entry in a 
  849.           directory. 
  850.  
  851. dos.h     This header file is used with functions that interact with DOS.  It 
  852.           includes the definitions for these functions, symbolic names for the 
  853.           numbers of DOS calls, definitions for the FP_OFF, FP_SEG and MK_FP 
  854.           macros, and for the following structures and unions: 
  855.  
  856.    DOSERROR      describes the DOS error information. 
  857.    REGS          describes the CPU registers for Intel 8086 family. 
  858.    SREGS         describes the segment registers for the Intel 8086 family. 
  859.    REGPACK       describes the CPU registers and segment registers for Intel 
  860.                  8086 family. 
  861.    INTPACK       describes the input parameter to an "interrupt" function. 
  862.  
  863. env.h     This POSIX header file contains prototypes for environment string 
  864.           functions. 
  865.  
  866. errno.h   This ANSI header file provides the extern declaration for error 
  867.           variable errno and provides the symbolic names for error codes that 
  868.           can be placed in the error variable. 
  869.  
  870. fcntl.h   This POSIX header file provides the flags used by the open and sopen 
  871.           functions.  The function declarations for these are found in the 
  872.           <io.h> header file. 
  873.  
  874. float.h   This ANSI header file contains declarations for constants related to 
  875.           floating-point numbers, declarations for low-level floating-point 
  876.           functions, and the declaration of the floating-point exception codes. 
  877.  
  878. io.h      This header file contains the declarations for functions that perform 
  879.           input/output operations at the operating system level.  These 
  880.           functions use file handles to reference files or devices.  The 
  881.           function fstat is declared in the <sys\stat.h> header file. 
  882.  
  883. limits.h  This ANSI header file contains constant declarations for limits or 
  884.           boundary values for ranges of integers and characters. 
  885.  
  886. locale.h  This ANSI header file contains declarations for the categories 
  887.           (LC...) of locales which can be selected using the setlocale function 
  888.           which is also declared. 
  889.  
  890. malloc.h  This header file provides declarations for the memory allocation and 
  891.           deallocation functions. 
  892.  
  893. math.h    This ANSI header file contains declarations for the mathematical 
  894.           functions (which operate with floating-point numbers) and for the 
  895.           structures: 
  896.  
  897.    exception     describes the exception structure passed to the matherr 
  898.                  function; symbolic constants for the types of exceptions are 
  899.                  included 
  900.  
  901.    complex       declares a complex number 
  902.  
  903. process.h This header file contains function declarations for the spawn... 
  904.           functions, the exec... functions, and the system function.  The file 
  905.           also contains declarations for the constants P_WAIT, P_NOWAIT, 
  906.           P_NOWAITO, and P_OVERLAY. 
  907.  
  908. search.h  This header file contains function prototypes for the lfind and 
  909.           lsearch functions. 
  910.  
  911. setjmp.h  This ANSI header file provides declarations to be used with the 
  912.           setjmp and longjmp functions. 
  913.  
  914. share.h   This header file defines constants for shared access to files using 
  915.           the sopen function. 
  916.  
  917. signal.h  This ANSI header file contains the declarations related to the signal 
  918.           and raise functions. 
  919.  
  920. stdarg.h  This ANSI header file contains the declarations for the macros which 
  921.           handle variable argument lists. 
  922.  
  923. stddef.h  This ANSI header file contains declarations for a few popular 
  924.           constants including NULL (null pointer), size_t (unsigned size of an 
  925.           object), and ptrdiff_t (difference between two pointers).  It also 
  926.           contains a declaration for the offsetof macro. 
  927.  
  928. stdio.h   This ANSI header file relates to " standard" input/output functions. 
  929.           Files, devices and directories are referenced using pointers to 
  930.           objects of the type FILE. The header file contains declarations for 
  931.           these functions and macros, defines the FILE type and contains 
  932.           various constants related to files. 
  933.  
  934. stdlib.h  This ANSI header file contains declarations for many standard 
  935.           functions excluding those declared in other header files discussed in 
  936.           this section. 
  937.  
  938. string.h  This ANSI header file contains declarations for functions which 
  939.           manipulate strings or blocks of memory. 
  940.  
  941. time.h    This ANSI header file declares the functions related to times and 
  942.           dates and defines the structured type struct tm. 
  943.  
  944. varargs.h This UNIX System V header file provides an alternate way of handling 
  945.           variable argument lists.  The equivalent ANSI header file is 
  946.           <stdarg.h>. 
  947.  
  948. The following header files are present in the sys subdirectory. Their presence 
  949. in this directory indicates that they are system-dependent header files. 
  950.  
  951. sys\locking.h   This header file contains the manifest constants used by the 
  952.                 locking function. 
  953.  
  954. sys\stat.h      This POSIX header file contains the declarations pertaining to 
  955.                 file status, including definitions for the fstat and stat 
  956.                 functions and for the structure: 
  957.  
  958.    stat      describes the information obtained for a directory, file or device 
  959.  
  960. sys\timeb.h     This header file describes the timeb structure used in 
  961.                 conjunction with the ftime function. 
  962.  
  963. sys\types.h     This POSIX header file contains declarations for the types used 
  964.                 by system-level calls to obtain file status or time 
  965.                 information. 
  966.  
  967. sys\utime.h     This POSIX header file contains a declaration for the utime 
  968.                 function and for the structured type utimbuf used by it. 
  969.  
  970.  
  971. ΓòÉΓòÉΓòÉ 1.3. Global Data ΓòÉΓòÉΓòÉ
  972.  
  973. Certain data items are used by the WATCOM C run-time library and may be 
  974. inspected (or changed in some cases) by a program.  The defined items are: 
  975.  
  976. _amblksiz Prototype in <stdlib.h>. This unsigned int data item contains the 
  977.           increment by which the "break" pointer for memory allocation will be 
  978.           advanced when there is no freed block large enough to satisfy a 
  979.           request to allocate a block of memory.  This value may be changed by 
  980.           a program at any time. 
  981.  
  982. _argc     This int item contains the number of arguments passed to main. 
  983.  
  984. _argv     This char ** item contains a pointer to a vector containing the 
  985.           actual arguments passed to main. 
  986.  
  987. daylight  Prototype in <time.h>. This unsigned int has a value of one when 
  988.           daylight saving time is supported in this locale and zero otherwise. 
  989.           Whenever a time function is called, the tzset function is called to 
  990.           set the value of the variable.  The value will be determined from the 
  991.           value of the TZ environment variable. 
  992.  
  993. _doserrno Prototype in <stdlib.h>. This int item contains the actual error code 
  994.           returned when a DOS function fails. 
  995.  
  996. environ   Prototype in <stdlib.h>. This char ** __near data item is a pointer 
  997.           to an array of character pointers to the environment strings. 
  998.  
  999. errno     Prototype in <errno.h>. This int item contains the number of the last 
  1000.           error that was detected.  The run-time library never resets errno to 
  1001.           0.  Symbolic names for these errors are found in the <errno.h> header 
  1002.           file.  See the descriptions for the perror and strerror functions for 
  1003.           information about the text which describes these errors. 
  1004.  
  1005. fltused_  The C compiler places a reference to the fltused_ symbol into any 
  1006.           module that uses a floating-point library routine or library routine 
  1007.           that requires floating-point support (e.g., the use of "%f" in the 
  1008.           printf function). 
  1009.  
  1010. _fmode    Prototype in <stdlib.h>. This data item contains the default type of 
  1011.           file (text or binary) translation for a file.  It will contain a 
  1012.           value of either 
  1013.  
  1014.    O_BINARY      indicates that data is transmitted to and from streams 
  1015.                  unchanged. 
  1016.  
  1017.    O_TEXT        indicates that carriage return characters are added before 
  1018.                  linefeed characters on output operations and are removed on 
  1019.                  input operations when they precede linefeed characters. 
  1020.  
  1021.           These values are defined in the <fcntl.h> header file.  The value of 
  1022.           _fmode may be changed by a program to change the default behavior of 
  1023.           the open, fopen, creat and sopen functions. 
  1024.  
  1025. __minreal Prototype in <stdlib.h>. This data item contains the minimum amount 
  1026.           of real memory (below 640K) to reserve when running a 32-bit DOS 
  1027.           extended application. 
  1028.  
  1029. _osmajor  Prototype in <stdlib.h>. This unsigned char variable contains the 
  1030.           major number for the version of DOS executing on the computer.  If 
  1031.           the current version is 3.20, then the value will be 3. 
  1032.  
  1033. _osminor  Prototype in <stdlib.h>. This unsigned char variable contains the 
  1034.           minor number for the version of DOS executing on the computer.  If 
  1035.           the current version is 3.20, then the value will be 20. 
  1036.  
  1037. _osmode   Prototype in <stdlib.h>. This unsigned char variable contains either 
  1038.           the value DOS_MODE which indicates the program is running in real 
  1039.           address mode, or it contains the value OS2_MODE which indicates the 
  1040.           program is running in protected address mode. 
  1041.  
  1042. _psp      Prototype in <stdlib.h>. This data item contains the segment value 
  1043.           for the DOS program segment prefix.  Consult the technical 
  1044.           documentation for your DOS system for the process information 
  1045.           contained in the program segment prefix. 
  1046.  
  1047. _stacksize On 16-bit 80x86 systems, this unsigned int value contains the size 
  1048.           of the stack for a TINY memory model program. Changing the value of 
  1049.           this item during the execution of a program will have no effect upon 
  1050.           the program, since the value is used when the program starts 
  1051.           execution.  To change the size of the stack to be 8K bytes, a 
  1052.           statement such as follows can be included with the program. 
  1053.  
  1054.                     unsigned int _stacksize = { 8 * 1024 };
  1055.  
  1056. stdaux    Prototype in <stdio.h>. This variable (with type FILE *) indicates 
  1057.           the standard auxiliary port. 
  1058.  
  1059. stderr    Prototype in <stdio.h>. This variable (with type FILE *) indicates 
  1060.           the standard error stream (set to the console by default). 
  1061.  
  1062. stdin     Prototype in <stdio.h>. This variable (with type FILE *) indicates 
  1063.           the standard input stream (set to the console by default). 
  1064.  
  1065. stdout    Prototype in <stdio.h>. This variable (with type FILE *) indicates 
  1066.           the standard output stream (set to the console by default). 
  1067.  
  1068. stdprn    Prototype in <stdio.h>. This variable (with type FILE *) indicates 
  1069.           the standard printer. 
  1070.  
  1071. sys_errlist Prototype in <stdlib.h>. This variable is an array of pointers to 
  1072.           character strings for each error code defined in the <errno.h> header 
  1073.           file. 
  1074.  
  1075. sys_nerr  Prototype in <stdlib.h>. This int variable contains the number of 
  1076.           messages declared in sys_errlist. 
  1077.  
  1078. _threadid Prototype in <stddef.h>. This variable contains a far pointer to an 
  1079.           int which points to the id of the current thread.  This variable is 
  1080.           defined only in the CLIBMTL library for OS/2. 
  1081.  
  1082. timezone  Prototype in <time.h>. This long int contains the number of seconds 
  1083.           of time that the local time zone is earlier than Coordinated 
  1084.           Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)). 
  1085.           Whenever a time function is called, the tzset function is called to 
  1086.           set the value of the variable.  The value will be determined from the 
  1087.           value of the TZ environment variable. 
  1088.  
  1089. tzname    Prototype in <time.h>. This array of two pointers to character 
  1090.           strings indicates the name of the standard abbreviation for the time 
  1091.           zone and the name of the abbreviation for the time zone when daylight 
  1092.           saving time is in effect.  Whenever a time function is called, the 
  1093.           tzset function is called to set the values in the array.  These 
  1094.           values will be determined from the value of the TZ environment 
  1095.           variable. 
  1096.  
  1097. __win_flags_alloc Prototype in <stdlib.h>. This unsigned long int variable 
  1098.           contains the flags to be used when allocating memory in Windows. 
  1099.  
  1100. __win_flags_realloc Prototype in <stdlib.h>. This unsigned long int variable 
  1101.           contains the flags to be used when reallocating memory in Windows. 
  1102.  
  1103.  
  1104. ΓòÉΓòÉΓòÉ 1.4. The TZ Environment Variable ΓòÉΓòÉΓòÉ
  1105.  
  1106. The TZ environment variable is used to establish the local time zone.  The 
  1107. value of the variable is used by various time functions to compute times 
  1108. relative to Coordinated Universal Time (UTC) (formerly known as Greenwich Mean 
  1109. Time (GMT)). 
  1110.  
  1111. The time on the computer should be set to the local time.  Use the DOS time 
  1112. command and the DOS date command if the time is not automatically maintained by 
  1113. the computer hardware. 
  1114.  
  1115. The TZ environment variable can be set (before the program is executed) by 
  1116. using the DOS set command as follows: 
  1117.  
  1118. SET TZ=PST8PDT
  1119.  
  1120. or (during the program execution) by using the setenv or putenv library 
  1121. functions: 
  1122.  
  1123. setenv( "TZ", "PST8PDT", 1 );
  1124. putenv( "TZ=PST8PDT" );
  1125.  
  1126. The value of the variable can be obtained by using the getenv function: 
  1127.  
  1128. char *tzvalue;
  1129. tzvalue = getenv( "TZ" );
  1130.  
  1131. The tzset function processes the TZ environment variable and sets the global 
  1132. variables daylight (indicates if daylight saving time is supported in the 
  1133. locale), timezone (contains the number of seconds of time difference between 
  1134. the local time zone and Coordinated Universal Time (UTC)), and tzname (a vector 
  1135. of two pointers to character strings containing the standard and daylight 
  1136. time-zone names). 
  1137.  
  1138. The value of the TZ environment variable should be set as follows (spaces are 
  1139. for clarity only): 
  1140.  
  1141. std offset dst offset , rule
  1142.  
  1143. The expanded format is as follows: 
  1144.  
  1145. stdoffset[dst[offset][,start[/time],end[/time]]]
  1146.  
  1147. std, dst  three or more letters that are the designation for the standard (std) 
  1148.           or summer (dst) time zone.  Only std is required.  If dst is omitted, 
  1149.           then summer time does not apply in this locale.  Upper- and lowercase 
  1150.           letters are allowed.  Any characters except for a leading colon (:), 
  1151.           digits, comma (,), minus (-), plus (+), and ASCII NUL (\0) are 
  1152.           allowed. 
  1153.  
  1154. offset    indicates the value one must add to the local time to arrive at 
  1155.           Coordinated Universal Time (UTC).  The offset has the form: 
  1156.  
  1157.                     hh[:mm[:ss]]
  1158.  
  1159.           The minutes (mm) and seconds (ss) are optional.  The hour (hh) is 
  1160.           required and may be a single digit.  The offset following std is 
  1161.           required.  If no offset follows dst, summer time is assumed to be one 
  1162.           hour ahead of standard time.  One or more digits may be used; the 
  1163.           value is always interpreted as a decimal number.  The hour may be 
  1164.           between 0 and 24, and the minutes (and seconds) - if present - 
  1165.           between 0 and 59.  If preceded by a "-", the time zone will be east 
  1166.           of the Prime Meridian ; otherwise it will be west (which may be 
  1167.           indicated by an optional preceding "+"). 
  1168.  
  1169. rule      indicates when to change to and back from summer time.  The rule has 
  1170.           the form: 
  1171.  
  1172.                     date/time,date/time
  1173.  
  1174.           where the first date describes when the change from standard to 
  1175.           summer time occurs and the second date describes when the change back 
  1176.           happens.  Each time field describes when, in current local time, the 
  1177.           change to the other time is made. 
  1178.  
  1179.           The format of date may be one of the following: 
  1180.  
  1181.    Jn        The Julian day n (1 <= n <= 365).  Leap days are not counted. 
  1182.              That is, in all years - including leap years - February 28 is day 
  1183.              59 and March 1 is day 60.  It is impossible to explicitly refer to 
  1184.              the occasional February 29. 
  1185.  
  1186.    n         The zero-based Julian day (0 <= n <= 365).  Leap years are 
  1187.              counted, and it is possible to refer to February 29. 
  1188.  
  1189.    Mm.n.d    The d'th day (0 <= d <= 6) of week n of month m of the year (1 <= 
  1190.              n <= 5, 1 <= m <= 12, where week 5 means "the last d day in month 
  1191.              m" which may occur in the fourth or fifth week).  Week 1 is the 
  1192.              first week in which the d'th day occurs.  Day zero is Sunday. 
  1193.  
  1194.           The time has the same format as offset except that no leading sign 
  1195.           ("+" or "-") is allowed.  The default, if time is omitted, is 
  1196.           02:00:00. 
  1197.  
  1198. Whenever ctime, _ctime, localtime, _localtime or mktime is called, the time 
  1199. zone names contained in the external variable tzname will be set as if the 
  1200. tzset function had been called.  The same is true if the %Z directive of 
  1201. strftime is used. 
  1202.  
  1203. Some examples are: 
  1204.  
  1205. TZ=EST5DST Eastern Standard Time is 5 hours earlier than Coordinated Universal 
  1206.           Time (UTC).  Standard time and daylight saving time both apply to 
  1207.           this locale.  By default, Eastern Daylight Time (DST) is one hour 
  1208.           ahead of standard time (i.e., DST4).  Since it is not specified, 
  1209.           daylight saving time starts on the first Sunday of April at 2:00 A.M. 
  1210.           and ends on the last Sunday of October at 2:00 A.M.  This is the 
  1211.           default when the TZ variable is not set. 
  1212.  
  1213. TZ=EST5DST4,M4.1.0/02:00:00,M10.5.0/02:00:00 This is the full specification for 
  1214.           the default when the TZ variable is not set.  Eastern Standard Time 
  1215.           is 5 hours earlier than Coordinated Universal Time (UTC).  Standard 
  1216.           time and daylight saving time both apply to this locale.  Eastern 
  1217.           Daylight Time (DST) is one hour ahead of standard time.  Daylight 
  1218.           saving time starts on the first (1) Sunday (0) of April (4) at 2:00 
  1219.           A.M.  and ends on the last (5) Sunday (0) of October (10) at 2:00 
  1220.           A.M. 
  1221.  
  1222. TZ=PST8PDT Pacific Standard Time is 8 hours earlier than Coordinated Universal 
  1223.           Time (UTC).  Standard time and daylight saving time both apply to 
  1224.           this locale.  By default, Pacific Daylight Time is one hour ahead of 
  1225.           standard time (i.e., PDT7).  Since it is not specified, daylight 
  1226.           saving time starts on the first Sunday of April at 2:00 A.M.  and 
  1227.           ends on the last Sunday of October at 2:00 A.M. 
  1228.  
  1229. TZ=NST3:30NDT1:30 Newfoundland Standard Time is 3 and 1/2 hours earlier than 
  1230.           Coordinated Universal Time (UTC).  Standard time and daylight saving 
  1231.           time both apply to this locale.  Newfoundland Daylight Time is 1 and 
  1232.           1/2 hours earlier than Coordinated Universal Time (UTC). 
  1233.  
  1234. TZ=Central Europe Time-2:00 Central European Time is 2 hours later than 
  1235.           Coordinated Universal Time (UTC).  Daylight saving time does not 
  1236.           apply in this locale. 
  1237.  
  1238.  
  1239. ΓòÉΓòÉΓòÉ 2. DOS Considerations ΓòÉΓòÉΓòÉ
  1240.  
  1241. For the most part, DOS (Disk Operating System) for your personal computer can 
  1242. be ignored, unless an application is highly dependent upon the hardware or uses 
  1243. specialized functions from the operating system.  In this section, some of 
  1244. these aspects will be addressed.  For a more detailed explanation, the 
  1245. technical documentation for the DOS that you are using should be consulted. 
  1246.  
  1247.  
  1248. ΓòÉΓòÉΓòÉ 2.1. DOS Devices ΓòÉΓòÉΓòÉ
  1249.  
  1250. Most of the hardware devices attached to your computer have names which are 
  1251. recognized by DOS.  These names cannot be used as the names of files.  Some 
  1252. examples are: 
  1253.  
  1254. CON       the console (screen) 
  1255. AUX       the serial (auxiliary) port 
  1256. COM1      serial port 1 
  1257. COM2      serial port 2 
  1258. PRN       the printer on the parallel port 
  1259. LPT1      the printer on the first parallel port 
  1260. LPT2      the printer on the second parallel port 
  1261. LPT3      the printer on the third parallel port 
  1262. NUL       a non-existent device, which accepts (and discards) output 
  1263.  
  1264. Disks (such as diskette drives and hard disks) are specified as single letters, 
  1265. starting with the letter A.  Diskette drives are first, followed by the hard 
  1266. disks:  A colon character (:) follows the letter for the drive. Either 
  1267. upper-case or lower-case letters can be used.  Some examples are: 
  1268.  
  1269. A:        the first disk drive 
  1270. a:        the first disk drive 
  1271. e:        the fifth disk drive 
  1272.  
  1273.  
  1274. ΓòÉΓòÉΓòÉ 2.2. DOS Directories ΓòÉΓòÉΓòÉ
  1275.  
  1276. Each disk drive is conceptually divided into directories.  Each directory is 
  1277. capable of containing files and/or other directories.  The initial directory, 
  1278. called the root directory,  is not named; all other directories are named and 
  1279. can be accessed with a path specification.  A path is either absolute or 
  1280. relative to the current working directory.  Some examples are: 
  1281.  
  1282. b:\       the root directory of the second disk drive 
  1283.  
  1284. \         the root directory of the current disk drive 
  1285.  
  1286. \outer\middle\inner directory inner which is contained within directory middle 
  1287.           which is contained within directory outer which is contained within 
  1288.           the root directory of the current disk drive. 
  1289.  
  1290. Directory names are separated by backslash characters (\).  The initial 
  1291. backslash character informs DOS that the path starts with the root directory. 
  1292. When the first character is not a backslash, the path starts with the current 
  1293. working directory on the indicated device. 
  1294.  
  1295. The DOS CHDIR (CD) command can be used to change the current working directory 
  1296. for a device.  Suppose that the following DOS commands were issued: 
  1297.  
  1298. chdir a:\apps\payroll
  1299. chdir c:\mydir
  1300.  
  1301. Then, the following path specifications are: 
  1302.  
  1303. Relative Path  Absolute Path 
  1304. a:xxx\y        a:\apps\payroll\xxx\y 
  1305. c:zzzzz        c:\mydir\zzzzz 
  1306.  
  1307. When no drive is specified, DOS uses the current disk drive. 
  1308.  
  1309.  
  1310. ΓòÉΓòÉΓòÉ 2.3. DOS File Names ΓòÉΓòÉΓòÉ
  1311.  
  1312. The name of a file within a directory has the format filename.ext where the 
  1313. required filename portion is up to eight characters in length and the optional 
  1314. ext portion is up to three characters in length.  A period character (.) 
  1315. separates the two names when the ext portion is present. 
  1316.  
  1317. More than eight characters can be given in the filename. DOS truncates the name 
  1318. to eight characters when a longer filename is given.  This may lead to 
  1319. erroneous results in some cases, since the files MYBIGDATAFILE and MYBIGDATES 
  1320. both refer to the file MYBIGDAT. 
  1321.  
  1322. The characters used in file names may be letters, digits as well as some other 
  1323. characters documented in your DOS technical documentation.  Most people 
  1324. restrict their file names to contain only letters and digits. Upper-case and 
  1325. lower-case letters are treated as being equivalent (file names are case 
  1326. insensitive).  Thus, the files 
  1327.  
  1328. MYDATA.NEW
  1329. mydata.new
  1330. MyData.New
  1331.  
  1332. all refer to the same file. 
  1333.  
  1334. You cannot use a DOS device name (such as CON or PRN, for example) for a file 
  1335. name.  See the section DOS Devices  for a list of these reserved names. 
  1336.  
  1337. A complete file designation has the following format: 
  1338.  
  1339. drive:\path\filename.ext
  1340.  
  1341. where: 
  1342.  
  1343. drive:    is an optional disk drive specification.  If omitted, the default 
  1344.           drive is used.  Some examples are: 
  1345.  
  1346.                     A:  (first disk drive)
  1347.                     c:  (third disk drive)
  1348.  
  1349. \path\    is the path specification for the directory containing the desired 
  1350.           file.  Some examples are: 
  1351.  
  1352.                     \mylib\
  1353.                     \apps\payroll\
  1354.  
  1355. filename.ext is the name of the file. 
  1356.  
  1357. Suppose that the current working directories are as follows: 
  1358.  
  1359. Drive   Directory 
  1360. A:      \payroll 
  1361. B:      \      (root directory) 
  1362. C:      \source\c 
  1363.  
  1364. and that the default disk drive is C:. Then, the following file designations 
  1365. will result in the indicated file references: 
  1366.  
  1367. Designation       Actual File 
  1368. pgm.c             C:\SOURCE\C\PGM.C 
  1369. \basic.dat        C:\BASIC.DAT 
  1370. paypgm\outsep.c   C:\SOURCE\C\PAYPGM\OUTSEP.C 
  1371. b:data            B:\DATA 
  1372. a:employee        A:\PAYROLL\EMPLOYEE 
  1373. a:\deduct\yr1988  A:\DEDUCT\YR1988 
  1374.  
  1375.  
  1376. ΓòÉΓòÉΓòÉ 2.4. DOS Files ΓòÉΓòÉΓòÉ
  1377.  
  1378. DOS files are stored within directories on disk drives.  Most software, 
  1379. including WATCOM C, treats files in two representations: 
  1380.  
  1381. BINARY    These files can contain arbitrary data.  It is the responsibility of 
  1382.           the software to recognize records within the file if they exist. 
  1383.  
  1384. TEXT      These files contain lines of "printable" characters.  Each line is 
  1385.           delimited by a carriage return character followed by a linefeed 
  1386.           character. 
  1387.  
  1388. Since the conceptual view of text files in the C language is that lines are 
  1389. terminated by only linefeed characters, the C library will remove carriage 
  1390. returns on input and add them on output, provided the mode is set to be text. 
  1391. This mode is set upon opening the file or with the setmode function. 
  1392.  
  1393.  
  1394. ΓòÉΓòÉΓòÉ 2.5. DOS Commands ΓòÉΓòÉΓòÉ
  1395.  
  1396. DOS commands are documented in the technical documention for your DOS system. 
  1397. These may be invoked from a C program with the system function. 
  1398.  
  1399.  
  1400. ΓòÉΓòÉΓòÉ 2.6. DOS Interrupts ΓòÉΓòÉΓòÉ
  1401.  
  1402. DOS interrupts and 8086 interrupts are documented in the technical 
  1403. documentation for your DOS system.  These may be generated from a C program by 
  1404. calling the bdos, intdos, intdosx, intr, int386, int386x, int86 and int86x 
  1405. functions. 
  1406.  
  1407.  
  1408. ΓòÉΓòÉΓòÉ 2.7. DOS Processes ΓòÉΓòÉΓòÉ
  1409.  
  1410. The current DOS system has the capability to execute only one process at a 
  1411. time.  Thus, when a process is initiated with the spawn... parameter P_WAIT, 
  1412. the new process will execute to completion before control returns to the 
  1413. initiating program.  Otherwise, the new task replaces the initial task.  Tasks 
  1414. can be started by using the system, exec... and spawn... functions. 
  1415.  
  1416.  
  1417. ΓòÉΓòÉΓòÉ 3. Library Functions and Macros ΓòÉΓòÉΓòÉ
  1418.  
  1419. Each of the functions or macros in the C Library is described in this chapter. 
  1420. Each description consists of a number of subsections: 
  1421.  
  1422. Synopsis: This subsection gives the header files that should be included within 
  1423.           a source file that references the function or macro.  It also shows 
  1424.           an appropriate declaration for the function or for a function that 
  1425.           could be substituted for a macro.  This declaration is not included 
  1426.           in your program; only the header file(s) should be included. 
  1427.  
  1428.           When a pointer argument is passed to a function and that function 
  1429.           does not modify the item indicated by that pointer, the argument is 
  1430.           shown with const before the argument.  For example, 
  1431.  
  1432.                     const char *string
  1433.  
  1434.           indicates that the array pointed at by string is not changed. 
  1435.  
  1436. Description: This subsection is a description of the function or macro. 
  1437.  
  1438. Returns:  This subsection describes the return value (if any) for the function 
  1439.           or macro. 
  1440.  
  1441. Errors:   This subsection describes the possible errno values. 
  1442.  
  1443. See Also: This optional subsection provides a list of related functions or 
  1444.           macros. 
  1445.  
  1446. Example:  This optional subsection consists of one or more examples of the use 
  1447.           of the function.  The examples are often just fragments of code (not 
  1448.           complete programs) for illustration purposes. 
  1449.  
  1450. Classification: This subsection provides an indication of where the function or 
  1451.           macro is commonly found.  The following notation is used: 
  1452.  
  1453.    ANSI        The function or macro is defined by the ANSI C standard. 
  1454.  
  1455.    POSIX 1003.1 The function or macro is not defined by the ANSI C standard. 
  1456.                The function is specified in the document IEEE Standard Portable 
  1457.                Operating System Interface  for Computer Environments  (IEEE 
  1458.                Draft Standard 1003.1-1990). 
  1459.  
  1460.    BIOS        The function accesses a service of the BIOS ROM's found in IBM 
  1461.                Personal Computers and compatibles.  These functions should not 
  1462.                be used if portability is a consideration. 
  1463.  
  1464.    DOS         The function or macro is neither ANSI nor POSIX.  It performs a 
  1465.                function related to DOS.  It may be found in other 
  1466.                implementations of C for personal computers with DOS.  Use these 
  1467.                functions with caution, if portability is a consideration. 
  1468.  
  1469.    Intel       The function or macro is neither ANSI nor POSIX.  It performs a 
  1470.                function related to the Intel x86 architecture.  It may be found 
  1471.                in other implementations of C for personal computers using Intel 
  1472.                chips.  Use these functions with caution, if portability is a 
  1473.                consideration. 
  1474.  
  1475.    OS/2        The function is specific to OS/2. 
  1476.  
  1477.    Windows     The function is specific to Microsoft Windows. 
  1478.  
  1479.    PenPoint    The function or macro is neither ANSI nor POSIX.  It performs a 
  1480.                function related to PenPoint.  It may be found in other 
  1481.                implementations of C for personal computers with PenPoint.  Use 
  1482.                these functions with caution, if portability is a consideration. 
  1483.  
  1484.    QNX         The function or macro is neither ANSI nor POSIX.  It performs a 
  1485.                function related to QNX.  It may be found in other 
  1486.                implementations of C for personal computers with QNX.  Use these 
  1487.                functions with caution, if portability is a consideration. 
  1488.  
  1489.    WATCOM      The function or macro is neither ANSI nor POSIX.  It may be 
  1490.                found in other implementations of the C language, but caution 
  1491.                should be used if portability is a consideration. 
  1492.  
  1493. Systems:  This subsection provides an indication of where the function or macro 
  1494.           is supported.  The following notation is used: 
  1495.  
  1496.    All         This function is supported under all systems. 
  1497.  
  1498.    DOS         This is DOS, a 16-bit real-mode system for Intel 80x86 
  1499.                computers. 
  1500.  
  1501.    DOS/32      This is DOS, extended for 32-bit protected-mode applications 
  1502.                running on Intel 386 or upward compatible systems. 
  1503.  
  1504.    DOS/PM      This is a 16-bit DOS protect-mode function running under Phar 
  1505.                Lap's 286|DOS-Extender "RUN286".  The function is found in one 
  1506.                of WATCOM's 16-bit protect-mode DOS libraries (DOSPM*.LIB under 
  1507.                the 16-bit OS2 subdirectory). 
  1508.  
  1509.    MACRO       This function is implemented as a macro (#define) under all 
  1510.                systems. 
  1511.  
  1512.    OS/2 1      This is IBM OS/2 1.x, a 16-bit protect-mode system for Intel 
  1513.                80286 and upwards compatible systems. 
  1514.  
  1515.                When "(MT)" appears after OS/2, it refers to the CLIBMTL library 
  1516.                which supports multi-threaded applications. 
  1517.  
  1518.                When "(DL)" appears after OS/2, it refers to the CLIBDLL library 
  1519.                which supports creation of Dynamic Link Libraries. 
  1520.  
  1521.                When "(all)" appears after "OS/2 2", it means all versions of 
  1522.                the OS/2 1.x libraries. 
  1523.  
  1524.                If a function is missing from the OS/2 library, it may be found 
  1525.                in WATCOM's 16-bit protect-mode DOS libraries (DOSPM*.LIB) for 
  1526.                Phar Lap's 286|DOS-Extender (RUN286). 
  1527.  
  1528.    OS/2 2      This is IBM OS/2 2.x, a 32-bit protect-mode system for Intel 
  1529.                80386 and upwards compatible systems. 
  1530.  
  1531.                When "(MT)" appears after OS/2, it refers to the CLIBMT3R or 
  1532.                CLIBMT3S library which supports multi-threaded applications. 
  1533.  
  1534.                When "(DL)" appears after OS/2, it refers to the CLIBDL3R or 
  1535.                CLIBDL3S library which supports creation of Dynamic Link 
  1536.                Libraries. 
  1537.  
  1538.                When "(all)" appears after "OS/2 2", it means all versions of 
  1539.                the OS/2 2.x libraries. 
  1540.  
  1541.    PenPoint    This is Go Corporation's PenPoint 1.0 operating system. 
  1542.  
  1543.    QNX         This is Quantum's 16-bit protect-mode operating system, QNX 4.x. 
  1544.  
  1545.    Win/16      This is Microsoft Windows 3.0, a 16-bit protect-mode system for 
  1546.                Intel 286 and upwards compatible systems. 
  1547.  
  1548.    Win/32      This is Microsoft Windows 3.0, extended for 32-bit protect-mode 
  1549.                applications running on Intel 386 or upward compatible systems. 
  1550.                This support is provided by WATCOM C/386. 
  1551.  
  1552.  
  1553. ΓòÉΓòÉΓòÉ 4. abort ΓòÉΓòÉΓòÉ
  1554.  
  1555. Synopsis: 
  1556.  
  1557.                     #include <stdlib.h>
  1558.                     void abort( void );
  1559.  
  1560. Description: The abort function raises the signal SIGABRT.  The default action 
  1561.           for SIGABRT is to terminate program execution, returning control to 
  1562.           the process that started the calling program (usually the operating 
  1563.           system). The status unsuccessful termination  is returned to the 
  1564.           invoking process by means of the function call raise(SIGABRT). Under 
  1565.           DOS and OS/2, the status value is 3. 
  1566.  
  1567. Returns:  The abort function does not return to its caller. 
  1568.  
  1569. See Also: atexit, exec Functions, exit, _exit, getcmd, getenv, main, onexit, 
  1570.           putenv, spawn Functions, system 
  1571.  
  1572. Example: 
  1573.  
  1574.                     #include <stdlib.h>
  1575.  
  1576.                     void main()
  1577.                       {
  1578.                         int major_error = 1;
  1579.  
  1580.                         if( major_error )
  1581.                           abort();
  1582.                       }
  1583.  
  1584. Classification: ANSI 
  1585.  
  1586.  
  1587. ΓòÉΓòÉΓòÉ 5. abs ΓòÉΓòÉΓòÉ
  1588.  
  1589. Synopsis: 
  1590.  
  1591.                     #include <stdlib.h>
  1592.                     int abs( int j );
  1593.  
  1594. Description: The abs function returns the absolute value of its integer 
  1595.           argument j. 
  1596.  
  1597. Returns:  The abs function returns the absolute value of its argument. 
  1598.  
  1599. See Also: fabs, labs 
  1600.  
  1601. Example: 
  1602.  
  1603.                     #include <stdio.h>
  1604.                     #include <stdlib.h>
  1605.  
  1606.                     void main()
  1607.                       {
  1608.                         printf( "%d %d %d\n", abs( -5 ), abs( 0 ), abs( 5 ) );
  1609.                       }
  1610.  
  1611.           produces the following: 
  1612.  
  1613.                     5 0 5
  1614.  
  1615. Classification: ANSI 
  1616.  
  1617.  
  1618. ΓòÉΓòÉΓòÉ 6. access ΓòÉΓòÉΓòÉ
  1619.  
  1620. Synopsis: 
  1621.  
  1622.                     #include <io.h>
  1623.                     int access( const char *path, int mode );
  1624.  
  1625. Description: The access function determines if the file or directory specified 
  1626.           by path exists and if it can be accessed with the file permission 
  1627.           given by mode. 
  1628.  
  1629.           When the value of mode is zero, only the existence of the file is 
  1630.           verified.  The read and/or write permission for the file can be 
  1631.           determined when mode is a combination of the bits: 
  1632.  
  1633.    Bit       Meaning 
  1634.    R_OK      test for read permission 
  1635.    W_OK      test for write permission 
  1636.    X_OK      test for execute permission 
  1637.    F_OK      test for existence of file 
  1638.  
  1639.           With DOS, all files have read permission; it is a good idea to test 
  1640.           for read permission anyway, since a later version of DOS may support 
  1641.           write-only files. 
  1642.  
  1643. Returns:  The access returns zero if the file or directory exists and can be 
  1644.           accessed with the specified mode.  Otherwise, -1 is returned and 
  1645.           errno is set to indicate the error. 
  1646.  
  1647. Errors:   When an error has occurred, errno contains a value indicating the 
  1648.           type of error that has been detected. 
  1649.  
  1650.    Constant  Meaning 
  1651.  
  1652.    EACCES    Access denied because the file's permission does not allow the 
  1653.              specified access. 
  1654.  
  1655.    ENOENT    Path or file not found. 
  1656.  
  1657. See Also: chmod, fstat, open, sopen, stat 
  1658.  
  1659. Example: 
  1660.  
  1661.                     #include <stdio.h>
  1662.                     #include <stdlib.h>
  1663.                     #include <io.h>
  1664.                     void main( int argc, char *argv[] )
  1665.                       {
  1666.                         if( argc != 2 ) {
  1667.                           fprintf( stderr, "Use: check <filename>\n" );
  1668.                           exit( 1 );
  1669.                         }
  1670.                         if( access( argv[1], F_OK ) == 0 ) {
  1671.                           printf( "%s exists\n", argv[1] );
  1672.                         } else {
  1673.                           printf( "%s does not exist\n", argv[1] );
  1674.                           exit( EXIT_FAILURE );
  1675.                         }
  1676.                         if( access( argv[1], R_OK ) == 0 ) {
  1677.                           printf( "%s is readable\n", argv[1] );
  1678.                         }
  1679.                         if( access( argv[1], W_OK ) == 0 ) {
  1680.                           printf( "%s is writeable\n", argv[1] );
  1681.                         }
  1682.                         if( access( argv[1], X_OK ) == 0 ) {
  1683.                           printf( "%s is executable\n", argv[1] );
  1684.                         }
  1685.                         exit( EXIT_SUCCESS );
  1686.                       }
  1687.  
  1688. Classification: POSIX 1003.1 
  1689.  
  1690.  
  1691. ΓòÉΓòÉΓòÉ 7. acos ΓòÉΓòÉΓòÉ
  1692.  
  1693. Synopsis: 
  1694.  
  1695.                     #include <math.h>
  1696.                     double acos( double x );
  1697.  
  1698. Description: The acos function computes the principal value of the arccosine of 
  1699.           x. A domain error occurs for arguments not in the range [-1,1]. 
  1700.  
  1701. Returns:  The acos function returns the arccosine in the range [0,PI].  When 
  1702.           the argument is outside the permissible range, the matherr function 
  1703.           is called.  Unless the default matherr function is replaced, it will 
  1704.           set the global variable errno to EDOM, and print a "DOMAIN error" 
  1705.           diagnostic message using the stderr stream. 
  1706.  
  1707. See Also: asin, atan, atan2, matherr 
  1708.  
  1709. Example: 
  1710.  
  1711.                     #include <stdio.h>
  1712.                     #include <math.h>
  1713.  
  1714.                     void main()
  1715.                       {
  1716.                         printf( "%f\n", acos(.5) );
  1717.                       }
  1718.  
  1719.           produces the following: 
  1720.  
  1721.                     1.047197
  1722.  
  1723. Classification: ANSI 
  1724.  
  1725.  
  1726. ΓòÉΓòÉΓòÉ 8. acosh ΓòÉΓòÉΓòÉ
  1727.  
  1728. Synopsis: 
  1729.  
  1730.                     #include <math.h>
  1731.                     double acosh( double x );
  1732.  
  1733. Description: The acosh function computes the inverse hyperbolic cosine of x. A 
  1734.           domain error occurs if the value of x is less than 1.0. 
  1735.  
  1736. Returns:  The acosh function returns the inverse hyperbolic cosine value.  When 
  1737.           the argument is outside the permissible range, the matherr function 
  1738.           is called.  Unless the default matherr function is replaced, it will 
  1739.           set the global variable errno to EDOM, and print a "DOMAIN error" 
  1740.           diagnostic message using the stderr stream. 
  1741.  
  1742. See Also: asinh, atanh, cosh, matherr 
  1743.  
  1744. Example: 
  1745.  
  1746.                     #include <stdio.h>
  1747.                     #include <math.h>
  1748.  
  1749.                     main()
  1750.                       {
  1751.                         printf( "%f\n", acosh(1.5) );
  1752.                       }
  1753.  
  1754.           produces the following: 
  1755.  
  1756.                     0.962424
  1757.  
  1758. Classification: WATCOM 
  1759.  
  1760.  
  1761. ΓòÉΓòÉΓòÉ 9. alloca ΓòÉΓòÉΓòÉ
  1762.  
  1763. Synopsis: 
  1764.  
  1765.                     #include <malloc.h>
  1766.                     void *alloca( size_t size );
  1767.  
  1768. Description: The alloca function allocates space for an object of size bytes 
  1769.           from the stack.  The allocated space is automatically discarded when 
  1770.           the current function exits.  The alloca function should not be used 
  1771.           in an expression that is an argument to a function. 
  1772.  
  1773. Returns:  The alloca function returns a pointer to the start of the allocated 
  1774.           memory.  The return value is NULL if there is insufficient stack 
  1775.           space available. 
  1776.  
  1777. See Also: calloc, malloc, _nmalloc, stackavail 
  1778.  
  1779. Example: 
  1780.  
  1781.                     #include <stdio.h>
  1782.                     #include <string.h>
  1783.                     #include <malloc.h>
  1784.                     FILE *open_err_file( char * );
  1785.                     void main()
  1786.                       {
  1787.                         FILE *fp;
  1788.  
  1789.                         fp = open_err_file( "alloca" );
  1790.                         if( fp == NULL ) {
  1791.                           printf( "Unable to open error file\n" );
  1792.                         } else {
  1793.                           fclose( fp );
  1794.                         }
  1795.                       }
  1796.                     FILE *open_err_file( char *name )
  1797.                       {
  1798.                          char *buffer;
  1799.                          /* allocate temp buffer for file name */
  1800.                          buffer = alloca( strlen(name) + 5 );
  1801.                          if( buffer ) {
  1802.                            sprintf( buffer, "%s.err", name );
  1803.                            return( fopen( buffer, "w" ) );
  1804.                          }
  1805.                          return( (FILE *) NULL );
  1806.                       }
  1807.  
  1808. Classification: WATCOM 
  1809.  
  1810.  
  1811. ΓòÉΓòÉΓòÉ 10. asctime, _asctime ΓòÉΓòÉΓòÉ
  1812.  
  1813. Synopsis: 
  1814.  
  1815.                     #include <time.h>
  1816.                     char * asctime( const struct tm *timeptr );
  1817.                     char *_asctime( const struct tm *timeptr, char *buf );
  1818.  
  1819.                     struct tm {
  1820.                       int tm_sec;   /* seconds after the minute -- [0,61] */
  1821.                       int tm_min;   /* minutes after the hour -- [0,59] */
  1822.                       int tm_hour;  /* hours after midnight -- [0,23] */
  1823.                       int tm_mday;  /* day of the month -- [1,31] */
  1824.                       int tm_mon;   /* months since January -- [0,11] */
  1825.                       int tm_year;  /* years since 1900 */
  1826.                       int tm_wday;  /* days since Sunday -- [0,6] */
  1827.                       int tm_yday;  /* days since January 1 -- [0,365]*/
  1828.                       int tm_isdst; /* Daylight Savings Time flag */
  1829.                     };
  1830.  
  1831. Description: The asctime functions convert the time information in the 
  1832.           structure pointed to by timeptr into a string containing exactly 26 
  1833.           characters.  This string has the form shown in the following example: 
  1834.  
  1835.                     Sat Mar 21 15:58:27 1987\n\0
  1836.  
  1837.           All fields have a constant width.  The new-line character '\n' and 
  1838.           the null character '\0' occupy the last two positions of the string. 
  1839.  
  1840.           The function _asctime places the result string in the buffer pointed 
  1841.           to by buf, and the function asctime places the result string in a 
  1842.           static buffer that is re-used each time asctime is called. 
  1843.  
  1844. Returns:  The asctime functions return a pointer to the character string 
  1845.           result. 
  1846.  
  1847. See Also: clock, ctime, difftime, gmtime, localtime, mktime, strftime, time, 
  1848.           tzset 
  1849.  
  1850. Example: 
  1851.  
  1852.                     #include <stdio.h>
  1853.                     #include <time.h>
  1854.                     void main()
  1855.                       {
  1856.                         struct tm  time_of_day;
  1857.                         time_t     ltime;
  1858.                         auto char  buf[26];
  1859.                         time( <ime );
  1860.                         _localtime( <ime, &time_of_day );
  1861.                         printf( "Date and time is: %s\n",
  1862.                                 _asctime( &time_of_day, buf ) );
  1863.                       }
  1864.  
  1865.           produces the following: 
  1866.  
  1867.                     Sat Mar 21 15:58:27 1987
  1868.  
  1869. Classification: asctime is ANSI, _asctime is not ANSI 
  1870.  
  1871.  
  1872. ΓòÉΓòÉΓòÉ 11. asin ΓòÉΓòÉΓòÉ
  1873.  
  1874. Synopsis: 
  1875.  
  1876.                     #include <math.h>
  1877.                     double asin( double x );
  1878.  
  1879. Description: The asin function computes the principal value of the arcsine of 
  1880.           x. A domain error occurs for arguments not in the range [-1,1]. 
  1881.  
  1882. Returns:  The asin function returns the arcsine in the range [-PI/2,PI/2]. 
  1883.           When the argument is outside the permissible range, the matherr 
  1884.           function is called.  Unless the default matherr function is replaced, 
  1885.           it will set the global variable errno to EDOM, and print a "DOMAIN 
  1886.           error" diagnostic message using the stderr stream. 
  1887.  
  1888. See Also: acos, atan, atan2, matherr 
  1889.  
  1890. Example: 
  1891.  
  1892.                     #include <stdio.h>
  1893.                     #include <math.h>
  1894.  
  1895.                     void main()
  1896.                       {
  1897.                         printf( "%f\n", asin(.5) );
  1898.                       }
  1899.  
  1900.           produces the following: 
  1901.  
  1902.                     0.523599
  1903.  
  1904. Classification: ANSI 
  1905.  
  1906.  
  1907. ΓòÉΓòÉΓòÉ 12. asinh ΓòÉΓòÉΓòÉ
  1908.  
  1909. Synopsis: 
  1910.  
  1911.                     #include <math.h>
  1912.                     double asinh( double x );
  1913.  
  1914. Description: The asinh function computes the inverse hyperbolic sine of x. 
  1915.  
  1916. Returns:  The asinh function returns the inverse hyperbolic sine value. 
  1917.  
  1918. See Also: acosh, atanh, sinh, matherr 
  1919.  
  1920. Example: 
  1921.  
  1922.                     #include <stdio.h>
  1923.                     #include <math.h>
  1924.  
  1925.                     main()
  1926.                       {
  1927.                         printf( "%f\n", asinh(0.5) );
  1928.                       }
  1929.  
  1930.           produces the following: 
  1931.  
  1932.                     0.481212
  1933.  
  1934. Classification: WATCOM 
  1935.  
  1936.  
  1937. ΓòÉΓòÉΓòÉ 13. assert ΓòÉΓòÉΓòÉ
  1938.  
  1939. Synopsis: 
  1940.  
  1941.                     #include <assert.h>
  1942.                     void assert( int expression );
  1943.  
  1944. Description: The assert macro prints a diagnostic message upon the stderr 
  1945.           stream and terminates the program if expression is false (0).  The 
  1946.           diagnostic message has the form 
  1947.  
  1948.           Assertion failed: expression, file filename, line linenumber 
  1949.  
  1950.           where filename is the name of the source file and linenumber is the 
  1951.           line number of the assertion that failed in the source file. Filename 
  1952.           and linenumber are the values of the preprocessing macros __FILE__ 
  1953.           and __LINE__ respectively.  No action is taken if expression is true 
  1954.           (non-zero). 
  1955.  
  1956.           The assert macro is typically used during program development to 
  1957.           identify program logic errors.  The given expression should be chosen 
  1958.           so that it is true when the program is functioning as intended. 
  1959.           After the program has been debugged, the special "no debug" 
  1960.           identifier NDEBUG can be used to remove assert calls from the program 
  1961.           when it is re-compiled.  If NDEBUG is defined (with any value) with a 
  1962.           -d command line option or with a #define directive, the C 
  1963.           preprocessor ignores all assert calls in the program source. 
  1964.  
  1965. Returns:  The assert macro does not return a value. 
  1966.  
  1967. Example: 
  1968.  
  1969.                     #include <stdio.h>
  1970.                     #include <assert.h>
  1971.                     void main()
  1972.                       {
  1973.                         process_string( "hello" );
  1974.                         process_string( "" );
  1975.                       }
  1976.                     void process_string( char *string )
  1977.                       {
  1978.                         /* use assert to check argument */
  1979.                         assert( string != NULL );
  1980.                         assert( *string != '\0' );
  1981.                         /* rest of code follows here */
  1982.                       }
  1983.  
  1984. Classification: ANSI 
  1985.  
  1986.  
  1987. ΓòÉΓòÉΓòÉ 14. atan ΓòÉΓòÉΓòÉ
  1988.  
  1989. Synopsis: 
  1990.  
  1991.                     #include <math.h>
  1992.                     double atan( double x );
  1993.  
  1994. Description: The atan function computes the principal value of the arctangent 
  1995.           of x. 
  1996.  
  1997. Returns:  The atan function returns the arctangent in the range (-PI/2,PI/2). 
  1998.  
  1999. See Also: acos, asin, atan2 
  2000.  
  2001. Example: 
  2002.  
  2003.                     #include <stdio.h>
  2004.                     #include <math.h>
  2005.  
  2006.                     void main()
  2007.                       {
  2008.                         printf( "%f\n", atan(.5) );
  2009.                       }
  2010.  
  2011.           produces the following: 
  2012.  
  2013.                     0.463648
  2014.  
  2015. Classification: ANSI 
  2016.  
  2017.  
  2018. ΓòÉΓòÉΓòÉ 15. atan2 ΓòÉΓòÉΓòÉ
  2019.  
  2020. Synopsis: 
  2021.  
  2022.                     #include <math.h>
  2023.                     double atan2( double y, double x );
  2024.  
  2025. Description: The atan2 function computes the principal value of the arctangent 
  2026.           of y/x, using the signs of both arguments to determine the quadrant 
  2027.           of the return value.  A domain error occurs if both arguments are 
  2028.           zero. 
  2029.  
  2030. Returns:  The atan2 function returns the arctangent of y/x, in the range 
  2031.           (-PI,PI).  When the argument is outside the permissible range, the 
  2032.           matherr function is called.  Unless the default matherr function is 
  2033.           replaced, it will set the global variable errno to EDOM, and print a 
  2034.           "DOMAIN error" diagnostic message using the stderr stream. 
  2035.  
  2036. See Also: acos, asin, atan, matherr 
  2037.  
  2038. Example: 
  2039.  
  2040.                     #include <stdio.h>
  2041.                     #include <math.h>
  2042.  
  2043.                     void main()
  2044.                       {
  2045.                         printf( "%f\n", atan2( .5, 1. ) );
  2046.                       }
  2047.  
  2048.           produces the following: 
  2049.  
  2050.                     0.463648
  2051.  
  2052. Classification: ANSI 
  2053.  
  2054.  
  2055. ΓòÉΓòÉΓòÉ 16. atanh ΓòÉΓòÉΓòÉ
  2056.  
  2057. Synopsis: 
  2058.  
  2059.                     #include <math.h>
  2060.                     double atanh( double x );
  2061.  
  2062. Description: The atanh function computes the inverse hyperbolic tangent of x. A 
  2063.           domain error occurs if the value of x is outside the range (-1,1). 
  2064.  
  2065. Returns:  The atanh function returns the inverse hyperbolic tangent value. 
  2066.           When the argument is outside the permissible range, the matherr 
  2067.           function is called.  Unless the default matherr function is replaced, 
  2068.           it will set the global variable errno to EDOM, and print a "DOMAIN 
  2069.           error" diagnostic message using the stderr stream. 
  2070.  
  2071. See Also: acosh, asinh, matherr, tanh 
  2072.  
  2073. Example: 
  2074.  
  2075.                     #include <stdio.h>
  2076.                     #include <math.h>
  2077.  
  2078.                     main()
  2079.                       {
  2080.                         printf( "%f\n", atanh(0.5) );
  2081.                       }
  2082.  
  2083.           produces the following: 
  2084.  
  2085.                     0.549306
  2086.  
  2087. Classification: WATCOM 
  2088.  
  2089.  
  2090. ΓòÉΓòÉΓòÉ 17. atexit ΓòÉΓòÉΓòÉ
  2091.  
  2092. Synopsis: 
  2093.  
  2094.                     #include <stdlib.h>
  2095.                     int atexit( void (*func)(void) );
  2096.  
  2097. Description: The atexit function is passed the address of function func to be 
  2098.           called when the program terminates normally.  Successive calls to 
  2099.           atexit create a list of functions that will be executed on a 
  2100.           "last-in, first-out" basis.  No more than 32 functions can be 
  2101.           registered with the atexit function. 
  2102.  
  2103.           The functions have no parameters and do not return values. 
  2104.  
  2105. Returns:  The atexit function returns zero if the registration succeeds, 
  2106.           non-zero if it fails. 
  2107.  
  2108. See Also: abort, _exit, exit 
  2109.  
  2110. Example: 
  2111.  
  2112.                     #include <stdio.h>
  2113.                     #include <stdlib.h>
  2114.                     void main()
  2115.                       {
  2116.                         void func1(void), func2(void), func3(void);
  2117.                         atexit( func1 );
  2118.                         atexit( func2 );
  2119.                         atexit( func3 );
  2120.                         printf( "Do this first.\n" );
  2121.                       }
  2122.                     void func1(void) { printf( "last.\n" ); }
  2123.                     void func2(void) { printf( "this " ); }
  2124.                     void func3(void) { printf( "Do " ); }
  2125.  
  2126.           produces the following: 
  2127.  
  2128.                     Do this first.
  2129.                     Do this last.
  2130.  
  2131. Classification: ANSI 
  2132.  
  2133.  
  2134. ΓòÉΓòÉΓòÉ 18. atof ΓòÉΓòÉΓòÉ
  2135.  
  2136. Synopsis: 
  2137.  
  2138.                     #include <stdlib.h>
  2139.                     double atof( const char *ptr );
  2140.  
  2141. Description: The atof function converts the string pointed to by ptr to double 
  2142.           representation.  It is equivalent to 
  2143.  
  2144.                     strtod( ptr, (char **)NULL )
  2145.  
  2146. Returns:  The atof function returns the converted value.  Zero is returned when 
  2147.           the input string cannot be converted.  When an error has occurred, 
  2148.           errno contains a value indicating the type of error that has been 
  2149.           detected. 
  2150.  
  2151. See Also: sscanf, strtod 
  2152.  
  2153. Example: 
  2154.  
  2155.                     #include <stdlib.h>
  2156.  
  2157.                     void main()
  2158.                       {
  2159.                         double x;
  2160.  
  2161.                         x = atof( "3.1415926" );
  2162.                       }
  2163.  
  2164. Classification: ANSI 
  2165.  
  2166.  
  2167. ΓòÉΓòÉΓòÉ 19. atoi ΓòÉΓòÉΓòÉ
  2168.  
  2169. Synopsis: 
  2170.  
  2171.                     #include <stdlib.h>
  2172.                     int atoi( const char *ptr );
  2173.  
  2174. Description: The atoi function converts the string pointed to by ptr to int 
  2175.           representation. 
  2176.  
  2177. Returns:  The atoi function returns the converted value. 
  2178.  
  2179. See Also: sscanf, strtol 
  2180.  
  2181. Example: 
  2182.  
  2183.                     #include <stdlib.h>
  2184.  
  2185.                     void main()
  2186.                       {
  2187.                         int x;
  2188.  
  2189.                         x = atoi( "-289" );
  2190.                       }
  2191.  
  2192. Classification: ANSI 
  2193.  
  2194.  
  2195. ΓòÉΓòÉΓòÉ 20. atol ΓòÉΓòÉΓòÉ
  2196.  
  2197. Synopsis: 
  2198.  
  2199.                     #include <stdlib.h>
  2200.                     long int atol( const char *ptr );
  2201.  
  2202. Description: The atol function converts the string pointed to by ptr to long 
  2203.           int representation. 
  2204.  
  2205. Returns:  The atol function returns the converted value. 
  2206.  
  2207. See Also: sscanf, strtol 
  2208.  
  2209. Example: 
  2210.  
  2211.                     #include <stdlib.h>
  2212.  
  2213.                     void main()
  2214.                       {
  2215.                         long int x;
  2216.  
  2217.                         x = atol( "-289" );
  2218.                       }
  2219.  
  2220. Classification: ANSI 
  2221.  
  2222.  
  2223. ΓòÉΓòÉΓòÉ 21. bdos ΓòÉΓòÉΓòÉ
  2224.  
  2225. Synopsis: 
  2226.  
  2227.                     #include <dos.h>
  2228.                     int bdos( int dos_func, unsigned dx, unsigned char al );
  2229.  
  2230. Description: The bdos function causes the computer's central processor (CPU) to 
  2231.           be interrupted with an interrupt number hexadecimal 21 ( 0x21 ), 
  2232.           which is a request to invoke a specific DOS function.  Before the 
  2233.           interrupt, the DX register is loaded from dx, the AH register is 
  2234.           loaded with the DOS function number from dos_func and the AL register 
  2235.           is loaded from al. The remaining registers are passed unchanged to 
  2236.           DOS. 
  2237.  
  2238.           You should consult the technical documentation for the DOS operating 
  2239.           system you are using to determine the expected register contents 
  2240.           before and after the interrupt in question. 
  2241.  
  2242. Returns:  The function returns the value of the AX register after the interrupt 
  2243.           has completed. 
  2244.  
  2245. See Also: int386, int386x, int86, int86x, intdos, intdosx, intr 
  2246.  
  2247. Example: 
  2248.  
  2249.                     #include <dos.h>
  2250.  
  2251.                     #define DISPLAY_OUTPUT  2
  2252.                     void main()
  2253.                       {
  2254.                         int rc;
  2255.  
  2256.                         rc = bdos( DISPLAY_OUTPUT, 'B', 0 );
  2257.                         rc = bdos( DISPLAY_OUTPUT, 'D', 0 );
  2258.                         rc = bdos( DISPLAY_OUTPUT, 'O', 0 );
  2259.                         rc = bdos( DISPLAY_OUTPUT, 'S', 0 );
  2260.                       }
  2261.  
  2262. Classification: DOS 
  2263.  
  2264.  
  2265. ΓòÉΓòÉΓòÉ 22. _beginthread ΓòÉΓòÉΓòÉ
  2266.  
  2267. Synopsis: 
  2268.  
  2269.                     #include <process.h>
  2270.                     int __far _beginthread(
  2271.                                  void (__far *start_address)(void __far *),
  2272.                                  void __far *stack_bottom,
  2273.                                  unsigned stack_size,
  2274.                                  void __far *arglist );
  2275.  
  2276. Description: The _beginthread function uses the OS/2 function DosCreateThread 
  2277.           to begin a new thread of execution at the function identified by 
  2278.           start_address with a single parameter identified by arglist. The new 
  2279.           thread will use the memory identified by stack_bottom and stack_size 
  2280.           for its stack.  The thread ends when it exits from its main function 
  2281.           or calls exit, _exit or _endthread. 
  2282.  
  2283. Returns:  The _beginthread function returns the thread id for the new thread if 
  2284.           successful.  A return value of -1 indicates that the thread could not 
  2285.           be started. 
  2286.  
  2287. See Also: _endthread 
  2288.  
  2289. Example: 
  2290.  
  2291.                     #include <stdio.h>
  2292.                     #include <stdlib.h>
  2293.                     #include <process.h>
  2294.                     #define  STACK_SIZE   4096
  2295.                     void __far child( char * __far *argv )
  2296.                       {
  2297.                         int  i;
  2298.                         for( i = 0; argv[i]; i++ ) {
  2299.                           printf( "argv[%d] = %s\n", i, argv[i] );
  2300.                         }
  2301.                         _endthread();
  2302.                       }
  2303.                     void main()
  2304.                       {
  2305.                         char *stack;
  2306.                         char *args[3];
  2307.                         int   tid;
  2308.                         args[0] = "child";
  2309.                         args[1] = "parm";
  2310.                         args[2] = NULL;
  2311.                         stack = malloc( STACK_SIZE );
  2312.                         tid = _beginthread( child, stack, STACK_SIZE, args );
  2313.                       }
  2314.  
  2315. Classification: OS/2 
  2316.  
  2317.  
  2318. ΓòÉΓòÉΓòÉ 23. bessel Functions ΓòÉΓòÉΓòÉ
  2319.  
  2320. Synopsis: 
  2321.  
  2322.                     #include <math.h>
  2323.                     double j0( double x );
  2324.                     double j1( double x );
  2325.                     double jn( int n, double x );
  2326.                     double y0( double x );
  2327.                     double y1( double x );
  2328.                     double yn( int n, double x );
  2329.  
  2330. Description: Functions j0, j1, and jn return Bessel functions of the first 
  2331.           kind. 
  2332.  
  2333.           Functions y0, y1, and yn return Bessel functions of the second kind. 
  2334.           The argument x must be positive.  If x is negative, _matherr will be 
  2335.           called to print a DOMAIN error message to stderr, set errno to EDOM, 
  2336.           and return the value -HUGE_VAL. This error handling can be modified 
  2337.           by using the matherr routine. 
  2338.  
  2339. Returns:  These functions return the result of the desired Bessel function of 
  2340.           x. 
  2341.  
  2342. See Also: matherr 
  2343.  
  2344. Example: 
  2345.  
  2346.                     #include <stdio.h>
  2347.                     #include <math.h>
  2348.  
  2349.                     void main()
  2350.                       {
  2351.                          double x, y, z;
  2352.  
  2353.                          x = j0( 2.4 );
  2354.                          y = y1( 1.58 );
  2355.                          z = jn( 3, 2.4 );
  2356.                          printf( "j0(2.4) = %f, y1(1.58) = %f\n", x, y );
  2357.                          printf( "jn(3,2.4) = %f\n", z );
  2358.                       }
  2359.  
  2360. Classification: WATCOM 
  2361.  
  2362.  
  2363. ΓòÉΓòÉΓòÉ 24. _bfreeseg ΓòÉΓòÉΓòÉ
  2364.  
  2365. Synopsis: 
  2366.  
  2367.                     #include <malloc.h>
  2368.                     int _bfreeseg( __segment seg );
  2369.  
  2370. Description: The _bfreeseg function frees a based-heap segment. 
  2371.  
  2372.           The argument seg indicates the segment returned by an earlier call to 
  2373.           _bheapseg. 
  2374.  
  2375. Returns:  The _bfreeseg function returns 0 if successful and -1 if an error 
  2376.           occurred. 
  2377.  
  2378. See Also: _bheapseg, _bfree, _bcalloc, _bexpand, _bmalloc, _brealloc 
  2379.  
  2380. Example: 
  2381.  
  2382.                     #include <malloc.h>
  2383.  
  2384.                     struct list {
  2385.                         struct list __based(__self) *next;
  2386.                         int   value;
  2387.                     };
  2388.                     void main()
  2389.                       {
  2390.                         int   i;
  2391.                         __segment   seg;
  2392.  
  2393.                         struct list __based(seg) *head;
  2394.                         struct list __based(seg) *p;
  2395.                         /* allocate based heap */
  2396.                         seg = _bheapseg( 1024 );
  2397.                         if( seg == _NULLSEG ) {
  2398.                           printf( "Unable to allocate based heap\n" );
  2399.                           exit( 1 );
  2400.                         }
  2401.                         /* create a linked list in the based heap */
  2402.                         head = 0;
  2403.                         for( i = 1; i < 10; i++ ) {
  2404.                           p = _bmalloc( seg, sizeof( struct list ) );
  2405.                           if( p == _NULLOFF ) {
  2406.                             printf( "_bmalloc failed\n" );
  2407.                             break;
  2408.                           }
  2409.                           p->next = head;
  2410.                           p->value = i;
  2411.                           head = p;
  2412.                         }
  2413.                         /* traverse the linked list, printing out values */
  2414.                         for( p = head; p != 0; p = p->next ) {
  2415.                           printf( "Value = %d\n", p->value );
  2416.                         }
  2417.                         /* free all the elements of the linked list */
  2418.                         for( ; p = head; ) {
  2419.                           head = p->next;
  2420.                           _bfree( seg, p );
  2421.                         }
  2422.                         /* free the based heap */
  2423.                         _bfreeseg( seg );
  2424.                       }
  2425.  
  2426. Classification: WATCOM 
  2427.  
  2428.  
  2429. ΓòÉΓòÉΓòÉ 25. _bheapseg ΓòÉΓòÉΓòÉ
  2430.  
  2431. Synopsis: 
  2432.  
  2433.                     #include <malloc.h>
  2434.                     __segment _bheapseg( size_t size );
  2435.  
  2436. Description: The _bheapseg function allocates a based-heap segment of a least 
  2437.           size bytes. 
  2438.  
  2439.           The argument size indicates the initial size for the heap.  The heap 
  2440.           will automatically be enlarged as needed if there is not enough space 
  2441.           available within the heap to satisfy an allocation request by 
  2442.           _bcalloc, _bexpand, _bmalloc, or _brealloc. 
  2443.  
  2444.           The value returned by _bheapseg is the segment value or selector for 
  2445.           the based heap.  This value must be saved and used as an argument to 
  2446.           other based heap functions to indicate which based heap to operate 
  2447.           upon. 
  2448.  
  2449.           Each call to _bheapseg allocates a new based heap. 
  2450.  
  2451. Returns:  The value returned by _bheapseg is the segment value or selector for 
  2452.           the based heap.  This value must be saved and used as an argument to 
  2453.           other based heap functions to indicate which based heap to operate 
  2454.           upon.  A special value of _NULLSEG is returned if the segment could 
  2455.           not be allocated. 
  2456.  
  2457. See Also: _bfreeseg, _bcalloc, _bexpand, _bmalloc, _brealloc 
  2458.  
  2459. Example: 
  2460.  
  2461.                     #include <malloc.h>
  2462.  
  2463.                     struct list {
  2464.                         struct list __based(__self) *next;
  2465.                         int   value;
  2466.                     };
  2467.                     void main()
  2468.                       {
  2469.                         int   i;
  2470.                         __segment   seg;
  2471.                         struct list __based(seg) *head;
  2472.                         struct list __based(seg) *p;
  2473.                         /* allocate based heap */
  2474.                         seg = _bheapseg( 1024 );
  2475.                         if( seg == _NULLSEG ) {
  2476.                           printf( "Unable to allocate based heap\n" );
  2477.                           exit( 1 );
  2478.                         }
  2479.                         /* create a linked list in the based heap */
  2480.                         head = 0;
  2481.                         for( i = 1; i < 10; i++ ) {
  2482.                           p = _bmalloc( seg, sizeof( struct list ) );
  2483.                           if( p == _NULLOFF ) {
  2484.                             printf( "_bmalloc failed\n" );
  2485.                             break;
  2486.                           }
  2487.                           p->next = head;
  2488.                           p->value = i;
  2489.                           head = p;
  2490.                         }
  2491.                         /* traverse the linked list, printing out values */
  2492.                         for( p = head; p != 0; p = p->next ) {
  2493.                           printf( "Value = %d\n", p->value );
  2494.                         }
  2495.                         /* free all the elements of the linked list */
  2496.                         for( ; p = head; ) {
  2497.                           head = p->next;
  2498.                           _bfree( seg, p );
  2499.                         }
  2500.                         /* free the based heap */
  2501.                         _bfreeseg( seg );
  2502.                       }
  2503.  
  2504. Classification: WATCOM 
  2505.  
  2506.  
  2507. ΓòÉΓòÉΓòÉ 26. _bios_disk ΓòÉΓòÉΓòÉ
  2508.  
  2509. Synopsis: 
  2510.  
  2511.                     #include <bios.h>
  2512.                     unsigned short _bios_disk( unsigned service,
  2513.                                                struct diskinfo_t *diskinfo );
  2514.                     struct  diskinfo_t {        /* disk parameters   */
  2515.                             unsigned drive;     /* drive number      */
  2516.                             unsigned head;      /* head number       */
  2517.                             unsigned track;     /* track number      */
  2518.                             unsigned sector;    /* sector number     */
  2519.                             unsigned nsectors;  /* number of sectors */
  2520.                             void __far *buffer; /* buffer address    */
  2521.                     };
  2522.  
  2523. Description: The _bios_disk function uses INT 0x13 to provide access to the 
  2524.           BIOS disk functions.  Information for the desired service is passed 
  2525.           the diskinfo_t structure pointed to by diskinfo. The value for 
  2526.           service can be one of the following values: 
  2527.  
  2528.    Value           Meaning 
  2529.  
  2530.    _DISK_RESET     Forces the disk controller to do a reset on the disk.  This 
  2531.                    request does not use the diskinfo argument. 
  2532.  
  2533.    _DISK_STATUS    Obtains the status of the last disk operation. 
  2534.  
  2535.    _DISK_READ      Reads the specified number of sectors from the disk.  This 
  2536.                    request uses all of the information passed in the diskinfo 
  2537.                    structure. 
  2538.  
  2539.    _DISK_WRITE     Writes the specified amount of data to the disk.  This 
  2540.                    request uses all of the information passed in the diskinfo 
  2541.                    structure. 
  2542.  
  2543.    _DISK_VERIFY    Checks the disk to be sure the specified sectors exist and 
  2544.                    can be read.  A CRC (cyclic redundancy check) test is 
  2545.                    performed.  This request uses all of the information passed 
  2546.                    in the diskinfo structure except for the buffer field. 
  2547.  
  2548.    _DISK_FORMAT    Formats the specified track on the disk.  The head and track 
  2549.                    fields indicate the track to be formatted.  Only one track 
  2550.                    can be formatted per call.  The buffer field points to a set 
  2551.                    of sector markers, whose format depends on the type of disk 
  2552.                    drive.  This service has no return value. 
  2553.  
  2554. Returns:  The _bios_disk function returns status information in the high-order 
  2555.           byte when service is _DISK_STATUS, _DISK_READ, _DISK_WRITE, or 
  2556.           _DISK_VERIFY.  The possible values are: 
  2557.  
  2558.    Value     Meaning 
  2559.    0x00      Operation successful 
  2560.    0x01      Bad command 
  2561.    0x02      Address mark not found 
  2562.    0x03      Attempt to write to write-protected disk 
  2563.    0x04      Sector not found 
  2564.    0x05      Reset failed 
  2565.    0x06      Disk changed since last operation 
  2566.    0x07      Drive parameter activity failed 
  2567.    0x08      DMA overrun 
  2568.    0x09      Attempt to DMA across 64K boundary 
  2569.    0x0A      Bad sector detected 
  2570.    0x0B      Bad track detected 
  2571.    0x0C      Unsupported track 
  2572.    0x10      Data read (CRC/ECC) error 
  2573.    0x11      CRC/ECC corrected data error 
  2574.    0x20      Controller failure 
  2575.    0x40      Seek operation failed 
  2576.    0x80      Disk timed out or failed to respond 
  2577.    0xAA      Drive not ready 
  2578.    0xBB      Undefined error occurred 
  2579.    0xCC      Write fault occurred 
  2580.    0xE0      Status error 
  2581.    0xFF      Sense operation failed 
  2582.  
  2583. Example: 
  2584.  
  2585.                     #include <stdio.h>
  2586.                     #include <bios.h>
  2587.  
  2588.                     void main()
  2589.                       {
  2590.                         struct diskinfo_t di;
  2591.                         unsigned short status;
  2592.  
  2593.                         di.drive = di.head = di.track = di.sector = 0;
  2594.                         di.nsectors = 1;
  2595.                         di.buffer = NULL;
  2596.  
  2597.                         status = _bios_disk( _DISK_VERIFY, &di );
  2598.                         printf( "Status = 0x%4.4X\n", status );
  2599.                       }
  2600.  
  2601. Classification: BIOS 
  2602.  
  2603.  
  2604. ΓòÉΓòÉΓòÉ 27. _bios_equiplist ΓòÉΓòÉΓòÉ
  2605.  
  2606. Synopsis: 
  2607.  
  2608.                     #include <bios.h>
  2609.                     unsigned short _bios_equiplist( void );
  2610.  
  2611. Description: The _bios_equiplist function uses INT 0x11 to determine what 
  2612.           hardware and peripherals are installed on the machine. 
  2613.  
  2614. Returns:  The _bios_equiplist function returns a set of bits indicating what is 
  2615.           current installed on the machine.  Those bits are defined as follows: 
  2616.  
  2617.    Bit           Meaning 
  2618.    bit 0         Set to 1 if system boots from disk 
  2619.    bit 1         Set to 1 if a math coprocessor is installed 
  2620.    bits 2-3      Indicates motherboard RAM size 
  2621.    bits 4-5      Initial video mode 
  2622.    bits 6-7      Number of diskette drives 
  2623.    bit 8         Set to 1 if machine does not have DMA 
  2624.    bits 9-11     Number of serial ports 
  2625.    bit 12        Set to 1 if a game port is attached 
  2626.    bit 13        Set to 1 if a serial printer is attached 
  2627.    bits 14-15    Number of parallel printers installed 
  2628.  
  2629. Example: 
  2630.  
  2631.                     #include <stdio.h>
  2632.                     #include <bios.h>
  2633.  
  2634.                     void main()
  2635.                       {
  2636.                         unsigned short equipment;
  2637.  
  2638.                         equipment = _bios_equiplist();
  2639.                         printf( "Equipment flags = 0x%4.4X\n", equipment );
  2640.                       }
  2641.  
  2642. Classification: BIOS 
  2643.  
  2644.  
  2645. ΓòÉΓòÉΓòÉ 28. _bios_keybrd ΓòÉΓòÉΓòÉ
  2646.  
  2647. Synopsis: 
  2648.  
  2649.                     #include <bios.h>
  2650.                     unsigned short _bios_keybrd( unsigned service );
  2651.  
  2652. Description: The _bios_keybrd function uses INT 0x16 to access the BIOS 
  2653.           keyboard services.  The possible values for service are the following 
  2654.           constants: 
  2655.  
  2656.    Constant                Meaning 
  2657.  
  2658.    _KEYBRD_READ            Reads the next character from the keyboard.  The 
  2659.                            function will wait until a character has been typed. 
  2660.  
  2661.    _KEYBRD_READY           Checks to see if a character has been typed.  If 
  2662.                            there is one, then its value will be returned, but 
  2663.                            it is not removed from the input buffer. 
  2664.  
  2665.    _KEYBRD_SHIFTSTATUS     Returns the current state of special keys. 
  2666.  
  2667.    _NKEYBRD_READ           Reads the next character from an enhanced keyboard. 
  2668.                            The function will wait until a character has been 
  2669.                            typed. 
  2670.  
  2671.    _NKEYBRD_READY          Checks to see if a character has been typed on an 
  2672.                            enhanced keyboard.  If there is one, then its value 
  2673.                            will be returned, but it is not removed from the 
  2674.                            input buffer. 
  2675.  
  2676.    _NKEYBRD_SHIFTSTATUS    Returns the current state of special keys on an 
  2677.                            enhanced keyboard. 
  2678.  
  2679. Returns:  The return value depends on the service requested. 
  2680.  
  2681.           The _KEYBRD_READ and _NKEYBRD_READ services return the character's 
  2682.           ASCII value in the low-order byte and the character's keyboard scan 
  2683.           code in the high-order byte. 
  2684.  
  2685.           The _KEYBRD_READY and _NKEYBRD_READY services return zero if there 
  2686.           was no character available, otherwise it returns the same value 
  2687.           returned by _KEYBRD_READ and _NKEYBRD_READ. 
  2688.  
  2689.           The shift status is returned in the low-order byte with one bit for 
  2690.           each special key defined as follows: 
  2691.  
  2692.    Bit           Meaning 
  2693.    bit 0 (0x01)  Right SHIFT key is pressed 
  2694.    bit 1 (0x02)  Left SHIFT key is pressed 
  2695.    bit 2 (0x04)  CTRL key is pressed 
  2696.    bit 3 (0x08)  ALT key is pressed 
  2697.    bit 4 (0x10)  SCROLL LOCK is on 
  2698.    bit 5 (0x20)  NUM LOCK is on 
  2699.    bit 6 (0x40)  CAPS LOCK is on 
  2700.    bit 7 (0x80)  Insert mode is set 
  2701.  
  2702. Example: 
  2703.  
  2704.                     #include <stdio.h>
  2705.                     #include <bios.h>
  2706.  
  2707.                     void main()
  2708.                       {
  2709.                         unsigned short key_state;
  2710.  
  2711.                         key_state = _bios_keybrd( _KEYBRD_SHIFTSTATUS );
  2712.                         if( key_state & 0x10 )
  2713.                             printf( "SCROLL LOCK is on\n" );
  2714.                         if( key_state & 0x20 )
  2715.                             printf( "NUM LOCK is on\n" );
  2716.                         if( key_state & 0x40 )
  2717.                             printf( "CAPS LOCK is on\n" );
  2718.                       }
  2719.  
  2720.           produces the following: 
  2721.  
  2722.                     NUM LOCK is on
  2723.  
  2724. Classification: BIOS 
  2725.  
  2726.  
  2727. ΓòÉΓòÉΓòÉ 29. _bios_memsize ΓòÉΓòÉΓòÉ
  2728.  
  2729. Synopsis: 
  2730.  
  2731.                     #include <bios.h>
  2732.                     unsigned short _bios_memsize( void );
  2733.  
  2734. Description: The _bios_memsize function uses INT 0x12 to determine the total 
  2735.           amount of memory available. 
  2736.  
  2737. Returns:  The _bios_memsize function returns the total amount of 1K blocks of 
  2738.           memory installed (maximum 640). 
  2739.  
  2740. Example: 
  2741.  
  2742.                     #include <stdio.h>
  2743.                     #include <bios.h>
  2744.  
  2745.                     void main()
  2746.                       {
  2747.                         unsigned short memsize;
  2748.  
  2749.                         memsize = _bios_memsize();
  2750.                         printf( "The total amount of memory is: %dK\n",
  2751.                                    memsize );
  2752.                       }
  2753.  
  2754.           produces the following: 
  2755.  
  2756.                     The total amount of memory is: 640K
  2757.  
  2758. Classification: BIOS 
  2759.  
  2760.  
  2761. ΓòÉΓòÉΓòÉ 30. _bios_printer ΓòÉΓòÉΓòÉ
  2762.  
  2763. Synopsis: 
  2764.  
  2765.                     #include <bios.h>
  2766.                     unsigned short _bios_printer( unsigned service,
  2767.                                                   unsigned port,
  2768.                                                   unsigned data );
  2769.  
  2770. Description: The _bios_printer function uses INT 0x17 to perform printer output 
  2771.           services to the printer specified by port. The values for service 
  2772.           are: 
  2773.  
  2774.    Value                   Meaning 
  2775.    _PRINTER_WRITE          Sends the low-order byte of data to the printer 
  2776.                            specified by port. 
  2777.    _PRINTER_INIT           Initializes the printer specified by port. 
  2778.    _PRINTER_STATUS         Get the status of the printer specified by port. 
  2779.  
  2780. Returns:  The _bios_printer function returns a printer status byte defined as 
  2781.           follows: 
  2782.  
  2783.    Bit           Meaning 
  2784.    bit 0 (0x01)  Printer timed out 
  2785.    bits 1-2      Unused 
  2786.    bit 3 (0x08)  I/O error 
  2787.    bit 4 (0x10)  Printer selected 
  2788.    bit 5 (0x20)  Out of paper 
  2789.    bit 6 (0x40)  Printer acknowledge 
  2790.    bit 7 (0x80)  Printer not busy 
  2791.  
  2792. Example: 
  2793.  
  2794.                     #include <stdio.h>
  2795.                     #include <bios.h>
  2796.  
  2797.                     void main()
  2798.                       {
  2799.                         unsigned short status;
  2800.  
  2801.                         status = _bios_printer( _PRINTER_STATUS, 1, 0 );
  2802.                         printf( "Printer status: 0x%2.2X\n", status );
  2803.                       }
  2804.  
  2805. Classification: BIOS 
  2806.  
  2807.  
  2808. ΓòÉΓòÉΓòÉ 31. _bios_serialcom ΓòÉΓòÉΓòÉ
  2809.  
  2810. Synopsis: 
  2811.  
  2812.                     #include <bios.h>
  2813.                     unsigned short _bios_serialcom( unsigned service,
  2814.                                                     unsigned serial_port,
  2815.                                                     unsigned data );
  2816.  
  2817. Description: The _bios_serialcom function uses INT 0x14 to provide serial 
  2818.           communications services to the serial port specified by serial_port. 
  2819.           0 represents COM1, 1 represents COM2, etc.  The values for service 
  2820.           are: 
  2821.  
  2822.    Value                 Meaning 
  2823.    _COM_INIT             Initializes the serial port to the parameters 
  2824.                          specified in data. 
  2825.    _COM_SEND             Transmits the low-order byte of data to the serial 
  2826.                          port. 
  2827.    _COM_RECEIVE          Reads an input character from the serial port. 
  2828.    _COM_STATUS           Returns the current status of the serial port. 
  2829.  
  2830.           The value passed in data for the _COM_INIT service can be built using 
  2831.           the appropriate combination of the following values: 
  2832.  
  2833.    Value                 Meaning 
  2834.    _COM_110              110 baud 
  2835.    _COM_150              150 baud 
  2836.    _COM_300              300 baud 
  2837.    _COM_600              600 baud 
  2838.    _COM_1200             1200 baud 
  2839.    _COM_2400             2400 baud 
  2840.    _COM_4800             4800 baud 
  2841.    _COM_9600             9600 baud 
  2842.  
  2843.    _COM_NOPARITY         No parity 
  2844.    _COM_EVENPARITY       Even parity 
  2845.    _COM_ODDPARITY        Odd parity 
  2846.  
  2847.    _COM_CHR7             7 data bits 
  2848.    _COM_CHR8             8 data bits 
  2849.  
  2850.    _COM_STOP1            1 stop bit 
  2851.    _COM_STOP2            2 stop bits 
  2852.  
  2853. Returns:  The _bios_serialcom function returns a 16-bit value with the 
  2854.           high-order byte containing status information defined as follows: 
  2855.  
  2856.    Bit               Meaning 
  2857.    bit 15 (0x8000)   Timed out 
  2858.    bit 14 (0x4000)   Transmit shift register empty 
  2859.    bit 13 (0x2000)   Transmit holding register empty 
  2860.    bit 12 (0x1000)   Break detected 
  2861.    bit 11 (0x0800)   Framing error 
  2862.    bit 10 (0x0400)   Parity error 
  2863.    bit 9 (0x0200)    Overrun error 
  2864.    bit 8 (0x0100)    Data ready 
  2865.  
  2866.           The low-order byte of the return value depends on the value of the 
  2867.           service argument. 
  2868.  
  2869.           When service is _COM_SEND, bit 15 will be set if the data could not 
  2870.           be sent.  If bit 15 is clear, the return value equals the byte sent. 
  2871.  
  2872.           When service is _COM_RECEIVE, the byte read will be returned in the 
  2873.           low-order byte if there was no error.  If there was an error, at 
  2874.           least one of the high-order status bits will be set. 
  2875.  
  2876.           When service is _COM_INIT or _COM_STATUS the low-order bits are 
  2877.           defined as follows: 
  2878.  
  2879.    Bit               Meaning 
  2880.    bit 0 (0x01)      Clear to send (CTS) changed 
  2881.    bit 1 (0x02)      Data set ready changed 
  2882.    bit 2 (0x04)      Trailing-edge ring detector 
  2883.    bit 3 (0x08)      Receive line signal detector changed 
  2884.    bit 4 (0x10)      Clear to send 
  2885.    bit 5 (0x20)      Data-set ready 
  2886.    bit 6 (0x40)      Ring indicator 
  2887.    bit 7 (0x80)      Receive-line signal detected 
  2888.  
  2889. Example: 
  2890.  
  2891.                     #include <stdio.h>
  2892.                     #include <bios.h>
  2893.  
  2894.                     void main()
  2895.                       {
  2896.                         unsigned short status;
  2897.  
  2898.                         status = _bios_serialcom( _COM_STATUS, 1, 0 );
  2899.                         printf( "Serial status: 0x%2.2X\n", status );
  2900.                       }
  2901.  
  2902. Classification: BIOS 
  2903.  
  2904.  
  2905. ΓòÉΓòÉΓòÉ 32. _bios_timeofday ΓòÉΓòÉΓòÉ
  2906.  
  2907. Synopsis: 
  2908.  
  2909.                     #include <bios.h>
  2910.                     int _bios_timeofday( int service, long *timeval );
  2911.  
  2912. Description: The _bios_timeofday function uses INT 0x1A to get or set the 
  2913.           current system clock value.  The values for service are: 
  2914.  
  2915.    Value                 Meaning 
  2916.  
  2917.    _TIME_GETCLOCK        Places the current system clock value in the location 
  2918.                          pointed to by timeval. The function returns zero if 
  2919.                          midnight has not passed since the last time the system 
  2920.                          clock was read or set; otherwise, it returns 1. 
  2921.  
  2922.    _TIME_SETCLOCK        Sets the system clock to the value in the location 
  2923.                          pointed to by timeval. 
  2924.  
  2925. Returns:  A value of -1 is returned if neither _TIME_GETCLOCK nor 
  2926.           _TIME_SETCLOCK were specified; otherwise 0 is returned. 
  2927.  
  2928. Example: 
  2929.  
  2930.                     #include <stdio.h>
  2931.                     #include <bios.h>
  2932.  
  2933.                     void main()
  2934.                       {
  2935.                         long time_of_day;
  2936.  
  2937.                         _bios_timeofday( _TIME_GETCLOCK, &time_of_day );
  2938.                         printf( "Ticks since midnight: %lu\n", time_of_day );
  2939.                       }
  2940.  
  2941.           produces the following: 
  2942.  
  2943.                     Ticks since midnight: 762717
  2944.  
  2945. Classification: BIOS 
  2946.  
  2947.  
  2948. ΓòÉΓòÉΓòÉ 33. bsearch ΓòÉΓòÉΓòÉ
  2949.  
  2950. Synopsis: 
  2951.  
  2952.                     #include <stdlib.h>
  2953.                     void *bsearch( const void *key,
  2954.                                    const void *base,
  2955.                                    size_t num,
  2956.                                    size_t width,
  2957.                                    int (*compar)( const void *pkey,
  2958.                                                   const void *pbase) );
  2959.  
  2960. Description: The bsearch function performs a binary search of a sorted array of 
  2961.           num elements, which is pointed to by base, for an item which matches 
  2962.           the object pointed to by key. Each element in the array is width 
  2963.           bytes in size.  The comparison function pointed to by compar is 
  2964.           called with two arguments that point to elements in the array.  The 
  2965.           first argument pkey points to the same object pointed to by key. The 
  2966.           second argument pbase points to a element in the array.  The 
  2967.           comparison function shall return an integer less than, equal to, or 
  2968.           greater than zero if the key object is less than, equal to, or 
  2969.           greater than the element in the array. 
  2970.  
  2971. Returns:  The bsearch function returns a pointer to the matching member of the 
  2972.           array, or NULL if a matching object could not be found.  If there are 
  2973.           multiple values in the array which are equal to the key, the return 
  2974.           value is not necessarily the first occurrence of a matching value 
  2975.           when the array is searched linearly. 
  2976.  
  2977. See Also: lfind, lsearch, qsort 
  2978.  
  2979. Example: 
  2980.  
  2981.                     #include <stdio.h>
  2982.                     #include <stdlib.h>
  2983.                     #include <string.h>
  2984.                     static char *keywords[] = {
  2985.                             "auto",
  2986.                             "break",
  2987.                             "case",
  2988.                             "char",
  2989.                             .
  2990.                             .
  2991.                             .
  2992.                             "while"
  2993.                       };
  2994.                     #define NUM_KW  sizeof(keywords) / sizeof(char *)
  2995.                     int kw_compare( char *p1, char **p2 )
  2996.                       {
  2997.                         return( strcmp( p1, *p2 ) );
  2998.                       }
  2999.                     int keyword_lookup( char *name )
  3000.                       {
  3001.                         char **key;
  3002.                         key = bsearch( name, keywords, NUM_KW,
  3003.                                        sizeof( char * ),  kw_compare );
  3004.                         if( key == NULL ) return( -1 );
  3005.                         return key - keywords;
  3006.                       }
  3007.                     void main()
  3008.                       {
  3009.                         printf( "%d\n", keyword_lookup( "case" ) );
  3010.                         printf( "%d\n", keyword_lookup( "crigger" ) );
  3011.                         printf( "%d\n", keyword_lookup( "auto" ) );
  3012.                       }
  3013.  
  3014.           produces the following: 
  3015.  
  3016.                     2
  3017.                     -1
  3018.                     0
  3019.  
  3020. Classification: ANSI 
  3021.  
  3022.  
  3023. ΓòÉΓòÉΓòÉ 34. cabs ΓòÉΓòÉΓòÉ
  3024.  
  3025. Synopsis: 
  3026.  
  3027.                     #include <math.h>
  3028.                     double cabs( struct complex value );
  3029.  
  3030.                     struct complex {
  3031.                         double real;    /* real part */
  3032.                         double imag;    /* imaginary part */
  3033.                     };
  3034.  
  3035. Description: The cabs function computes the absolute value of the complex 
  3036.           number value by a calculation which is equivalent to 
  3037.  
  3038.                     sqrt( (value.real*value.real) + (value.imag*value.imag) )
  3039.  
  3040.           In certain cases, overflow errors may occur which will cause the 
  3041.           matherr routine to be invoked. 
  3042.  
  3043. Returns:  The absolute value is returned. 
  3044.  
  3045. Example: 
  3046.  
  3047.                     #include <stdio.h>
  3048.                     #include <math.h>
  3049.  
  3050.                     struct complex c = { -3.0, 4.0 };
  3051.  
  3052.                     void main()
  3053.                       {
  3054.                         printf( "%f\n", cabs( c ) );
  3055.                       }
  3056.  
  3057.           produces the following: 
  3058.  
  3059.                     5.000000
  3060.  
  3061. Classification: WATCOM 
  3062.  
  3063.  
  3064. ΓòÉΓòÉΓòÉ 35. calloc Functions ΓòÉΓòÉΓòÉ
  3065.  
  3066. Synopsis: 
  3067.  
  3068.                     #include <stdlib.h>  For ANSI compatibility (calloc only)
  3069.                     #include <malloc.h>  Required for other function prototypes
  3070.                     void *calloc( size_t n, size_t size );
  3071.                     void __based(void) *_bcalloc( __segment seg,
  3072.                                                   size_t n,
  3073.                                                   size_t size );
  3074.                     void __far  *_fcalloc( size_t n, size_t size );
  3075.                     void __near *_ncalloc( size_t n, size_t size );
  3076.  
  3077. Description: The calloc functions allocate space for an array of n objects, 
  3078.           each of length size bytes.  Each element is initialized to 0. 
  3079.  
  3080.           Each function allocates memory from a particular heap, as listed 
  3081.           below: 
  3082.  
  3083.    Function      Heap 
  3084.    calloc        Depends on data model of the program 
  3085.    _bcalloc      Based heap specified by seg value 
  3086.    _fcalloc      Far heap (outside the default data segment) 
  3087.    _ncalloc      Near heap (inside the default data segment) 
  3088.  
  3089.           In a small data memory model, the calloc function is equivalent to 
  3090.           the _ncalloc function; in a large data memory model, the calloc 
  3091.           function is equivalent to the _fcalloc function. 
  3092.  
  3093.           A block of memory allocated should be freed using the appropriate 
  3094.           free function. 
  3095.  
  3096. Returns:  The calloc functions return a pointer to the start of the allocated 
  3097.           memory.  The return value is NULL ( _NULLOFF for _bcalloc) if there 
  3098.           is insufficient memory available or if the value of the size argument 
  3099.           is zero. 
  3100.  
  3101. See Also: _expand Functions, free Functions, halloc, hfree, malloc Functions, 
  3102.           _msize Functions, realloc Functions, sbrk 
  3103.  
  3104. Example: 
  3105.  
  3106.                     #include <stdlib.h>
  3107.  
  3108.                     void main()
  3109.                       {
  3110.                         char *buffer;
  3111.  
  3112.                         buffer = (char *)calloc( 80, sizeof(char) );
  3113.                       }
  3114.  
  3115. Classification: calloc is ANSI; _bcalloc, _fcalloc, _ncalloc are not ANSI 
  3116.  
  3117.  
  3118. ΓòÉΓòÉΓòÉ 36. ceil ΓòÉΓòÉΓòÉ
  3119.  
  3120. Synopsis: 
  3121.  
  3122.                     #include <math.h>
  3123.                     double ceil( double x );
  3124.  
  3125. Description: The ceil function (ceiling function) computes the smallest integer 
  3126.           not less than x. 
  3127.  
  3128. Returns:  The ceil function returns the smallest integer not less than x, 
  3129.           expressed as a double. 
  3130.  
  3131. See Also: floor 
  3132.  
  3133. Example: 
  3134.  
  3135.                     #include <stdio.h>
  3136.                     #include <math.h>
  3137.  
  3138.                     void main()
  3139.                       {
  3140.                         printf( "%f %f %f %f %f\n", ceil( -2.1 ), ceil( -2. ),
  3141.                             ceil( 0.0 ), ceil( 2. ), ceil( 2.1 ) );
  3142.                       }
  3143.  
  3144.           produces the following: 
  3145.  
  3146.                     -2.000000 -2.000000 0.000000 2.000000 3.000000
  3147.  
  3148. Classification: ANSI 
  3149.  
  3150.  
  3151. ΓòÉΓòÉΓòÉ 37. cgets ΓòÉΓòÉΓòÉ
  3152.  
  3153. Synopsis: 
  3154.  
  3155.                     #include <conio.h>
  3156.                     char *cgets( char *buf );
  3157.  
  3158. Description: The cgets function gets a string of characters directly from the 
  3159.           console and stores the string and its length in the array pointed to 
  3160.           by buf. The first element of the array buf[0] must contain the 
  3161.           maximum length in characters of the string to be read.  The array 
  3162.           must be big enough to hold the string, a terminating null character, 
  3163.           and two additional bytes. 
  3164.  
  3165.           The cgets function reads characters until a carriage-return line-feed 
  3166.           combination is read, or until the specified number of characters is 
  3167.           read.  The string is stored in the array starting at buf[2]. The 
  3168.           carriage-return line-feed combination, if read, is replaced by a null 
  3169.           character.  The actual length of the string read is placed in buf[1]. 
  3170.  
  3171. Returns:  The cgets function returns a pointer to the start of the string which 
  3172.           is at buf[2]. 
  3173.  
  3174. See Also: fgets, getch, getche, gets 
  3175.  
  3176. Example: 
  3177.  
  3178.                     #include <conio.h>
  3179.  
  3180.                     void main()
  3181.                       {
  3182.                         char buffer[82];
  3183.  
  3184.                         buffer[0] = 80;
  3185.                         cgets( buffer );
  3186.                         cprintf( "%s\r\n", &buffer[2] );
  3187.                       }
  3188.  
  3189. Classification: WATCOM 
  3190.  
  3191.  
  3192. ΓòÉΓòÉΓòÉ 38. _chain_intr ΓòÉΓòÉΓòÉ
  3193.  
  3194. Synopsis: 
  3195.  
  3196.                     #include <dos.h>
  3197.                     void _chain_intr( void (__interrupt __far *func)() );
  3198.  
  3199. Description: The _chain_intr function is used at the end of an interrupt 
  3200.           routine to start executing another interrupt handler (usually the 
  3201.           previous handler for that interrupt).  When the interrupt handler 
  3202.           designated by func receives control, the stack and registers appear 
  3203.           as though the interrupt just occurred. 
  3204.  
  3205. Returns:  The _chain_intr function does not return. 
  3206.  
  3207. See Also: _dos_getvect, _dos_keep, _dos_setvect 
  3208.  
  3209. Example: 
  3210.  
  3211.                     #include <stdio.h>
  3212.                     #include <dos.h>
  3213.  
  3214.                     volatile int clock_ticks;
  3215.                     void (__interrupt __far *prev_int_1c)();
  3216.                     #define BLIP_COUNT  (5*18)  /* 5 seconds */
  3217.  
  3218.                     void __interrupt __far timer_rtn()
  3219.                       {
  3220.                         ++clock_ticks;
  3221.                         _chain_intr( prev_int_1c );
  3222.                       }
  3223.  
  3224.                     void main()
  3225.                       {
  3226.                         prev_int_1c = _dos_getvect( 0x1c );
  3227.                         _dos_setvect( 0x1c, timer_rtn );
  3228.                         while( compile_a_line() ) {
  3229.                             if( clock_ticks >= BLIP_COUNT ) {
  3230.                                 putchar( '.' );
  3231.                                 clock_ticks -= BLIP_COUNT;
  3232.                             }
  3233.                         }
  3234.                         _dos_setvect( 0x1c, prev_int_1c );
  3235.                       }
  3236.  
  3237. Classification: WATCOM 
  3238.  
  3239.  
  3240. ΓòÉΓòÉΓòÉ 39. chdir ΓòÉΓòÉΓòÉ
  3241.  
  3242. Synopsis: 
  3243.  
  3244.                     #include <sys\types.h>
  3245.                     #include <direct.h>
  3246.                     int chdir( const char *path );
  3247.  
  3248. Description: The chdir function changes the current working directory to the 
  3249.           specified path. The path can be either relative to the current 
  3250.           working directory or it can be an absolute path name. 
  3251.  
  3252. Returns:  The chdir function returns zero if successful.  Otherwise, -1 is 
  3253.           returned, errno is set to indicate the error, and the current working 
  3254.           directory remains unchanged. 
  3255.  
  3256. Errors:   When an error has occurred, errno contains a value indicating the 
  3257.           type of error that has been detected. 
  3258.  
  3259.    ENOENT    The specified path does not exist or path is an empty string. 
  3260.  
  3261. See Also: getcwd, mkdir, rmdir 
  3262.  
  3263. Example: 
  3264.  
  3265.                     #include <stdio.h>
  3266.                     #include <stdlib.h>
  3267.                     #include <direct.h>
  3268.  
  3269.                     void main( int argc, char *argv[] )
  3270.                       {
  3271.                         if( argc != 2 ) {
  3272.                           fprintf( stderr, "Use: cd <directory>\n" );
  3273.                           exit( 1 );
  3274.                         }
  3275.  
  3276.                         if( chdir( argv[1] ) == 0 ) {
  3277.                           printf( "Directory changed to %s\n", argv[1] );
  3278.                           exit( 0 );
  3279.                         } else {
  3280.                           perror( argv[1] );
  3281.                           exit( 1 );
  3282.                         }
  3283.                       }
  3284.  
  3285. Classification: POSIX 1003.1 
  3286.  
  3287.  
  3288. ΓòÉΓòÉΓòÉ 40. chmod ΓòÉΓòÉΓòÉ
  3289.  
  3290. Synopsis: 
  3291.  
  3292.                     #include <sys\types.h>
  3293.                     #include <sys\stat.h>
  3294.                     #include <io.h>
  3295.                     int chmod( const char *path, int permission );
  3296.  
  3297. Description: The chmod function changes the permissions for a file specified by 
  3298.           path to be the settings in the mode given by permission. The access 
  3299.           permissions for the file or directory are specified as a combination 
  3300.           of bits (defined in the <sys\stat.h> header file). 
  3301.  
  3302.           The following bits define permissions for the owner. 
  3303.  
  3304.    Permission    Meaning 
  3305.    S_IRWXU       Read, write, execute/search 
  3306.    S_IRUSR       Read permission 
  3307.    S_IWUSR       Write permission 
  3308.    S_IXUSR       Execute/search permission 
  3309.  
  3310.           The following bits define permissions for the group. 
  3311.  
  3312.    Permission    Meaning 
  3313.    S_IRWXG       Read, write, execute/search 
  3314.    S_IRGRP       Read permission 
  3315.    S_IWGRP       Write permission 
  3316.    S_IXGRP       Execute/search permission 
  3317.  
  3318.           The following bits define permissions for others. 
  3319.  
  3320.    Permission    Meaning 
  3321.    S_IRWXO       Read, write, execute/search 
  3322.    S_IROTH       Read permission 
  3323.    S_IWOTH       Write permission 
  3324.    S_IXOTH       Execute/search permission 
  3325.  
  3326.           The following bits define miscellaneous permissions used by other 
  3327.           implementations. 
  3328.  
  3329.    Permission    Meaning 
  3330.    S_IREAD       is equivalent to S_IRUSR (read permission) 
  3331.    S_IWRITE      is equivalent to S_IWUSR (write permission) 
  3332.    S_IEXEC       is equivalent to S_IXUSR (execute/search permission) 
  3333.  
  3334.           The following bits may also be specified in permission. 
  3335.  
  3336.    Permission    Meaning 
  3337.    S_ISUID       set user id on execution 
  3338.    S_ISGID       set group id on execution 
  3339.  
  3340.           If the calling process does not have appropriate privileges, and if 
  3341.           the group ID of the file does not match the effective group ID or one 
  3342.           of the supplementary group IDs, and if the file is a regular file, 
  3343.           bit S_ISGID (set group ID on execution) in the file's mode shall be 
  3344.           cleared upon successful return from the chmod function. 
  3345.  
  3346.           Upon successful completion, the chmod function will mark for update 
  3347.           the st_ctime  field of the file. 
  3348.  
  3349. Returns:  The chmod returns zero if the new settings are successfully made; 
  3350.           otherwise, -1 is returned and errno is set to indicate the error. 
  3351.  
  3352. Errors:   When an error has occurred, errno contains a value indicating the 
  3353.           type of error that has been detected. 
  3354.  
  3355.    Constant      Meaning 
  3356.  
  3357.    EACCES        Search permission is denied for a component of path. 
  3358.  
  3359.    ENOENT        The specified path does not exist or path is an empty string. 
  3360.  
  3361. See Also: fstat, open, sopen, stat 
  3362.  
  3363. Example: 
  3364.  
  3365.                     /*
  3366.                      * change the permissions of a list of files
  3367.                      * to be read/write by the owner only
  3368.                      */
  3369.                     #include <stdio.h>
  3370.                     #include <stdlib.h>
  3371.                     #include <sys\types.h>
  3372.                     #include <sys\stat.h>
  3373.                     #include <io.h>
  3374.                     void main( int argc, char *argv[] )
  3375.                       {
  3376.                         int i;
  3377.                         int ecode = 0;
  3378.                         for( i = 1; i < argc; i++ ) {
  3379.                           if( chmod( argv[i], S_IRUSR | S_IWUSR ) == -1 ) {
  3380.                             perror( argv[i] );
  3381.                             ecode++;
  3382.                           }
  3383.                         }
  3384.                         exit( ecode );
  3385.                       }
  3386.  
  3387. Classification: POSIX 1003.1 
  3388.  
  3389.  
  3390. ΓòÉΓòÉΓòÉ 41. chsize ΓòÉΓòÉΓòÉ
  3391.  
  3392. Synopsis: 
  3393.  
  3394.                     #include <io.h>
  3395.                     int chsize( int handle, long size );
  3396.  
  3397. Description: The chsize function changes the size of the file associated with 
  3398.           handle by extending or truncating the file to the length specified by 
  3399.           size. If the file needs to be extended, the file is padded with NULL 
  3400.           ('\0') characters. 
  3401.  
  3402. Returns:  The chsize function returns zero if successful.  A return value of -1 
  3403.           indicates an error, and errno is set to indicate the error. 
  3404.  
  3405. Errors:   When an error has occurred, errno contains a value indicating the 
  3406.           type of error that has been detected. 
  3407.  
  3408.    Constant  Meaning 
  3409.    EACCES    The specified file is locked against access. 
  3410.    EBADF     Invalid file handle. 
  3411.    ENOSPC    Not enough space left on the device to extend the file. 
  3412.  
  3413. See Also: close, creat, open 
  3414.  
  3415. Example: 
  3416.  
  3417.                     #include <stdio.h>
  3418.                     #include <io.h>
  3419.                     #include <fcntl.h>
  3420.                     #include <sys\stat.h>
  3421.  
  3422.                     void main()
  3423.                       {
  3424.                         int  handle;
  3425.                         handle = open( "file", O_RDWR | O_CREAT,
  3426.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  3427.                         if( handle != -1 ) {
  3428.                           if( chsize( handle, 32 * 1024L ) != 0 ) {
  3429.                               printf( "Error extending file\n" );
  3430.                           }
  3431.                           close( handle );
  3432.                         }
  3433.                       }
  3434.  
  3435. Classification: WATCOM 
  3436.  
  3437.  
  3438. ΓòÉΓòÉΓòÉ 42. _clear87 ΓòÉΓòÉΓòÉ
  3439.  
  3440. Synopsis: 
  3441.  
  3442.                     #include <float.h>
  3443.                     unsigned int _clear87( void );
  3444.  
  3445. Description: The _clear87  function clears the floating-point status word which 
  3446.           is used to record the status of 8087/80287/80387/80486 floating-point 
  3447.           operations. 
  3448.  
  3449. Returns:  The _clear87  function returns the old floating-point status.  The 
  3450.           description of this status is found in the <float.h> header file. 
  3451.  
  3452. See Also: _control87, _fpreset, _status87 
  3453.  
  3454. Example: 
  3455.  
  3456.                     #include <stdio.h>
  3457.                     #include <float.h>
  3458.                     void main()
  3459.                       {
  3460.                         unsigned int fp_status;
  3461.                         fp_status = _clear87();
  3462.                         printf( "80x87 status =" );
  3463.                         if( fp_status & SW_INVALID )
  3464.                             printf( " invalid" );
  3465.                         if( fp_status & SW_DENORMAL )
  3466.                             printf( " denormal" );
  3467.                         if( fp_status & SW_ZERODIVIDE )
  3468.                             printf( " zero_divide" );
  3469.                         if( fp_status & SW_OVERFLOW )
  3470.                             printf( " overflow" );
  3471.                         if( fp_status & SW_UNDERFLOW )
  3472.                             printf( " underflow" );
  3473.                         if( fp_status & SW_INEXACT )
  3474.                             printf( " inexact_result" );
  3475.                         printf( "\n" );
  3476.                       }
  3477.  
  3478. Classification: Intel 
  3479.  
  3480.  
  3481. ΓòÉΓòÉΓòÉ 43. clearenv ΓòÉΓòÉΓòÉ
  3482.  
  3483. Synopsis: 
  3484.  
  3485.                     #include <env.h>
  3486.                     int clearenv( void );
  3487.  
  3488. Description: The clearenv  function clears the process environment area. No 
  3489.           environment variables are defined immediately after a call to the 
  3490.           clearenv  function.  Note that this clears the PATH, COMSPEC, and TZ 
  3491.           environment variables which may then affect the operation of other 
  3492.           library functions. 
  3493.  
  3494.           The clearenv  function may manipulate the value of the pointer 
  3495.           environ. 
  3496.  
  3497. Returns:  The clearenv  function returns zero upon successful completion. 
  3498.           Otherwise, it will return a non-zero value and set errno  to indicate 
  3499.           the error. 
  3500.  
  3501. Errors:   When an error has occurred, errno  contains a value indicating the 
  3502.           type of error that has been detected. 
  3503.  
  3504.    ENOMEM    Not enough memory to allocate a control structure. 
  3505.  
  3506. See Also: exec Functions, getenv, putenv, setenv, spawn Functions, system 
  3507.  
  3508. Example: 
  3509.  
  3510.           The following example clears the entire environment area and sets up 
  3511.           a new TZ environment variable. 
  3512.  
  3513.                     #include <env.h>
  3514.  
  3515.                     void main()
  3516.                       {
  3517.                         clearenv();
  3518.                         setenv( "TZ", "EST5DST", 0 );
  3519.                       }
  3520.  
  3521. Classification: POSIX 1003.1 
  3522.  
  3523.  
  3524. ΓòÉΓòÉΓòÉ 44. clearerr ΓòÉΓòÉΓòÉ
  3525.  
  3526. Synopsis: 
  3527.  
  3528.                     #include <stdio.h>
  3529.                     void clearerr( FILE *fp );
  3530.  
  3531. Description: The clearerr  function clears the end-of-file and error indicators 
  3532.           for the stream pointed to by fp. These indicators are cleared only 
  3533.           when the file is opened or by an explicit call to the clearerr  or 
  3534.           rewind  functions. 
  3535.  
  3536. Returns:  The clearerr  function returns no value. 
  3537.  
  3538. See Also: feof, ferror, perror 
  3539.  
  3540. Example: 
  3541.  
  3542.                     #include <stdio.h>
  3543.  
  3544.                     void main()
  3545.                       {
  3546.                         FILE *fp;
  3547.                         int c;
  3548.  
  3549.                         c = 'J';
  3550.                         fp = fopen( "file", "w" );
  3551.                         if( fp != NULL ) {
  3552.                           fputc( c, fp );
  3553.                           if( ferror( fp ) ) {  /* if error        */
  3554.                               clearerr( fp );   /* clear the error */
  3555.                               fputc( c, fp );   /* and retry it    */
  3556.                           }
  3557.                         }
  3558.                       }
  3559.  
  3560. Classification: ANSI 
  3561.  
  3562.  
  3563. ΓòÉΓòÉΓòÉ 45. clock ΓòÉΓòÉΓòÉ
  3564.  
  3565. Synopsis: 
  3566.  
  3567.                     #include <time.h>
  3568.                     clock_t clock(void);
  3569.  
  3570. Description: The clock  function returns the number of clock ticks of processor 
  3571.           time used by program since the program started executing.  This can 
  3572.           be converted to seconds by dividing by the value of the macro 
  3573.           CLOCKS_PER_SEC. 
  3574.  
  3575. Returns:  The clock  function returns the number of clock ticks that have 
  3576.           occurred since the program started executing. 
  3577.  
  3578. See Also: asctime, ctime, difftime, gmtime, localtime, mktime, strftime, time, 
  3579.           tzset 
  3580.  
  3581. Example: 
  3582.  
  3583.                     #include <stdio.h>
  3584.                     #include <math.h>
  3585.                     #include <time.h>
  3586.  
  3587.                     void main()
  3588.                       {
  3589.                         clock_t start_time, end_time;
  3590.  
  3591.                         start_time = clock();
  3592.                         compute();
  3593.                         end_time = clock();
  3594.                         printf( "Execution time was %lu seconds\n",
  3595.                               (end_time - start_time) / CLOCKS_PER_SEC );
  3596.                       }
  3597.                     void compute( void )
  3598.                       {
  3599.                         int i, j;
  3600.                         double x;
  3601.  
  3602.                         x = 0.0;
  3603.                         for( i = 1; i <= 100; i++ )
  3604.                           for( j = 1; j <= 100; j++ )
  3605.                             x += sqrt( (double) i * j );
  3606.                         printf( "%16.7f\n", x );
  3607.                       }
  3608.  
  3609. Classification: ANSI 
  3610.  
  3611.  
  3612. ΓòÉΓòÉΓòÉ 46. close ΓòÉΓòÉΓòÉ
  3613.  
  3614. Synopsis: 
  3615.  
  3616.                     #include <io.h>
  3617.                     int close( int handle );
  3618.  
  3619. Description: The close  function closes a file at the operating system level. 
  3620.           The handle value is the file handle returned by a successful 
  3621.           execution of one of the creat, dup, dup2, open  or sopen  functions. 
  3622.  
  3623. Returns:  The close  function returns zero if successful.  Otherwise, it 
  3624.           returns -1 and errno  is set to indicate the error. 
  3625.  
  3626. Errors:   When an error has occurred, errno  contains a value indicating the 
  3627.           type of error that has been detected. 
  3628.  
  3629.    EBADF     The handle argument is not a valid file handle. 
  3630.  
  3631. See Also: creat, dup, dup2, open, sopen 
  3632.  
  3633. Example: 
  3634.  
  3635.                     #include <fcntl.h>
  3636.                     #include <io.h>
  3637.  
  3638.                     void main()
  3639.                       {
  3640.                         int handle;
  3641.  
  3642.                         handle = open( "file", O_RDONLY );
  3643.                         if( handle != -1 ) {
  3644.  
  3645.                           /* process file */
  3646.  
  3647.                           close( handle );
  3648.                         }
  3649.                       }
  3650.  
  3651. Classification: POSIX 1003.1 
  3652.  
  3653.  
  3654. ΓòÉΓòÉΓòÉ 47. closedir ΓòÉΓòÉΓòÉ
  3655.  
  3656. Synopsis: 
  3657.  
  3658.                     #include <direct.h>
  3659.                     int closedir( DIR *dirp );
  3660.  
  3661. Description: The closedir  function closes the directory specified by dirp and 
  3662.           frees the memory allocated by opendir. 
  3663.  
  3664. Returns:  The closedir  function returns zero if successful, non-zero 
  3665.           otherwise. 
  3666.  
  3667. Errors:   When an error has occurred, errno  contains a value indicating the 
  3668.           type of error that has been detected. 
  3669.  
  3670.    EBADF     The argument dirp does not refer to an open directory stream. 
  3671.  
  3672. See Also: opendir, readdir 
  3673.  
  3674. Example: 
  3675.  
  3676.           To get a list of files contained in the directory \watcom\h on your 
  3677.           default disk: 
  3678.  
  3679.                     #include <stdio.h>
  3680.                     #include <direct.h>
  3681.                     void main()
  3682.                       {
  3683.                         DIR *dirp;
  3684.                         struct dirent *direntp;
  3685.                         dirp = opendir( "\\watcom\\h" );
  3686.  
  3687.  
  3688.                         if( dirp != NULL ) {
  3689.                           for(;;) {
  3690.                             direntp = readdir( dirp );
  3691.                             if( direntp == NULL ) break;
  3692.                             printf( "%s\n", direntp->d_name );
  3693.                           }
  3694.                           closedir( dirp );
  3695.                         }
  3696.                       }
  3697.  
  3698.           Note the use of two adjacent backslash characters (\) within 
  3699.           character-string constants to signify a single backslash. 
  3700.  
  3701. Classification: POSIX 1003.1 
  3702.  
  3703.  
  3704. ΓòÉΓòÉΓòÉ 48. _control87 ΓòÉΓòÉΓòÉ
  3705.  
  3706. Synopsis: 
  3707.  
  3708.                     #include <float.h>
  3709.                     unsigned int _control87( unsigned int newcw,
  3710.                                              unsigned int mask );
  3711.  
  3712. Description: The _control87  function updates the control word of the 
  3713.           8087/80287/80387/80486.  If mask is zero, then the control word is 
  3714.           not updated.  If mask is non-zero, then the control word is updated 
  3715.           with bits from newcw corresponding to every bit that is on in mask. 
  3716.  
  3717. Returns:  The _control87  function returns the new control word.  The 
  3718.           description of bits defined for the control word is found in the 
  3719.           <float.h> header file. 
  3720.  
  3721. See Also: _clear87, _fpreset, _status87 
  3722.  
  3723. Example: 
  3724.  
  3725.                     #include <stdio.h>
  3726.                     #include <float.h>
  3727.  
  3728.                     char *status[2] = { "disabled", "enabled" };
  3729.  
  3730.                     void main()
  3731.                       {
  3732.                         unsigned int fp_cw = 0;
  3733.                         unsigned int fp_mask = 0;
  3734.                         unsigned int bits;
  3735.                         fp_cw = _control87( fp_cw,
  3736.                                             fp_mask );
  3737.                         printf( "Interrupt Exception Masks\n" );
  3738.                         bits = fp_cw & MCW_EM;
  3739.                         printf( "  Invalid Operation exception %s\n",
  3740.                                 status[ (bits & EM_INVALID) == 0 ] );
  3741.                         printf( "  Denormalized exception %s\n",
  3742.                                 status[ (bits & EM_DENORMAL) == 0 ] );
  3743.                         printf( "  Divide-By-Zero exception %s\n",
  3744.                                 status[ (bits & EM_ZERODIVIDE) == 0 ] );
  3745.                         printf( "  Overflow exception %s\n",
  3746.                                 status[ (bits & EM_OVERFLOW) == 0 ] );
  3747.                         printf( "  Underflow exception %s\n",
  3748.                                 status[ (bits & EM_UNDERFLOW) == 0 ] );
  3749.                         printf( "  Precision exception %s\n",
  3750.                                 status[ (bits & EM_PRECISION) == 0 ] );
  3751.                         printf( "Infinity Control = " );
  3752.                         bits = fp_cw & MCW_IC;
  3753.                         if( bits == IC_AFFINE )     printf( "affine\n" );
  3754.                         if( bits == IC_PROJECTIVE ) printf( "projective\n" );
  3755.                         printf( "Rounding Control = " );
  3756.                         bits = fp_cw & MCW_RC;
  3757.                         if( bits == RC_NEAR )       printf( "near\n" );
  3758.                         if( bits == RC_DOWN )       printf( "down\n" );
  3759.                         if( bits == RC_UP )         printf( "up\n" );
  3760.                         if( bits == RC_CHOP )       printf( "chop\n" );
  3761.                         printf( "Precision Control = " );
  3762.                         bits = fp_cw & MCW_PC;
  3763.                         if( bits == PC_24 )         printf( "24 bits\n" );
  3764.                         if( bits == PC_53 )         printf( "53 bits\n" );
  3765.                         if( bits == PC_64 )         printf( "64 bits\n" );
  3766.                       }
  3767.  
  3768. Classification: Intel 
  3769.  
  3770.  
  3771. ΓòÉΓòÉΓòÉ 49. cos ΓòÉΓòÉΓòÉ
  3772.  
  3773. Synopsis: 
  3774.  
  3775.                     #include <math.h>
  3776.                     double cos( double x );
  3777.  
  3778. Description: The cos  function computes the cosine of x (measured in radians). 
  3779.           A large magnitude argument may yield a result with little or no 
  3780.           significance. 
  3781.  
  3782. Returns:  The cos  function returns the cosine value. 
  3783.  
  3784. See Also: acos, sin, tan 
  3785.  
  3786. Example: 
  3787.  
  3788.                     #include <math.h>
  3789.  
  3790.                     void main()
  3791.                       {
  3792.                         double value;
  3793.                         value = cos( 3.1415278 );
  3794.                       }
  3795.  
  3796. Classification: ANSI 
  3797.  
  3798.  
  3799. ΓòÉΓòÉΓòÉ 50. cosh ΓòÉΓòÉΓòÉ
  3800.  
  3801. Synopsis: 
  3802.  
  3803.                     #include <math.h>
  3804.                     double cosh( double x );
  3805.  
  3806. Description: The cosh  function computes the hyperbolic cosine of x. A range 
  3807.           error occurs if the magnitude of x is too large. 
  3808.  
  3809. Returns:  The cosh  function returns the hyperbolic cosine value. When the 
  3810.           argument is outside the permissible range, the matherr function is 
  3811.           called.  Unless the default matherr  function is replaced, it will 
  3812.           set the global variable errno  to ERANGE, and print a "RANGE error" 
  3813.           diagnostic message using the stderr  stream. 
  3814.  
  3815. See Also: sinh, tanh, matherr 
  3816.  
  3817. Example: 
  3818.  
  3819.                     #include <stdio.h>
  3820.                     #include <math.h>
  3821.  
  3822.                     void main()
  3823.                       {
  3824.                         printf( "%f\n", cosh(.5) );
  3825.                       }
  3826.  
  3827.           produces the following: 
  3828.  
  3829.                     1.127626
  3830.  
  3831. Classification: ANSI 
  3832.  
  3833.  
  3834. ΓòÉΓòÉΓòÉ 51. cprintf ΓòÉΓòÉΓòÉ
  3835.  
  3836. Synopsis: 
  3837.  
  3838.                     #include <conio.h>
  3839.                     int cprintf( const char *format, ... );
  3840.  
  3841. Description: The cprintf  function writes output directly to the console under 
  3842.           control of the argument format. The putch  function is used to output 
  3843.           characters to the console. The format string is described under the 
  3844.           description of the printf function. 
  3845.  
  3846. Returns:  The cprintf  function returns the number of characters written. 
  3847.  
  3848. See Also: fprintf, printf, sprintf, vfprintf, vprintf, vsprintf 
  3849.  
  3850. Example: 
  3851.  
  3852.                     #include <conio.h>
  3853.  
  3854.                     void main()
  3855.                       {
  3856.                         char *weekday, *month;
  3857.                         int day, year;
  3858.  
  3859.                         weekday = "Saturday";
  3860.                         month = "April";
  3861.                         day = 18;
  3862.                         year = 1987;
  3863.                         cprintf( "%s, %s %d, %d\n",
  3864.                               weekday, month, day, year );
  3865.                       }
  3866.  
  3867.           produces the following: 
  3868.  
  3869.                     Saturday, April 18, 1987
  3870.  
  3871. Classification: WATCOM 
  3872.  
  3873.  
  3874. ΓòÉΓòÉΓòÉ 52. cputs ΓòÉΓòÉΓòÉ
  3875.  
  3876. Synopsis: 
  3877.  
  3878.                     #include <conio.h>
  3879.                     int cputs( const char *buf );
  3880.  
  3881. Description: The cputs  function writes the character string pointed to by buf 
  3882.           directly to the console using the putch  function.  Unlike the puts 
  3883.           function, the carriage-return and line-feed characters are not 
  3884.           appended to the string.  The terminating null character is not 
  3885.           written. 
  3886.  
  3887. Returns:  The cputs  function returns a non-zero value if an error occurs; 
  3888.           otherwise, it returns zero.  When an error has occurred, errno 
  3889.           contains a value indicating the type of error that has been detected. 
  3890.  
  3891. See Also: fputs, putch, puts 
  3892.  
  3893. Example: 
  3894.  
  3895.                     #include <conio.h>
  3896.  
  3897.                     void main()
  3898.                       {
  3899.                         char buffer[82];
  3900.  
  3901.                         buffer[0] = 80;
  3902.                         cgets( buffer );
  3903.                         cputs( &buffer[2] );
  3904.                         putch( '\r' );
  3905.                         putch( '\n' );
  3906.                       }
  3907.  
  3908. Classification: WATCOM 
  3909.  
  3910.  
  3911. ΓòÉΓòÉΓòÉ 53. creat ΓòÉΓòÉΓòÉ
  3912.  
  3913. Synopsis: 
  3914.  
  3915.                     #include <sys\types.h>
  3916.                     #include <sys\stat.h>
  3917.                     #include <io.h>
  3918.                     int creat( const char *path, int mode );
  3919.  
  3920. Description: The creat  function creates (and opens) a file at the operating 
  3921.           system level.  It is equivalent to: 
  3922.  
  3923.                     open( path, O_WRONLY | O_CREAT | O_TRUNC, mode );
  3924.  
  3925.           The name of the file to be created is given by path. When the file 
  3926.           exists (it must be writeable), it is truncated to contain no data and 
  3927.           the preceding mode setting is unchanged. 
  3928.  
  3929.           When the file does not exist, it is created with access permissions 
  3930.           given by the mode argument.  The access permissions for the file or 
  3931.           directory are specified as a combination of bits (defined in the 
  3932.           <sys\stat.h> header file). 
  3933.  
  3934.           The following bits define permissions for the owner. 
  3935.  
  3936.    Permission    Meaning 
  3937.    S_IRWXU       Read, write, execute/search 
  3938.    S_IRUSR       Read permission 
  3939.    S_IWUSR       Write permission 
  3940.    S_IXUSR       Execute/search permission 
  3941.  
  3942.           The following bits define permissions for the group. 
  3943.  
  3944.    Permission    Meaning 
  3945.    S_IRWXG       Read, write, execute/search 
  3946.    S_IRGRP       Read permission 
  3947.    S_IWGRP       Write permission 
  3948.    S_IXGRP       Execute/search permission 
  3949.  
  3950.           The following bits define permissions for others. 
  3951.  
  3952.    Permission    Meaning 
  3953.    S_IRWXO       Read, write, execute/search 
  3954.    S_IROTH       Read permission 
  3955.    S_IWOTH       Write permission 
  3956.    S_IXOTH       Execute/search permission 
  3957.  
  3958.           The following bits define miscellaneous permissions used by other 
  3959.           implementations. 
  3960.  
  3961.    Permission    Meaning 
  3962.    S_IREAD       is equivalent to S_IRUSR (read permission) 
  3963.    S_IWRITE      is equivalent to S_IWUSR (write permission) 
  3964.    S_IEXEC       is equivalent to S_IXUSR (execute/search permission) 
  3965.  
  3966.           All files are readable with DOS; however, it is a good idea to set 
  3967.           S_IREAD when read permission is intended for the file. 
  3968.  
  3969. Returns:  If successful, creat  returns a handle for the file.  When an error 
  3970.           occurs while opening the file, -1 is returned, and errno is set to 
  3971.           indicate the error. 
  3972.  
  3973. Errors:   When an error has occurred, errno  contains a value indicating the 
  3974.           type of error that has been detected. 
  3975.  
  3976.    Constant      Meaning 
  3977.  
  3978.    EACCES        Access denied because path specifies a directory or a volume 
  3979.                  ID, or a read-only file. 
  3980.  
  3981.    EMFILE        No more handles available (too many open files). 
  3982.  
  3983.    ENOENT        The specified path does not exist or path is an empty string. 
  3984.  
  3985. See Also: close, dup, dup2, eof, exec Functions, filelength, fileno, fstat, 
  3986.           isatty, lseek, open, read, setmode, sopen, stat, tell, write, umask 
  3987.  
  3988. Example: 
  3989.  
  3990.                     #include <sys\types.h>
  3991.                     #include <sys\stat.h>
  3992.                     #include <io.h>
  3993.  
  3994.                     void main()
  3995.                       {
  3996.                         int handle;
  3997.  
  3998.                         handle = creat( "file", S_IWRITE | S_IREAD );
  3999.                         if( handle != -1 ) {
  4000.  
  4001.                           /* process file */
  4002.  
  4003.                           close( handle );
  4004.                         }
  4005.                       }
  4006.  
  4007. Classification: POSIX 1003.1 
  4008.  
  4009.  
  4010. ΓòÉΓòÉΓòÉ 54. cscanf ΓòÉΓòÉΓòÉ
  4011.  
  4012. Synopsis: 
  4013.  
  4014.                     #include <conio.h>
  4015.                     int cscanf( const char *format, ... );
  4016.  
  4017. Description: The cscanf  function scans input from the console under control of 
  4018.           the argument format. Following the format string is a list of 
  4019.           addresses to receive values.  The cscanf  function uses the function 
  4020.           getche  to read characters from the console.  The format string is 
  4021.           described under the description of the scanf  function. 
  4022.  
  4023. Returns:  The cscanf  function returns EOF  when the scanning is terminated by 
  4024.           reaching the end of the input stream.  Otherwise, the number of input 
  4025.           arguments for which values were successfully scanned and stored is 
  4026.           returned.  When a file input error occurs, the errno global variable 
  4027.           may be set. 
  4028.  
  4029. See Also: fscanf, scanf, sscanf 
  4030.  
  4031. Example: 
  4032.  
  4033.           To scan a date in the form "Saturday April 18 1987": 
  4034.  
  4035.                     #include <conio.h>
  4036.  
  4037.                     void main()
  4038.                       {
  4039.                         int day, year;
  4040.                         char weekday[10], month[12];
  4041.  
  4042.                         cscanf( "%s %s %d %d",
  4043.                             weekday, month, &day, &year );
  4044.                       }
  4045.  
  4046.  
  4047. Classification: WATCOM 
  4048.  
  4049.  
  4050. ΓòÉΓòÉΓòÉ 55. ctime, _ctime ΓòÉΓòÉΓòÉ
  4051.  
  4052. Synopsis: 
  4053.  
  4054.                     #include <time.h>
  4055.                     char * ctime( const time_t *timer );
  4056.                     char *_ctime( const time_t *timer, char *buf );
  4057.  
  4058. Description: The ctime  functions convert the calendar time pointed to by timer 
  4059.           to local time in the form of a string.  The ctime  function is 
  4060.           equivalent to 
  4061.  
  4062.                     asctime( localtime( timer ) )
  4063.  
  4064.           The ctime  functions convert the time into a string containing 
  4065.           exactly 26 characters.  This string has the form shown in the 
  4066.           following example: 
  4067.  
  4068.                     Sat Mar 21 15:58:27 1987\n\0
  4069.  
  4070.           All fields have a constant width.  The new-line character '\n' and 
  4071.           the null character '\0' occupy the last two positions of the string. 
  4072.  
  4073.           The function _ctime  places the result string in the buffer pointed 
  4074.           to by buf, and the function ctime  places the result string in a 
  4075.           static buffer that is re-used each time ctime  is called. 
  4076.  
  4077.           Whenever ctime  is called, the tzset  function is also called. 
  4078.  
  4079.           The calendar time is usually obtained by using the time function. 
  4080.           That time is Coordinated Universal Time (UTC) (formerly known as 
  4081.           Greenwich Mean Time (GMT)). 
  4082.  
  4083.           The time set on the computer with the DOS time command and the DOS 
  4084.           date command reflects the local time.  The environment variable TZ is 
  4085.           used to establish the time zone to which this local time applies. 
  4086.           See the section The TZ Environment Variable  for a discussion of how 
  4087.           to set the time zone. 
  4088.  
  4089. Returns:  The ctime  functions return the pointer to the string containing the 
  4090.           local time. 
  4091.  
  4092. See Also: asctime, clock, difftime, gmtime, localtime, mktime, strftime, time, 
  4093.           tzset 
  4094.  
  4095. Example: 
  4096.  
  4097.                     #include <stdio.h>
  4098.                     #include <time.h>
  4099.  
  4100.                     void main()
  4101.                       {
  4102.                         time_t time_of_day;
  4103.                         auto char buf[26];
  4104.  
  4105.                         time_of_day = time( NULL );
  4106.                         printf( "It is now: %s", _ctime( &time_of_day, buf ) );
  4107.                       }
  4108.  
  4109.           produces the following: 
  4110.  
  4111.                     It is now: Fri Dec 25 15:58:42 1987
  4112.  
  4113. Classification: ctime is ANSI, _ctime is not ANSI 
  4114.  
  4115.  
  4116. ΓòÉΓòÉΓòÉ 56. cwait ΓòÉΓòÉΓòÉ
  4117.  
  4118. Synopsis: 
  4119.  
  4120.                     #include <process.h>
  4121.                     int cwait( int *status, int process_id, int action );
  4122.  
  4123. Description: The cwait  function suspends the calling process until the 
  4124.           specified child process terminates. 
  4125.  
  4126.           If status is not NULL, it points to a word that will be filled in 
  4127.           with the termination status word and return code of the terminated 
  4128.           child process. 
  4129.  
  4130.           If the child process terminated normally, then the low order byte of 
  4131.           the status word will be set to 0, and the high order byte will 
  4132.           contain the low order byte of the return code that the child process 
  4133.           passed to the DOSEXIT  function.  The DOSEXIT  function is called 
  4134.           whenever main  returns, or exit  or _exit are explicity called. 
  4135.  
  4136.           If the child process did not terminate normally, then the high order 
  4137.           byte of the status word will be set to 0, and the low order byte will 
  4138.           contain one of the following values: 
  4139.  
  4140.    Value     Meaning 
  4141.    1         Hard-error abort 
  4142.    2         Trap operation 
  4143.    3         SIGTERM signal not intercepted 
  4144.  
  4145.           The process_id argument specifies which child process to wait for. 
  4146.           This value is returned by the call to the spawn  function that 
  4147.           started the child process. 
  4148.  
  4149.           The action argument specifies when the parent process resumes 
  4150.           execution.  The possible values are: 
  4151.  
  4152.    Value               Meaning 
  4153.  
  4154.    WAIT_CHILD          Wait until the specified child process has ended. 
  4155.  
  4156.    WAIT_GRANDCHILD     Wait until the specified child process and all of the 
  4157.                        child processes of that child process have ended. 
  4158.  
  4159. Returns:  The cwait  function returns the child's process id if the child 
  4160.           process terminated normally.  Otherwise, cwait  returns -1 and sets 
  4161.           errno  to one of the following values: 
  4162.  
  4163.    Constant      Meaning 
  4164.    EINVAL        Invalid action code 
  4165.    ECHILD        Invalid process id, or the child does not exist. 
  4166.    EINTR         The child process terminated abnormally. 
  4167.  
  4168. See Also: exit, _exit, spawn Functions, wait 
  4169.  
  4170. Example: 
  4171.  
  4172.                     #include <stdio.h>
  4173.                     #include <process.h>
  4174.  
  4175.                     void main()
  4176.                       {
  4177.                          int   process_id;
  4178.                          int   status;
  4179.  
  4180.                          process_id = spawnl( P_NOWAIT, "child.exe",
  4181.                                     "child", "parm", NULL );
  4182.                          cwait( &status, process_id, WAIT_CHILD );
  4183.                       }
  4184.  
  4185. Classification: OS/2 
  4186.  
  4187.  
  4188. ΓòÉΓòÉΓòÉ 57. delay ΓòÉΓòÉΓòÉ
  4189.  
  4190. Synopsis: 
  4191.  
  4192.                     #include <dos.h>
  4193.                     void delay( unsigned milliseconds );
  4194.  
  4195. Description: The delay  function suspends execution by the specified number of 
  4196.           milliseconds. 
  4197.  
  4198. Returns:  The delay  function has no return value. 
  4199.  
  4200. See Also: sleep 
  4201.  
  4202. Example: 
  4203.  
  4204.                     #include <dos.h>
  4205.  
  4206.                     void main()
  4207.                       {
  4208.                         sound( 200 );
  4209.                         delay( 500 );  /* delay for 1/2 second */
  4210.                         nosound();
  4211.                       }
  4212.  
  4213. Classification: WATCOM 
  4214.  
  4215.  
  4216. ΓòÉΓòÉΓòÉ 58. difftime ΓòÉΓòÉΓòÉ
  4217.  
  4218. Synopsis: 
  4219.  
  4220.                     #include <time.h>
  4221.                     double difftime( time_t time1, time_t time0 );
  4222.  
  4223. Description: The difftime  function calculates the difference between the two 
  4224.           calendar times: 
  4225.  
  4226.                         time1 - time0
  4227.  
  4228. Returns:  The difftime  function returns the difference between the two times 
  4229.           in seconds as a double. 
  4230.  
  4231. See Also: asctime, clock, ctime, gmtime, localtime, mktime, strftime, time, 
  4232.           tzset 
  4233.  
  4234. Example: 
  4235.  
  4236.                     #include <stdio.h>
  4237.                     #include <time.h>
  4238.  
  4239.                     void compute( void );
  4240.  
  4241.                     void main()
  4242.                       {
  4243.                         time_t start_time, end_time;
  4244.  
  4245.                         start_time = time( NULL );
  4246.                         compute();
  4247.                         end_time = time( NULL );
  4248.                         printf( "Elapsed time: %f seconds",
  4249.                             difftime( end_time, start_time ) );
  4250.                       }
  4251.  
  4252.                     void compute( void )
  4253.                       {
  4254.                         int i, j;
  4255.  
  4256.                         for( i = 1; i <= 20; i++ ) {
  4257.                           for( j = 1; j <= 20; j++ )
  4258.                             printf( "%3d ", i * j );
  4259.                           printf( "\n" );
  4260.                         }
  4261.                       }
  4262.  
  4263. Classification: ANSI 
  4264.  
  4265.  
  4266. ΓòÉΓòÉΓòÉ 59. _disable ΓòÉΓòÉΓòÉ
  4267.  
  4268. Synopsis: 
  4269.  
  4270.                     #include <dos.h>
  4271.                     void _disable( void );
  4272.  
  4273. Description: The _disable  function causes interrupts to become disabled. 
  4274.  
  4275.           The _disable  function would be used in conjunction with the _enable 
  4276.           function to make sure that a sequence of instructions are executed 
  4277.           without any intervening interrupts occurring. 
  4278.  
  4279. Returns:  The _disable  function returns no value. 
  4280.  
  4281. See Also: _enable 
  4282.  
  4283. Example: 
  4284.  
  4285.                     #include <stdio.h>
  4286.                     #include <stdlib.h>
  4287.                     #include <dos.h>
  4288.                     struct list_entry {
  4289.                         struct list_entry *next;
  4290.                         int    data;
  4291.                     };
  4292.                     struct list_entry *ListHead = NULL;
  4293.                     struct list_entry *ListTail = NULL;
  4294.                     void main()
  4295.                       {
  4296.                         struct list_entry *p;
  4297.                         int i;
  4298.  
  4299.                         for( i = 1; i <= 10; i++ ) {
  4300.                           p = malloc( sizeof( struct list_entry ) );
  4301.                           if( p == NULL ) break;
  4302.                           p->data = i;
  4303.                           insert( p );
  4304.                         }
  4305.                       }
  4306.                     void insert( struct list_entry *new_entry )
  4307.                       {
  4308.                         /* insert new_entry at end of linked list */
  4309.                         new_entry->next = NULL;
  4310.                         _disable();       /* disable interrupts */
  4311.                         if( ListTail == NULL ) {
  4312.                           ListHead = new_entry;
  4313.                         } else {
  4314.                           ListTail->next = new_entry;
  4315.                         }
  4316.                         ListTail = new_entry;
  4317.                         _enable();        /* enable interrupts now */
  4318.                       }
  4319.  
  4320. Classification: Intel 
  4321.  
  4322.  
  4323. ΓòÉΓòÉΓòÉ 60. div ΓòÉΓòÉΓòÉ
  4324.  
  4325. Synopsis: 
  4326.  
  4327.                     #include <stdlib.h>
  4328.                     div_t div( int numer, int denom );
  4329.  
  4330.                     typedef struct {
  4331.                         int quot;     /* quotient */
  4332.                         int rem;      /* remainder */
  4333.                     } div_t;
  4334.  
  4335. Description: The div  function calculates the quotient and remainder of the 
  4336.           division of the numerator numer by the denominator denom. 
  4337.  
  4338. Returns:  The div  function returns a structure of type div_t  which contains 
  4339.           the fields quot  and rem. 
  4340.  
  4341. See Also: ldiv 
  4342.  
  4343. Example: 
  4344.  
  4345.                     #include <stdio.h>
  4346.                     #include <stdlib.h>
  4347.  
  4348.                     void main()
  4349.                       {
  4350.                         print_time( 130 );
  4351.                       }
  4352.  
  4353.                     void print_time( int seconds )
  4354.                       {
  4355.                          auto div_t min_sec;
  4356.  
  4357.                          min_sec = div( seconds, 60 );
  4358.                          printf( "It took %d minutes and %d seconds\n",
  4359.                                   min_sec.quot, min_sec.rem );
  4360.                       }
  4361.  
  4362.           produces the following: 
  4363.  
  4364.                     It took 2 minutes and 10 seconds
  4365.  
  4366. Classification: ANSI 
  4367.  
  4368.  
  4369. ΓòÉΓòÉΓòÉ 61. _dos_allocmem ΓòÉΓòÉΓòÉ
  4370.  
  4371. Synopsis: 
  4372.  
  4373.                     #include <dos.h>
  4374.                     unsigned _dos_allocmem( unsigned size,
  4375.                                             unsigned short *segment);
  4376.  
  4377. Description: The _dos_allocmem  function uses system call 0x48 to allocate size 
  4378.           paragraphs directly from DOS.  The size of a paragraph is 16 bytes. 
  4379.           The allocated memory is always paragraph aligned.  The segment 
  4380.           descriptor for the allocated memory is returned in the word pointed 
  4381.           to by segment. If the allocation request fails, the maximum number of 
  4382.           paragraphs that can be allocated is returned in this word instead. 
  4383.  
  4384. Returns:  The _dos_allocmem  function returns zero if successful. Otherwise, it 
  4385.           returns an MS-DOS error code and sets errno  to ENOMEM  indicating 
  4386.           insufficient memory or corrupted memory. 
  4387.  
  4388. See Also: alloca, calloc, _dos_freemem, _dos_setblock, halloc, malloc 
  4389.  
  4390. Example: 
  4391.  
  4392.                     #include <stdio.h>
  4393.                     #include <dos.h>
  4394.                     void main()
  4395.                       {
  4396.                         unsigned short segment;
  4397.                         /* Try to allocate 100 paragraphs, then free them */
  4398.                         if( _dos_allocmem( 100, &segment ) != 0 ) {
  4399.                           printf( "_dos_allocmem failed\n" );
  4400.                           printf( "Only %u paragraphs available\n",
  4401.                                    segment );
  4402.                         } else {
  4403.                           printf( "_dos_allocmem succeeded\n" );
  4404.                           if( _dos_freemem( segment ) != 0 ) {
  4405.                             printf( "_dos_freemem failed\n" );
  4406.                           } else {
  4407.                             printf( "_dos_freemem succeeded\n" );
  4408.                           }
  4409.                         }
  4410.                       }
  4411.  
  4412. Classification: DOS 
  4413.  
  4414.  
  4415. ΓòÉΓòÉΓòÉ 62. _dos_close ΓòÉΓòÉΓòÉ
  4416.  
  4417. Synopsis: 
  4418.  
  4419.                     #include <dos.h>
  4420.                     unsigned _dos_close( int handle );
  4421.  
  4422. Description: The _dos_close  function uses system call 0x3E to close the file 
  4423.           indicated by handle. The value for handle is the one returned by a 
  4424.           function call that created or last opened the file. 
  4425.  
  4426. Returns:  The _dos_close  function returns zero if successful. Otherwise, it 
  4427.           returns an MS-DOS error code and sets errno  to EBADF  indicating an 
  4428.           invalid file handle. 
  4429.  
  4430. See Also: creat, _dos_creat, _dos_creatnew, _dos_open, dup, fclose, open 
  4431.  
  4432. Example: 
  4433.  
  4434.                     #include <stdio.h>
  4435.                     #include <dos.h>
  4436.                     #include <fcntl.h>
  4437.                     void main()
  4438.                       {
  4439.                         int handle;
  4440.                         /* Try to open "stdio.h" and then close it */
  4441.                         if( _dos_open( "stdio.h", O_RDONLY, &handle ) != 0 ){
  4442.                           printf( "Unable to open file\n" );
  4443.                         } else {
  4444.                           printf( "Open succeeded\n" );
  4445.                           if( _dos_close( handle ) != 0 ) {
  4446.                             printf( "Close failed\n" );
  4447.                           } else {
  4448.                             printf( "Close succeeded\n" );
  4449.                           }
  4450.                         }
  4451.                       }
  4452.  
  4453. Classification: DOS 
  4454.  
  4455.  
  4456. ΓòÉΓòÉΓòÉ 63. _dos_creat ΓòÉΓòÉΓòÉ
  4457.  
  4458. Synopsis: 
  4459.  
  4460.                     #include <dos.h>
  4461.                     unsigned _dos_creat( char *path,
  4462.                                          unsigned attribute,
  4463.                                          int *handle );
  4464.  
  4465. Description: The _dos_creat  function uses system call 0x3C to create a new 
  4466.           file named path, with the access attributes specified by attribute. 
  4467.           The handle for the new file is returned in the word pointed to by 
  4468.           handle. If the file already exists, the contents will be erased, and 
  4469.           the attributes of the file will remain unchanged.  The possible 
  4470.           values for attribute are: 
  4471.  
  4472.    Attribute Meaning 
  4473.  
  4474.    _A_NORMAL Indicates a normal file.  File can be read or written without any 
  4475.              restrictions. 
  4476.  
  4477.    _A_RDONLY Indicates a read-only file.  File cannot be opened for "write". 
  4478.  
  4479.    _A_HIDDEN Indicates a hidden file.  This file will not show up in a normal 
  4480.              directory search. 
  4481.  
  4482.    _A_SYSTEM Indicates a system file.  This file will not show up in a normal 
  4483.              directory search. 
  4484.  
  4485. Returns:  The _dos_creat  function returns zero if successful. Otherwise, it 
  4486.           returns an MS-DOS error code and sets errno  to one of the following 
  4487.           values: 
  4488.  
  4489.    Constant  Meaning 
  4490.  
  4491.    EACCES    Access denied because the directory is full, or the file exists 
  4492.              and cannot be overwritten. 
  4493.  
  4494.    EMFILE    No more handles available, (too many open files) 
  4495.  
  4496.    ENOENT    Path or file not found 
  4497.  
  4498. See Also: creat, _dos_creatnew, _dos_open, open 
  4499.  
  4500. Example: 
  4501.  
  4502.                     #include <stdio.h>
  4503.                     #include <dos.h>
  4504.                     void main()
  4505.                       {
  4506.                         int handle;
  4507.                         if( _dos_creat( "file", _A_NORMAL, &handle ) != 0 ){
  4508.                           printf( "Unable to create file\n" );
  4509.                         } else {
  4510.                           printf( "Create succeeded\n" );
  4511.                           _dos_close( handle );
  4512.                         }
  4513.                       }
  4514.  
  4515. Classification: DOS 
  4516.  
  4517.  
  4518. ΓòÉΓòÉΓòÉ 64. _dos_creatnew ΓòÉΓòÉΓòÉ
  4519.  
  4520. Synopsis: 
  4521.  
  4522.                     #include <dos.h>
  4523.                     unsigned _dos_creatnew( char *path,
  4524.                                             unsigned attribute,
  4525.                                             int *handle );
  4526.  
  4527. Description: The _dos_creatnew  function uses system call 0x5B to create a new 
  4528.           file named path, with the access attributes specified by attribute. 
  4529.           The handle for the new file is returned in the word pointed to by 
  4530.           handle. If the file already exists, the create will fail.  The 
  4531.           possible values for attribute are: 
  4532.  
  4533.    Attribute Meaning 
  4534.  
  4535.    _A_NORMAL Indicates a normal file.  File can be read or written without any 
  4536.              restrictions. 
  4537.  
  4538.    _A_RDONLY Indicates a read-only file.  File cannot be opened for "write". 
  4539.  
  4540.    _A_HIDDEN Indicates a hidden file.  This file will not show up in a normal 
  4541.              directory search. 
  4542.  
  4543.    _A_SYSTEM Indicates a system file.  This file will not show up in a normal 
  4544.              directory search. 
  4545.  
  4546. Returns:  The _dos_creatnew  function returns zero if successful. Otherwise, it 
  4547.           returns an MS-DOS error code and sets errno  to one of the following 
  4548.           values: 
  4549.  
  4550.    Constant  Meaning 
  4551.  
  4552.    EACCES    Access denied because the directory is full, or the file exists 
  4553.              and cannot be overwritten. 
  4554.  
  4555.    EEXIST    File already exists 
  4556.  
  4557.    EMFILE    No more handles available, (too many open files) 
  4558.  
  4559.    ENOENT    Path or file not found 
  4560.  
  4561. See Also: creat, _dos_creat, _dos_open, open 
  4562.  
  4563. Example: 
  4564.  
  4565.                     #include <stdio.h>
  4566.                     #include <dos.h>
  4567.                     void main()
  4568.                       {
  4569.                         int handle1, handle2;
  4570.                         if( _dos_creat( "file", _A_NORMAL, &handle1 ) ){
  4571.                           printf( "Unable to create file\n" );
  4572.                         } else {
  4573.                           printf( "Create succeeded\n" );
  4574.                           if( _dos_creatnew( "file", _A_NORMAL, &handle2 ) ){
  4575.                             printf( "Unable to create new file\n" );
  4576.                           }
  4577.                           _dos_close( handle1 );
  4578.                         }
  4579.                       }
  4580.  
  4581. Classification: DOS 
  4582.  
  4583.  
  4584. ΓòÉΓòÉΓòÉ 65. dosexterr ΓòÉΓòÉΓòÉ
  4585.  
  4586. Synopsis: 
  4587.  
  4588.                     #include <dos.h>
  4589.                     int dosexterr( struct DOSERROR *err_info );
  4590.  
  4591.                     struct DOSERROR {
  4592.                             int exterror;   /* contents of AX register */
  4593.                             char class;     /* contents of BH register */
  4594.                             char action;    /* contents of BL register */
  4595.                             char locus;     /* contents of CH register */
  4596.                     };
  4597.  
  4598. Description: The dosexterr function extracts extended error information 
  4599.           following a failed DOS function.  This information is placed in the 
  4600.           structure located by err_info. This function is only useful with DOS 
  4601.           version 3.0 or later. 
  4602.  
  4603.           You should consult the technical documentation for the DOS system on 
  4604.           your computer for an interpretation of the error information. 
  4605.  
  4606. Returns:  The function returns zero when the preceding DOS call did not result 
  4607.           in an error.  Otherwise, the function returns the number of the 
  4608.           extended error. 
  4609.  
  4610. See Also: perror 
  4611.  
  4612. Example: 
  4613.  
  4614.                     #include <stdio.h>
  4615.                     #include <dos.h>
  4616.                     #include <fcntl.h>
  4617.  
  4618.                     struct DOSERROR dos_err;
  4619.                     void main()
  4620.                       {
  4621.                         int handle;
  4622.                         /* Try to open "stdio.h" and then close it */
  4623.                         if( _dos_open( "stdio.h", O_RDONLY, &handle ) != 0 ){
  4624.                           dosexterr( &dos_err );
  4625.                           printf( "Unable to open file\n" );
  4626.                           printf( "exterror (AX) = %d\n", dos_err.exterror );
  4627.                           printf( "class    (BH) = %d\n", dos_err.class );
  4628.                           printf( "action   (BL) = %d\n", dos_err.action );
  4629.                           printf( "locus    (CH) = %d\n", dos_err.locus );
  4630.                         } else {
  4631.                           printf( "Open succeeded\n" );
  4632.                           if( _dos_close( handle ) != 0 ) {
  4633.                             printf( "Close failed\n" );
  4634.                           } else {
  4635.                             printf( "Close succeeded\n" );
  4636.                           }
  4637.                         }
  4638.                       }
  4639.  
  4640.           produces the following: 
  4641.  
  4642.                     Unable to open file
  4643.                     exterror (AX) = 2
  4644.                     class    (BH) = 8
  4645.                     action   (BL) = 3
  4646.                     locus    (CH) = 2
  4647.  
  4648. Classification: DOS 
  4649.  
  4650.  
  4651. ΓòÉΓòÉΓòÉ 66. _dos_find Functions ΓòÉΓòÉΓòÉ
  4652.  
  4653. Synopsis: 
  4654.  
  4655.                     #include <dos.h>
  4656.                     unsigned _dos_findfirst( char *path,
  4657.                                              unsigned attributes,
  4658.                                              struct find_t *buffer );
  4659.                     unsigned _dos_findnext(  struct find_t *buffer );
  4660.                     unsigned _dos_findclose( struct find_t *buffer );
  4661.  
  4662.                     struct find_t {
  4663.                       char reserved[21];      /* reserved for use by DOS   */
  4664.                       char attrib;            /* attribute byte for file   */
  4665.                       unsigned short wr_time; /* time of last write to file*/
  4666.                       unsigned short wr_date; /* date of last write to file*/
  4667.                       unsigned long  size;    /* length of file in bytes   */
  4668.                       char name[13];          /* null-terminated filename  */
  4669.                     };
  4670.  
  4671. Description: The _dos_findfirst function uses system call 0x4E to return 
  4672.           information on the first file whose name and attributes match the 
  4673.           path and attributes arguments.  The information is returned in a 
  4674.           find_t structure pointed to by buffer. The path argument may contain 
  4675.           wildcard characters ('?' and '*').  The attributes argument may be 
  4676.           any combination of the following constants: 
  4677.  
  4678.    Attribute Meaning 
  4679.  
  4680.    _A_NORMAL Indicates a normal file.  File can be read or written without any 
  4681.              restrictions. 
  4682.  
  4683.    _A_RDONLY Indicates a read-only file.  File cannot be opened for "write". 
  4684.  
  4685.    _A_HIDDEN Indicates a hidden file.  This file will not show up in a normal 
  4686.              directory search. 
  4687.  
  4688.    _A_SYSTEM Indicates a system file.  This file will not show up in a normal 
  4689.              directory search. 
  4690.  
  4691.    _A_VOLID  Indicates a volume-ID. 
  4692.  
  4693.    _A_SUBDIR Indicates a sub-directory. 
  4694.  
  4695.    _A_ARCH   This is the archive flag.  It is set whenever the file is 
  4696.              modified, and is cleared by the MS-DOS BACKUP command and other 
  4697.              backup utility programs. 
  4698.  
  4699.           The _dos_findnext function uses system call 0x4F to return 
  4700.           information on the next file whose name and attributes match the 
  4701.           pattern supplied to the _dos_findfirst function. 
  4702.  
  4703.           On some systems (e.g. OS/2), you must call _dos_findclose to indicate 
  4704.           that you are done matching files.  This function deallocates any 
  4705.           resources that were allocated by the _dos_findfirst function. 
  4706.  
  4707. Returns:  The _dos_find functions return zero if successful. Otherwise, the 
  4708.           _dos_findfirst and _dos_findnext functions return an MS-DOS error 
  4709.           code and sets errno to ENOENT indicating that no more files matched 
  4710.           the path and attributes arguments. 
  4711.  
  4712. See Also: opendir, readdir, closedir 
  4713.  
  4714. Example: 
  4715.  
  4716.                     #include <stdio.h>
  4717.                     #include <dos.h>
  4718.                     void main()
  4719.                       {
  4720.                         struct find_t  fileinfo;
  4721.                         unsigned rc;        /* return code */
  4722.                         /* Display name and size of "*.c" files */
  4723.                         rc = _dos_findfirst( "*.c", _A_NORMAL, &fileinfo );
  4724.                         while( rc == 0 ) {
  4725.                           printf( "%14s %10ld\n", fileinfo.name,
  4726.                                                   fileinfo.size );
  4727.                           rc = _dos_findnext( &fileinfo );
  4728.                         }
  4729.                         _dos_findclose( &fileinfo );
  4730.                       }
  4731.  
  4732. Classification: DOS 
  4733.  
  4734.  
  4735. ΓòÉΓòÉΓòÉ 67. _dos_freemem ΓòÉΓòÉΓòÉ
  4736.  
  4737. Synopsis: 
  4738.  
  4739.                     #include <dos.h>
  4740.                     unsigned _dos_freemem( unsigned segment );
  4741.  
  4742. Description: The _dos_freemem function uses system call 0x49 to release memory 
  4743.           that was previously allocated by _dos_allocmem. The value contained 
  4744.           in segment is the one returned by a previous call to _dos_allocmem. 
  4745.  
  4746. Returns:  The _dos_freemem function returns zero if successful. Otherwise, it 
  4747.           returns an MS-DOS error code and sets errno to ENOMEM indicating a 
  4748.           bad segment value or DOS memory has been corrupted. 
  4749.  
  4750. See Also: _dos_allocmem, _dos_setblock, _ffree, free, hfree, _nfree 
  4751.  
  4752. Example: 
  4753.  
  4754.                     #include <stdio.h>
  4755.                     #include <dos.h>
  4756.                     void main()
  4757.                       {
  4758.                         unsigned short segment;
  4759.                         /* Try to allocate 100 paragraphs, then free them */
  4760.                         if( _dos_allocmem( 100, &segment ) != 0 ) {
  4761.                           printf( "_dos_allocmem failed\n" );
  4762.                           printf( "Only %u paragraphs available\n",
  4763.                                    segment );
  4764.                         } else {
  4765.                           printf( "_dos_allocmem succeeded\n" );
  4766.                           if( _dos_freemem( segment ) != 0 ) {
  4767.                             printf( "_dos_freemem failed\n" );
  4768.                           } else {
  4769.                             printf( "_dos_freemem succeeded\n" );
  4770.                           }
  4771.                         }
  4772.                       }
  4773.  
  4774. Classification: DOS 
  4775.  
  4776.  
  4777. ΓòÉΓòÉΓòÉ 68. _dos_getdate ΓòÉΓòÉΓòÉ
  4778.  
  4779. Synopsis: 
  4780.  
  4781.                     #include <dos.h>
  4782.                     void _dos_getdate( struct dosdate_t *date );
  4783.  
  4784.                     struct dosdate_t {
  4785.                             unsigned char day;      /* 1-31 */
  4786.                             unsigned char month;    /* 1-12 */
  4787.                             unsigned short year;    /* 1980-2099 */
  4788.                             unsigned char dayofweek;/* 0-6 (0=Sunday) */
  4789.                     };
  4790.  
  4791. Description: The _dos_getdate function uses system call 0x2A to get the current 
  4792.           system date.  The date information is returned in a dosdate_t 
  4793.           structure pointed to by date. 
  4794.  
  4795. Returns:  The _dos_getdate function has no return value. 
  4796.  
  4797. See Also: _dos_gettime, _dos_setdate, _dos_settime, gmtime, localtime, mktime, 
  4798.           time 
  4799.  
  4800. Example: 
  4801.  
  4802.                     #include <stdio.h>
  4803.                     #include <dos.h>
  4804.                     void main()
  4805.                       {
  4806.                         struct dosdate_t date;
  4807.                         struct dostime_t time;
  4808.                         /* Get and display the current date and time */
  4809.                         _dos_getdate( &date );
  4810.                         _dos_gettime( &time );
  4811.                         printf( "The date (MM-DD-YYYY) is: %d-%d-%d\n",
  4812.                                       date.month, date.day, date.year );
  4813.                         printf( "The time (HH:MM:SS) is: %.2d:%.2d:%.2d\n",
  4814.                                       time.hour, time.minute, time.second );
  4815.                       }
  4816.  
  4817.           produces the following: 
  4818.  
  4819.                     The date (MM-DD-YYYY) is: 12-25-1989
  4820.                     The time (HH:MM:SS) is: 14:23:57
  4821.  
  4822. Classification: DOS 
  4823.  
  4824.  
  4825. ΓòÉΓòÉΓòÉ 69. _dos_getdiskfree ΓòÉΓòÉΓòÉ
  4826.  
  4827. Synopsis: 
  4828.  
  4829.                     #include <dos.h>
  4830.                     unsigned _dos_getdiskfree( unsigned drive,
  4831.                                             struct diskfree_t *diskspace );
  4832.                     struct diskfree_t {
  4833.                             unsigned short total_clusters;
  4834.                             unsigned short avail_clusters;
  4835.                             unsigned short sectors_per_cluster;
  4836.                             unsigned short bytes_per_sector;
  4837.                     };
  4838.  
  4839. Description: The _dos_getdiskfree function uses system call 0x36 to obtain 
  4840.           useful information on the disk drive specified by drive. Specify 0 
  4841.           for the default drive, 1 for drive A, 2 for drive B, etc.  The 
  4842.           information about the drive is returned in the structure diskfree_t 
  4843.           pointed to by diskspace. 
  4844.  
  4845. Returns:  The _dos_getdiskfree function returns zero if successful. Otherwise, 
  4846.           it returns a non-zero value and sets errno to EINVAL indicating an 
  4847.           invalid drive was specified. 
  4848.  
  4849. See Also: _dos_getdrive, _dos_setdrive 
  4850.  
  4851. Example: 
  4852.  
  4853.                     #include <stdio.h>
  4854.                     #include <dos.h>
  4855.                     void main()
  4856.                       {
  4857.                         struct diskfree_t disk_data;
  4858.                         /* get information about drive 3 (the C drive) */
  4859.                         if( _dos_getdiskfree( 3, &disk_data ) == 0 ) {
  4860.                           printf( "total clusters: %u\n",
  4861.                                             disk_data.total_clusters );
  4862.                           printf( "available clusters: %u\n",
  4863.                                             disk_data.avail_clusters );
  4864.                           printf( "sectors/cluster: %u\n",
  4865.                                             disk_data.sectors_per_cluster );
  4866.                           printf( "bytes per sector: %u\n",
  4867.                                             disk_data.bytes_per_sector );
  4868.                         } else {
  4869.                           printf( "Invalid drive specified\n" );
  4870.                         }
  4871.                       }
  4872.  
  4873.           produces the following: 
  4874.  
  4875.                     total clusters: 16335
  4876.                     available clusters: 510
  4877.                     sectors/cluster: 4
  4878.                     bytes per sector: 512
  4879.  
  4880. Classification: DOS 
  4881.  
  4882.  
  4883. ΓòÉΓòÉΓòÉ 70. _dos_getdrive ΓòÉΓòÉΓòÉ
  4884.  
  4885. Synopsis: 
  4886.  
  4887.                     #include <dos.h>
  4888.                     void _dos_getdrive( unsigned *drive );
  4889.  
  4890. Description: The _dos_getdrive function uses system call 0x19 to get the 
  4891.           current disk drive number.  The current disk drive number is returned 
  4892.           in the word pointed to by drive. A value of 1 is drive A, 2 is drive 
  4893.           B, 3 is drive C, etc. 
  4894.  
  4895. Returns:  The _dos_getdrive function has no return value. 
  4896.  
  4897. See Also: _dos_getdiskfree, _dos_setdrive 
  4898.  
  4899. Example: 
  4900.  
  4901.                     #include <stdio.h>
  4902.                     #include <dos.h>
  4903.                     void main()
  4904.                       {
  4905.                         unsigned drive;
  4906.                         _dos_getdrive( &drive );
  4907.                         printf( "The current drive is %c\n",
  4908.                                     'A' + drive - 1 );
  4909.                       }
  4910.  
  4911.           produces the following: 
  4912.  
  4913.                     The current drive is C
  4914.  
  4915. Classification: DOS 
  4916.  
  4917.  
  4918. ΓòÉΓòÉΓòÉ 71. _dos_getfileattr ΓòÉΓòÉΓòÉ
  4919.  
  4920. Synopsis: 
  4921.  
  4922.                     #include <dos.h>
  4923.                     unsigned _dos_getfileattr( char *path,
  4924.                                                unsigned *attributes );
  4925.  
  4926. Description: The _dos_getfileattr function uses system call 0x43 to get the 
  4927.           current attributes of the file or directory that path points to.  The 
  4928.           possible attributes are: 
  4929.  
  4930.    Attribute Meaning 
  4931.  
  4932.    _A_NORMAL Indicates a normal file.  File can be read or written without any 
  4933.              restrictions. 
  4934.  
  4935.    _A_RDONLY Indicates a read-only file.  File cannot be opened for "write". 
  4936.  
  4937.    _A_HIDDEN Indicates a hidden file.  This file will not show up in a normal 
  4938.              directory search. 
  4939.  
  4940.    _A_SYSTEM Indicates a system file.  This file will not show up in a normal 
  4941.              directory search. 
  4942.  
  4943.    _A_VOLID  Indicates a volume-ID. 
  4944.  
  4945.    _A_SUBDIR Indicates a sub-directory. 
  4946.  
  4947.    _A_ARCH   This is the archive flag.  It is set whenever the file is 
  4948.              modified, and is cleared by the MS-DOS BACKUP command and other 
  4949.              backup utility programs. 
  4950.  
  4951. Returns:  The _dos_getfileattr function returns zero if successful. Otherwise, 
  4952.           it returns an MS-DOS error code and sets errno to ENOENT indicating 
  4953.           that no file matched the path. 
  4954.  
  4955. See Also: _dos_setfileattr 
  4956.  
  4957. Example: 
  4958.  
  4959.                     #include <stdio.h>
  4960.                     #include <dos.h>
  4961.                     void main()
  4962.                       {
  4963.                         int      handle;
  4964.                         if( _dos_creat( "file", _A_RDONLY, &handle ) != 0 ) {
  4965.                           printf( "Error creating file\n" );
  4966.                         }
  4967.                         print_attribute();
  4968.                         _dos_setfileattr( "file", _A_NORMAL );
  4969.                         print_attribute();
  4970.                         _dos_close( handle );
  4971.                       }
  4972.                     print_attribute()
  4973.                       {
  4974.                         unsigned attribute;
  4975.                         _dos_getfileattr( "file", &attribute );
  4976.                         printf( "File attribute is %d\n", attribute );
  4977.                         if( attribute & _A_RDONLY ) {
  4978.                             printf( "This is a read-only file.\n" );
  4979.                         } else {
  4980.                             printf( "This is not a read-only file.\n" );
  4981.                         }
  4982.                       }
  4983.  
  4984. Classification: DOS 
  4985.  
  4986.  
  4987. ΓòÉΓòÉΓòÉ 72. _dos_getftime ΓòÉΓòÉΓòÉ
  4988.  
  4989. Synopsis: 
  4990.  
  4991.                     #include <dos.h>
  4992.                     unsigned _dos_getftime( int handle,
  4993.                                             unsigned short *date,
  4994.                                             unsigned short *time );
  4995.  
  4996. Description: The _dos_getftime function uses system call 0x57 to get the date 
  4997.           and time that the file associated with handle was last modified.  The 
  4998.           date consists of the year, month and day packed into 16 bits as 
  4999.           follows: 
  5000.  
  5001.    Bits      Meaning 
  5002.    bits 0-4  Day (1-31) 
  5003.    bits 5-8  Month (1-12) 
  5004.    bits 9-15 Year (0-119 representing 1980-2099) 
  5005.  
  5006.           The time consists of the hour, minute and seconds/2 packed into 16 
  5007.           bits as follows: 
  5008.  
  5009.    Bits      Meaning 
  5010.    bits 0-4  Seconds/2 (0-29) 
  5011.    bits 5-10 Minutes (0-59) 
  5012.    bits 11-15 Hours (0-23) 
  5013.  
  5014. Returns:  The _dos_getftime function returns zero if successful. Otherwise, it 
  5015.           returns an MS-DOS error code and sets errno to one of the following 
  5016.           values: 
  5017.  
  5018.    EBADF     Invalid file handle 
  5019.  
  5020. See Also: _dos_setftime 
  5021.  
  5022. Example: 
  5023.  
  5024.                     #include <stdio.h>
  5025.                     #include <dos.h>
  5026.                     #include <fcntl.h>
  5027.                     #define YEAR(t)   (((t & 0xFE00) >> 9) + 1980)
  5028.                     #define MONTH(t)  ((t & 0x01E0) >> 5)
  5029.                     #define DAY(t)    (t & 0x001F)
  5030.                     #define HOUR(t)   ((t & 0xF800) >> 11)
  5031.                     #define MINUTE(t) ((t & 0x07E0) >> 5)
  5032.                     #define SECOND(t) ((t & 0x001F) << 1)
  5033.                     void main()
  5034.                       {
  5035.                         int      handle;
  5036.                         unsigned short date, time;
  5037.                         if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
  5038.                           printf( "Unable to open file\n" );
  5039.                         } else {
  5040.                           printf( "Open succeeded\n" );
  5041.                           _dos_getftime( handle, &date, &time );
  5042.                           printf( "The file was last modified on %d/%d/%d",
  5043.                                   MONTH(date), DAY(date), YEAR(date) );
  5044.                           printf( " at %.2d:%.2d:%.2d\n",
  5045.                                   HOUR(time), MINUTE(time), SECOND(time) );
  5046.                           _dos_close( handle );
  5047.                         }
  5048.                       }
  5049.  
  5050.           produces the following: 
  5051.  
  5052.                     Open succeeded
  5053.                     The file was last modified on 12/29/1989 at 14:32:46
  5054.  
  5055. Classification: DOS 
  5056.  
  5057.  
  5058. ΓòÉΓòÉΓòÉ 73. _dos_gettime ΓòÉΓòÉΓòÉ
  5059.  
  5060. Synopsis: 
  5061.  
  5062.                     #include <dos.h>
  5063.                     void _dos_gettime( struct dostime_t *time );
  5064.  
  5065.                     struct dostime_t {
  5066.                             unsigned char hour;     /* 0-23 */
  5067.                             unsigned char minute;   /* 0-59 */
  5068.                             unsigned char second;   /* 0-59 */
  5069.                             unsigned char hsecond;  /* 1/100 second; 0-99 */
  5070.                     };
  5071.  
  5072. Description: The _dos_gettime function uses system call 0x2C to get the current 
  5073.           system time.  The time information is returned in a dostime_t 
  5074.           structure pointed to by time. 
  5075.  
  5076. Returns:  The _dos_gettime function has no return value. 
  5077.  
  5078. See Also: _dos_getdate, _dos_setdate, _dos_settime, gmtime, localtime, mktime, 
  5079.           time 
  5080.  
  5081. Example: 
  5082.  
  5083.                     #include <stdio.h>
  5084.                     #include <dos.h>
  5085.                     void main()
  5086.                       {
  5087.                         struct dosdate_t date;
  5088.                         struct dostime_t time;
  5089.                         /* Get and display the current date and time */
  5090.                         _dos_getdate( &date );
  5091.                         _dos_gettime( &time );
  5092.                         printf( "The date (MM-DD-YYYY) is: %d-%d-%d\n",
  5093.                             date.month, date.day, date.year );
  5094.                         printf( "The time (HH:MM:SS) is: %.2d:%.2d:%.2d\n",
  5095.                             time.hour, time.minute, time.second );
  5096.                       }
  5097.  
  5098.           produces the following: 
  5099.  
  5100.                     The date (MM-DD-YYYY) is: 12-25-1989
  5101.                     The time (HH:MM:SS) is: 14:23:57
  5102.  
  5103. Classification: DOS 
  5104.  
  5105.  
  5106. ΓòÉΓòÉΓòÉ 74. _dos_getvect ΓòÉΓòÉΓòÉ
  5107.  
  5108. Synopsis: 
  5109.  
  5110.                     #include <dos.h>
  5111.                     void (__interrupt __far *_dos_getvect(unsigned intnum))();
  5112.  
  5113. Description: The _dos_getvect function gets the current value of interrupt 
  5114.           vector number intnum. 
  5115.  
  5116. Returns:  The function returns a far pointer to the current interrupt handler 
  5117.           for interrupt number intnum. 
  5118.  
  5119. See Also: _chain_intr, _dos_keep, _dos_setvect 
  5120.  
  5121. Example: 
  5122.  
  5123.                     #include <stdio.h>
  5124.                     #include <dos.h>
  5125.  
  5126.                     volatile int clock_ticks;
  5127.                     void (__interrupt __far *prev_int_1c)();
  5128.                     #define BLIP_COUNT  (5*18)  /* 5 seconds */
  5129.                     void __interrupt __far timer_rtn()
  5130.                       {
  5131.                         ++clock_ticks;
  5132.                         _chain_intr( prev_int_1c );
  5133.                       }
  5134.  
  5135.                     int delays = 0;
  5136.                     void main()
  5137.                       {
  5138.                         prev_int_1c = _dos_getvect( 0x1c );
  5139.                         _dos_setvect( 0x1c, timer_rtn );
  5140.                         while( compile_a_line() ) {
  5141.                             if( clock_ticks >= BLIP_COUNT ) {
  5142.                                 putchar( '.' );
  5143.                                 clock_ticks -= BLIP_COUNT;
  5144.                             }
  5145.                         }
  5146.                         _dos_setvect( 0x1c, prev_int_1c );
  5147.                       }
  5148.                     int compile_a_line()
  5149.                       {
  5150.                         if( delays > 15 ) return( 0 );
  5151.                         delay( 1000 );  /* delay for 1 second */
  5152.                         printf( "Delayed for 1 second\n" );
  5153.                         delays++;
  5154.                         return( 1 );
  5155.                       }
  5156.  
  5157. Classification: WATCOM 
  5158.  
  5159.  
  5160. ΓòÉΓòÉΓòÉ 75. _dos_keep ΓòÉΓòÉΓòÉ
  5161.  
  5162. Synopsis: 
  5163.  
  5164.                     #include <dos.h>
  5165.                     void _dos_keep( unsigned retcode, unsigned memsize );
  5166.  
  5167. Description: The _dos_keep function is used to install 
  5168.           terminate-and-stay-resident programs ("TSR's") in memory.  The amount 
  5169.           of memory kept for the program is memsize paragraphs (a paragraph is 
  5170.           16 bytes) from the Program Segment Prefix which is stored in the 
  5171.           variable _psp. The value of retcode is returned to the parent 
  5172.           process. 
  5173.  
  5174. Returns:  The _dos_keep function does not return. 
  5175.  
  5176. See Also: _chain_intr, _dos_getvect, _dos_setvect 
  5177.  
  5178. Classification: DOS 
  5179.  
  5180.  
  5181. ΓòÉΓòÉΓòÉ 76. _dos_open ΓòÉΓòÉΓòÉ
  5182.  
  5183. Synopsis: 
  5184.  
  5185.                     #include <dos.h>
  5186.                     #include <fcntl.h>
  5187.                     #include <share.h>
  5188.                     unsigned _dos_open( char *path,
  5189.                                         unsigned mode,
  5190.                                         int *handle );
  5191.  
  5192. Description: The _dos_open function uses system call 0x3D to open the file 
  5193.           specified by path, which must be an existing file.  The mode argument 
  5194.           specifies the file's access, sharing and inheritance permissions. The 
  5195.           access mode must be one of: 
  5196.  
  5197.    Mode      Meaning 
  5198.    O_RDONLY  Read only 
  5199.    O_WRONLY  Write only 
  5200.    O_RDWR    Both read and write 
  5201.  
  5202.           The sharing permissions, if specified, must be one of: 
  5203.  
  5204.    Permission Meaning 
  5205.    SH_COMPAT Set compatibility mode. 
  5206.    SH_DENYRW Prevent read or write access to the file. 
  5207.    SH_DENYWR Prevent write access of the file. 
  5208.    SH_DENYRD Prevent read access to the file. 
  5209.    SH_DENYNO Permit both read and write access to the file. 
  5210.  
  5211.           The inheritance permission, if specified, is: 
  5212.  
  5213.    Permission Meaning 
  5214.  
  5215.    O_NOINHERIT File is not inherited by a child process 
  5216.  
  5217. Returns:  The _dos_open function returns zero if successful. Otherwise, it 
  5218.           returns an MS-DOS error code and sets errno to one of the following 
  5219.           values: 
  5220.  
  5221.    Constant  Meaning 
  5222.  
  5223.    EACCES    Access denied because path specifies a directory or a volume ID, 
  5224.              or opening a read-only file for write access 
  5225.  
  5226.    EINVAL    A sharing mode was specified when file sharing is not installed, 
  5227.              or access-mode value is invalid 
  5228.  
  5229.    EMFILE    No more handles available, (too many open files) 
  5230.  
  5231.    ENOENT    Path or file not found 
  5232.  
  5233. See Also: _dos_close, _dos_creat, _dos_creatnew, _dos_read, _dos_write, open 
  5234.  
  5235. Example: 
  5236.  
  5237.                     #include <stdio.h>
  5238.                     #include <dos.h>
  5239.                     #include <fcntl.h>
  5240.                     #include <share.h>
  5241.                     void main()
  5242.                       {
  5243.                         int handle;
  5244.                         if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
  5245.                             printf( "Unable to open file\n" );
  5246.                         } else {
  5247.                             printf( "Open succeeded\n" );
  5248.                             _dos_close( handle );
  5249.                         }
  5250.                       }
  5251.  
  5252. Classification: DOS 
  5253.  
  5254.  
  5255. ΓòÉΓòÉΓòÉ 77. _dos_read ΓòÉΓòÉΓòÉ
  5256.  
  5257. Synopsis: 
  5258.  
  5259.                     #include <dos.h>
  5260.                     unsigned _dos_read( int handle, void __far *buffer,
  5261.                                         unsigned count, unsigned *bytes );
  5262.  
  5263. Description: The _dos_read function uses system call 0x3F to read count bytes 
  5264.           of data from the file specified by handle into the buffer pointed to 
  5265.           by buffer. The number of bytes successfully read will be stored in 
  5266.           the unsigned integer pointed to by bytes. 
  5267.  
  5268. Returns:  The _dos_read function returns zero if successful. Otherwise, it 
  5269.           returns an MS-DOS error code and sets errno to one of the following 
  5270.           values: 
  5271.  
  5272.    Constant  Meaning 
  5273.  
  5274.    EACCES    Access denied because the file is not open for read access 
  5275.  
  5276.    EBADF     Invalid file handle 
  5277.  
  5278. See Also: _dos_close, _dos_open, _dos_write 
  5279.  
  5280. Example: 
  5281.  
  5282.                     #include <stdio.h>
  5283.                     #include <dos.h>
  5284.                     #include <fcntl.h>
  5285.                     void main()
  5286.                       {
  5287.                         unsigned len_read;
  5288.                         int      handle;
  5289.                         auto char buffer[80];
  5290.                         if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
  5291.                           printf( "Unable to open file\n" );
  5292.                         } else {
  5293.                           printf( "Open succeeded\n" );
  5294.                           _dos_read( handle, buffer, 80, &len_read );
  5295.                           _dos_close( handle );
  5296.                         }
  5297.                       }
  5298.  
  5299. Classification: DOS 
  5300.  
  5301.  
  5302. ΓòÉΓòÉΓòÉ 78. _dos_setblock ΓòÉΓòÉΓòÉ
  5303.  
  5304. Synopsis: 
  5305.  
  5306.                     #include <dos.h>
  5307.                     unsigned _dos_setblock( unsigned size,
  5308.                                             unsigned short segment,
  5309.                                             unsigned *maxsize );
  5310.  
  5311. Description: The _dos_setblock function uses system call 0x4A to change the 
  5312.           size of segment, which was previously allocated by _dos_allocmem, to 
  5313.           size paragraphs.  If the request fails, the maximum number of 
  5314.           paragraphs that this memory block can be changed to is returned in 
  5315.           the word pointed to by maxsize. 
  5316.  
  5317. Returns:  The _dos_setblock function returns zero if successful. Otherwise, it 
  5318.           returns an MS-DOS error code and sets errno to ENOMEM indicating a 
  5319.           bad segment value, insufficient memory or corrupted memory. 
  5320.  
  5321. See Also: _dos_allocmem, _dos_freemem, realloc 
  5322.  
  5323. Example: 
  5324.  
  5325.                     #include <stdio.h>
  5326.                     #include <dos.h>
  5327.                     void main()
  5328.                       {
  5329.                         unsigned short segment;
  5330.                         unsigned maxsize;
  5331.  
  5332.                         /* Try to allocate 100 paragraphs, then free them */
  5333.                         if( _dos_allocmem( 100, &segment ) != 0 ) {
  5334.                           printf( "_dos_allocmem failed\n" );
  5335.                           printf( "Only %u paragraphs available\n",segment);
  5336.                         } else {
  5337.  
  5338.  
  5339.                           printf( "_dos_allocmem succeeded\n" );
  5340.                           /* Try to increase it to 200 paragraphs */
  5341.                           if( _dos_setblock( 200, segment, &maxsize ) != 0 ){
  5342.                             printf( "Unable to increase the size\n" );
  5343.                           }
  5344.                           if( _dos_freemem( segment ) != 0 ) {
  5345.                             printf( "_dos_freemem failed\n" );
  5346.                           }
  5347.                         }
  5348.                       }
  5349.  
  5350. Classification: DOS 
  5351.  
  5352.  
  5353. ΓòÉΓòÉΓòÉ 79. _dos_setdate ΓòÉΓòÉΓòÉ
  5354.  
  5355. Synopsis: 
  5356.  
  5357.                     #include <dos.h>
  5358.                     unsigned _dos_setdate( struct dosdate_t *date );
  5359.  
  5360.                     struct dosdate_t {
  5361.                             unsigned char day;      /* 1-31 */
  5362.                             unsigned char month;    /* 1-12 */
  5363.                             unsigned short year;    /* 1980-2099 */
  5364.                             unsigned char dayofweek;/* 0-6 (0=Sunday) */
  5365.                     };
  5366.  
  5367. Description: The _dos_setdate function uses system call 0x2B to set the current 
  5368.           system date.  The date information is passed in a dosdate_t structure 
  5369.           pointed to by date. 
  5370.  
  5371. Returns:  The _dos_setdate function returns zero if successful. Otherwise, it 
  5372.           returns a non-zero value and sets errno to EINVAL indicating that an 
  5373.           invalid date was given. 
  5374.  
  5375. See Also: _dos_getdate, _dos_gettime, _dos_settime, gmtime, localtime, mktime, 
  5376.           time 
  5377.  
  5378. Example: 
  5379.  
  5380.                     #include <stdio.h>
  5381.                     #include <dos.h>
  5382.                     void main()
  5383.                       {
  5384.                         struct dosdate_t date;
  5385.                         struct dostime_t time;
  5386.                         /* Get and display the current date and time */
  5387.                         _dos_getdate( &date );
  5388.                         _dos_gettime( &time );
  5389.                         printf( "The date (MM-DD-YYYY) is: %d-%d-%d\n",
  5390.                             date.month, date.day, date.year );
  5391.                         printf( "The time (HH:MM:SS) is: %.2d:%.2d:%.2d\n",
  5392.                             time.hour, time.minute, time.second );
  5393.                         /* Change it to the turn of the century */
  5394.                         date.year = 1999;
  5395.                         date.month = 12;
  5396.                         date.day = 31;
  5397.                         time.hour = 23;
  5398.                         time.minute = 59;
  5399.                         _dos_setdate( &date );
  5400.                         _dos_settime( &time );
  5401.                         printf( "New date (MM-DD-YYYY) is: %d-%d-%d\n",
  5402.                             date.month, date.day, date.year );
  5403.                         printf( "New time (HH:MM:SS) is: %.2d:%.2d:%.2d\n",
  5404.                             time.hour, time.minute, time.second );
  5405.                       }
  5406.  
  5407.           produces the following: 
  5408.  
  5409.                     The date (MM-DD-YYYY) is: 12-25-1989
  5410.                     The time (HH:MM:SS) is: 14:23:15
  5411.                     New date (MM-DD-YYYY) is: 12-31-1999
  5412.                     New time (HH:MM:SS) is: 23:59:16
  5413.  
  5414. Classification: DOS 
  5415.  
  5416.  
  5417. ΓòÉΓòÉΓòÉ 80. _dos_setdrive ΓòÉΓòÉΓòÉ
  5418.  
  5419. Synopsis: 
  5420.  
  5421.                     #include <dos.h>
  5422.                     void _dos_setdrive( unsigned drive, unsigned *total );
  5423.  
  5424. Description: The _dos_setdrive function uses system call 0x0E to set the 
  5425.           current default disk drive to be the drive specified by drive, where 
  5426.           1 = drive A, 2 = drive B, etc.  The total number of disk drives is 
  5427.           returned in the word pointed to by total. 
  5428.  
  5429. Returns:  The _dos_setdrive function has no return value.  If an invalid drive 
  5430.           number is specified, the function fails with no error indication. 
  5431.           You must use the _dos_getdrive function to check that the desired 
  5432.           drive has been set. 
  5433.  
  5434. See Also: _dos_getdiskfree, _dos_getdrive 
  5435.  
  5436. Example: 
  5437.  
  5438.                     #include <stdio.h>
  5439.                     #include <dos.h>
  5440.                     void main()
  5441.                       {
  5442.                         unsigned drive, total;
  5443.                         _dos_getdrive( &drive );
  5444.                         printf( "Current drive is %c\n", 'A' + drive - 1 );
  5445.                         /* try to change to drive C */
  5446.                         _dos_setdrive( 3, &total );
  5447.                         _dos_getdrive( &drive );
  5448.                         printf( "Current drive is %c\n", 'A' + drive - 1 );
  5449.                         printf( "Total number of drives is %u\n", total );
  5450.                       }
  5451.  
  5452.           produces the following: 
  5453.  
  5454.                     Current drive is D
  5455.                     Current drive is C
  5456.                     Total number of drives is 6
  5457.  
  5458. Classification: DOS 
  5459.  
  5460.  
  5461. ΓòÉΓòÉΓòÉ 81. _dos_setfileattr ΓòÉΓòÉΓòÉ
  5462.  
  5463. Synopsis: 
  5464.  
  5465.                     #include <dos.h>
  5466.                     unsigned _dos_setfileattr( char *path,
  5467.                                                unsigned attributes );
  5468.  
  5469. Description: The _dos_setfileattr function uses system call 0x43 to set the 
  5470.           attributes of the file or directory that path points to.  The 
  5471.           possible attributes are: 
  5472.  
  5473.    Attribute Meaning 
  5474.  
  5475.    _A_NORMAL Indicates a normal file.  File can be read or written without any 
  5476.              restrictions. 
  5477.  
  5478.    _A_RDONLY Indicates a read-only file.  File cannot be opened for "write". 
  5479.  
  5480.    _A_HIDDEN Indicates a hidden file.  This file will not show up in a normal 
  5481.              directory search. 
  5482.  
  5483.    _A_SYSTEM Indicates a system file.  This file will not show up in a normal 
  5484.              directory search. 
  5485.  
  5486.    _A_VOLID  Indicates a volume-ID. 
  5487.  
  5488.    _A_SUBDIR Indicates a sub-directory. 
  5489.  
  5490.    _A_ARCH   This is the archive flag.  It is set whenever the file is 
  5491.              modified, and is cleared by the MS-DOS BACKUP command and other 
  5492.              backup utility programs. 
  5493.  
  5494. Returns:  The _dos_setfileattr function returns zero if successful. Otherwise, 
  5495.           it returns an MS-DOS error code and sets errno to one of the 
  5496.           following: 
  5497.  
  5498.    Constant  Meaning 
  5499.  
  5500.    ENOENT    No file or directory matched the specified path. 
  5501.  
  5502.    EACCES    Access denied; cannot change the volume ID or the subdirectory. 
  5503.  
  5504. See Also: _dos_getfileattr 
  5505.  
  5506. Example: 
  5507.  
  5508.                     #include <stdio.h>
  5509.                     #include <dos.h>
  5510.                     void main()
  5511.                       {
  5512.                         int      handle;
  5513.                         if( _dos_creat( "file", _A_RDONLY, &handle ) != 0 ){
  5514.                           printf( "Error creating file\n" );
  5515.                         }
  5516.                         print_attribute();
  5517.                         _dos_setfileattr( "file", _A_NORMAL );
  5518.                         print_attribute();
  5519.                         _dos_close( handle );
  5520.                       }
  5521.                     print_attribute()
  5522.                       {
  5523.                         unsigned attribute;
  5524.                         _dos_getfileattr( "file", &attribute );
  5525.                         printf( "File attribute is %d\n", attribute );
  5526.                         if( attribute & _A_RDONLY ) {
  5527.                             printf( "This is a read-only file\n" );
  5528.                         } else {
  5529.                             printf( "This is not a read-only file\n" );
  5530.                         }
  5531.                       }
  5532.  
  5533. Classification: DOS 
  5534.  
  5535.  
  5536. ΓòÉΓòÉΓòÉ 82. _dos_setftime ΓòÉΓòÉΓòÉ
  5537.  
  5538. Synopsis: 
  5539.  
  5540.                     #include <dos.h>
  5541.                     unsigned _dos_setftime( int handle,
  5542.                                             unsigned short date,
  5543.                                             unsigned short time );
  5544.  
  5545. Description: The _dos_setftime function uses system call 0x57 to set the date 
  5546.           and time that the file associated with handle was last modified.  The 
  5547.           date consists of the year, month and day packed into 16 bits as 
  5548.           follows: 
  5549.  
  5550.    Bits      Meaning 
  5551.    bits 0-4  Day (1-31) 
  5552.    bits 5-8  Month (1-12) 
  5553.    bits 9-15 Year (0-119 representing 1980-2099) 
  5554.  
  5555.           The time consists of the hour, minute and seconds/2 packed into 16 
  5556.           bits as follows: 
  5557.  
  5558.    Bits      Meaning 
  5559.    bits 0-4  Seconds/2 (0-29) 
  5560.    bits 5-10 Minutes (0-59) 
  5561.    bits 11-15 Hours (0-23) 
  5562.  
  5563. Returns:  The _dos_setftime function returns zero if successful. Otherwise, it 
  5564.           returns an MS-DOS error code and sets errno to one of the following 
  5565.           values: 
  5566.  
  5567.    EBADF     Invalid file handle 
  5568.  
  5569. See Also: _dos_getftime 
  5570.  
  5571. Example: 
  5572.  
  5573.                     #include <stdio.h>
  5574.                     #include <dos.h>
  5575.                     #include <fcntl.h>
  5576.                     #define YEAR(t)   (((t & 0xFE00) >> 9) + 1980)
  5577.                     #define MONTH(t)  ((t & 0x01E0) >> 5)
  5578.                     #define DAY(t)    (t & 0x001F)
  5579.                     #define HOUR(t)   ((t & 0xF800) >> 11)
  5580.                     #define MINUTE(t) ((t & 0x07E0) >> 5)
  5581.                     #define SECOND(t) ((t & 0x001F) << 1)
  5582.                     void main()
  5583.                       {
  5584.                         int      handle;
  5585.                         unsigned short date, time;
  5586.                         if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
  5587.                           printf( "Unable to open file\n" );
  5588.                         } else {
  5589.                           printf( "Open succeeded\n" );
  5590.                           _dos_getftime( handle, &date, &time );
  5591.                           printf( "The file was last modified on %d/%d/%d",
  5592.                                   MONTH(date), DAY(date), YEAR(date) );
  5593.                           printf( " at %.2d:%.2d:%.2d\n",
  5594.                                   HOUR(time), MINUTE(time), SECOND(time) );
  5595.                           /* set the time to 12 noon */
  5596.                           time = (12 << 11) + (0 << 5) + 0;
  5597.                           _dos_setftime( handle, date, time );
  5598.                           _dos_getftime( handle, &date, &time );
  5599.                           printf( "The file was last modified on %d/%d/%d",
  5600.                                   MONTH(date), DAY(date), YEAR(date) );
  5601.                           printf( " at %.2d:%.2d:%.2d\n",
  5602.                                   HOUR(time), MINUTE(time), SECOND(time) );
  5603.                           _dos_close( handle );
  5604.                         }
  5605.                       }
  5606.  
  5607.           produces the following: 
  5608.  
  5609.                     Open succeeded
  5610.                     The file was last modified on 12/29/1989 at 14:32:46
  5611.                     The file was last modified on 12/29/1989 at 12:00:00
  5612.  
  5613. Classification: DOS 
  5614.  
  5615.  
  5616. ΓòÉΓòÉΓòÉ 83. _dos_settime ΓòÉΓòÉΓòÉ
  5617.  
  5618. Synopsis: 
  5619.  
  5620.                     #include <dos.h>
  5621.                     unsigned _dos_settime( struct dostime_t *time );
  5622.                     struct dostime_t {
  5623.                             unsigned char hour;     /* 0-23 */
  5624.                             unsigned char minute;   /* 0-59 */
  5625.                             unsigned char second;   /* 0-59 */
  5626.                             unsigned char hsecond;  /* 1/100 second; 0-99 */
  5627.                     };
  5628.  
  5629. Description: The _dos_settime function uses system call 0x2D to set the current 
  5630.           system time.  The time information is passed in a dostime_t structure 
  5631.           pointed to by time. 
  5632.  
  5633. Returns:  The _dos_settime function returns zero if successful. Otherwise, it 
  5634.           returns a non-zero value and sets errno to EINVAL indicating that an 
  5635.           invalid time was given. 
  5636.  
  5637. See Also: _dos_getdate, _dos_setdate, _dos_gettime, gmtime, localtime, mktime, 
  5638.           time 
  5639.  
  5640. Example: 
  5641.  
  5642.                     #include <stdio.h>
  5643.                     #include <dos.h>
  5644.                     void main()
  5645.                       {
  5646.                         struct dosdate_t date;
  5647.                         struct dostime_t time;
  5648.                         /* Get and display the current date and time */
  5649.                         _dos_getdate( &date );
  5650.                         _dos_gettime( &time );
  5651.                         printf( "The date (MM-DD-YYYY) is: %d-%d-%d\n",
  5652.                             date.month, date.day, date.year );
  5653.                         printf( "The time (HH:MM:SS) is: %.2d:%.2d:%.2d\n",
  5654.                             time.hour, time.minute, time.second );
  5655.                         /* Change it to the turn of the century */
  5656.                         date.year = 1999;
  5657.                         date.month = 12;
  5658.                         date.day = 31;
  5659.                         time.hour = 23;
  5660.                         time.minute = 59;
  5661.                         _dos_setdate( &date );
  5662.                         _dos_settime( &time );
  5663.                         printf( "New date (MM-DD-YYYY) is: %d-%d-%d\n",
  5664.                                       date.month, date.day, date.year );
  5665.                         printf( "New time (HH:MM:SS) is: %.2d:%.2d:%.2d\n",
  5666.                                       time.hour, time.minute, time.second );
  5667.                       }
  5668.  
  5669.           produces the following: 
  5670.  
  5671.                     The date (MM-DD-YYYY) is: 12-25-1989
  5672.                     The time (HH:MM:SS) is: 14:23:15
  5673.                     New date (MM-DD-YYYY) is: 12-31-1999
  5674.                     New time (HH:MM:SS) is: 23:59:16
  5675.  
  5676. Classification: DOS 
  5677.  
  5678.  
  5679. ΓòÉΓòÉΓòÉ 84. _dos_setvect ΓòÉΓòÉΓòÉ
  5680.  
  5681. Synopsis: 
  5682.  
  5683.                     #include <dos.h>
  5684.                     void _dos_setvect( unsigned intnum,
  5685.                                        void (__interrupt __far *handler)() );
  5686.  
  5687. Description: The _dos_setvect function sets interrupt vector number intnum to 
  5688.           point to the interrupt handling function pointed to by handler. 
  5689.  
  5690. Returns:  The function does not return a value. 
  5691.  
  5692. See Also: _chain_intr, _dos_getvect, _dos_keep 
  5693.  
  5694. Example: 
  5695.  
  5696.                     #include <stdio.h>
  5697.                     #include <dos.h>
  5698.  
  5699.                     volatile int clock_ticks;
  5700.                     void (__interrupt __far *prev_int_1c)();
  5701.                     #define BLIP_COUNT  (5*18)  /* 5 seconds */
  5702.                     void __interrupt __far timer_rtn()
  5703.                       {
  5704.                         ++clock_ticks;
  5705.                         _chain_intr( prev_int_1c );
  5706.                       }
  5707.  
  5708.                     int delays = 0;
  5709.                     void main()
  5710.                       {
  5711.                         prev_int_1c = _dos_getvect( 0x1c );
  5712.                         _dos_setvect( 0x1c, timer_rtn );
  5713.                         while( compile_a_line() ) {
  5714.                             if( clock_ticks >= BLIP_COUNT ) {
  5715.                                 putchar( '.' );
  5716.                                 clock_ticks -= BLIP_COUNT;
  5717.                             }
  5718.                         }
  5719.                         _dos_setvect( 0x1c, prev_int_1c );
  5720.                       }
  5721.                     int compile_a_line()
  5722.                       {
  5723.                         if( delays > 15 ) return( 0 );
  5724.                         delay( 1000 );  /* delay for 1 second */
  5725.                         printf( "Delayed for 1 second\n" );
  5726.                         delays++;
  5727.                         return( 1 );
  5728.                       }
  5729.  
  5730. Classification: WATCOM 
  5731.  
  5732.  
  5733. ΓòÉΓòÉΓòÉ 85. _dos_write ΓòÉΓòÉΓòÉ
  5734.  
  5735. Synopsis: 
  5736.  
  5737.                     #include <dos.h>
  5738.                     unsigned _dos_write( int handle, void __far *buffer,
  5739.                                          unsigned count, unsigned *bytes );
  5740.  
  5741. Description: The _dos_write function uses system call 0x40 to write count bytes 
  5742.           of data from the buffer pointed to by buffer to the file specified by 
  5743.           handle. The number of bytes successfully written will be stored in 
  5744.           the unsigned integer pointed to by bytes. 
  5745.  
  5746. Returns:  The _dos_write function returns zero if successful. Otherwise, it 
  5747.           returns an MS-DOS error code and sets errno to one of the following 
  5748.           values: 
  5749.  
  5750.    Constant  Meaning 
  5751.  
  5752.    EACCES    Access denied because the file is not open for write access 
  5753.  
  5754.    EBADF     Invalid file handle 
  5755.  
  5756. See Also: _dos_close, _dos_open, _dos_read 
  5757.  
  5758. Example: 
  5759.  
  5760.                     #include <stdio.h>
  5761.                     #include <dos.h>
  5762.                     #include <fcntl.h>
  5763.                     char buffer[] = "This is a test for _dos_write.";
  5764.                     void main()
  5765.                       {
  5766.                         unsigned len_written;
  5767.                         int      handle;
  5768.                         if( _dos_creat( "file", _A_NORMAL, &handle ) != 0 ) {
  5769.                           printf( "Unable to create file\n" );
  5770.                         } else {
  5771.                           printf( "Create succeeded\n" );
  5772.                           _dos_write( handle, buffer, sizeof(buffer),
  5773.                                       &len_written );
  5774.                           _dos_close( handle );
  5775.                         }
  5776.                       }
  5777.  
  5778. Classification: DOS 
  5779.  
  5780.  
  5781. ΓòÉΓòÉΓòÉ 86. dup ΓòÉΓòÉΓòÉ
  5782.  
  5783. Synopsis: 
  5784.  
  5785.                     #include <io.h>
  5786.                     int dup( int handle );
  5787.  
  5788. Description: The dup function duplicates the file handle given by the argument 
  5789.           handle. The new file handle refers to the same open file handle as 
  5790.           the original file handle, and shares any locks.  The new file handle 
  5791.           is identical to the original in that it references the same file or 
  5792.           device, it has the same open mode (read and/or write) and it will 
  5793.           have file position identical to the original.  Changing the position 
  5794.           with one handle will result in a changed position in the other. 
  5795.  
  5796. Returns:  If successful, the new file handle is returned to be used with the 
  5797.           other functions which operate on the file.  Otherwise, -1 is returned 
  5798.           and errno is set to indicate the error. 
  5799.  
  5800. Errors:   When an error has occurred, errno contains a value indicating the 
  5801.           type of error that has been detected. 
  5802.  
  5803.    Constant  Meaning 
  5804.  
  5805.    EBADF     The argument handle is not a valid open file handle. 
  5806.  
  5807.    EMFILE    The number of file handles would exceed {OPEN_MAX}. 
  5808.  
  5809. See Also: close, creat, dup2, eof, exec Functions, filelength, fileno, fstat, 
  5810.           isatty, lseek, open, read, setmode, sopen, stat, tell, write, umask 
  5811.  
  5812. Example: 
  5813.  
  5814.                     #include <fcntl.h>
  5815.                     #include <io.h>
  5816.                     void main()
  5817.                       {
  5818.                         int handle, dup_handle;
  5819.                         handle = open( "file",
  5820.                                     O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
  5821.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  5822.  
  5823.                         if( handle != -1 ) {
  5824.                           dup_handle = dup( handle );
  5825.                           if( dup_handle != -1 ) {
  5826.  
  5827.                             /* process file */
  5828.  
  5829.                             close( dup_handle );
  5830.                           }
  5831.                           close( handle );
  5832.                         }
  5833.                       }
  5834.  
  5835. Classification: POSIX 1003.1 
  5836.  
  5837.  
  5838. ΓòÉΓòÉΓòÉ 87. dup2 ΓòÉΓòÉΓòÉ
  5839.  
  5840. Synopsis: 
  5841.  
  5842.                     #include <io.h>
  5843.                     int dup2( int handle, int handle2 );
  5844.  
  5845. Description: The dup2 function duplicates the file handle given by the argument 
  5846.           handle. The new file handle is identical to the original in that it 
  5847.           references the same file or device, it has the same open mode (read 
  5848.           and/or write) and it will have identical file position to the 
  5849.           original (changing the position with one handle will result in a 
  5850.           changed position in the other). 
  5851.  
  5852.           The number of the new handle is handle2. If a file already is opened 
  5853.           with this handle, the file is closed before the duplication is 
  5854.           attempted. 
  5855.  
  5856. Returns:  The dup2 function returns zero if successful.  Otherwise, -1 is 
  5857.           returned and errno is set to indicate the error. 
  5858.  
  5859. Errors:   When an error has occurred, errno contains a value indicating the 
  5860.           type of error that has been detected. 
  5861.  
  5862.    Constant  Meaning 
  5863.  
  5864.    EBADF     The argument handle is not a valid open file handle or handle2 is 
  5865.              out of range. 
  5866.  
  5867.    EMFILE    The number of file handles would exceed {OPEN_MAX}, or no file 
  5868.              handles above handle2 are available. 
  5869.  
  5870. See Also: close, creat, dup, eof, exec Functions, filelength, fileno, fstat, 
  5871.           isatty, lseek, open, read, setmode, sopen, stat, tell, write, umask 
  5872.  
  5873. Example: 
  5874.  
  5875.                     #include <fcntl.h>
  5876.                     #include <io.h>
  5877.  
  5878.                     void main()
  5879.                       {
  5880.                         int handle, dup_handle;
  5881.  
  5882.                         handle = open( "file",
  5883.                                     O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
  5884.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  5885.                         if( handle != -1 ) {
  5886.                           dup_handle = 4;
  5887.                           if( dup2( handle, dup_handle ) != -1 ) {
  5888.  
  5889.                             /* process file */
  5890.  
  5891.                             close( dup_handle );
  5892.                           }
  5893.                           close( handle );
  5894.                         }
  5895.                       }
  5896.  
  5897. Classification: POSIX 1003.1 
  5898.  
  5899.  
  5900. ΓòÉΓòÉΓòÉ 88. ecvt ΓòÉΓòÉΓòÉ
  5901.  
  5902. Synopsis: 
  5903.  
  5904.                     #include <stdlib.h>
  5905.                     char *ecvt( double value,
  5906.                                 int ndigits,
  5907.                                 int *dec,
  5908.                                 int *sign );
  5909.  
  5910. Description: The ecvt function converts the floating-point number value into a 
  5911.           character string.  The parameter ndigits specifies the number of 
  5912.           significant digits desired.  The converted number will be rounded to 
  5913.           ndigits of precision. 
  5914.  
  5915.           The character string will contain only digits and is terminated by a 
  5916.           null character.  The integer pointed to by dec will be filled in with 
  5917.           a value indicating the position of the decimal point relative to the 
  5918.           start of the string of digits.  A zero or negative value indicates 
  5919.           that the decimal point lies to the left of the first digit.  The 
  5920.           integer pointed to by sign will contain 0 if the number is positive, 
  5921.           and non-zero if the number is negative. 
  5922.  
  5923. Returns:  The ecvt function returns a pointer to a static buffer containing the 
  5924.           converted string of digits.  Note:  ecvt and fcvt both use the same 
  5925.           static buffer. 
  5926.  
  5927. See Also: fcvt, gcvt, printf 
  5928.  
  5929. Example: 
  5930.  
  5931.                     #include <stdio.h>
  5932.                     #include <stdlib.h>
  5933.  
  5934.                     void main()
  5935.                       {
  5936.                          char *str;
  5937.                          int  dec, sign;
  5938.  
  5939.                          str = ecvt( 123.456789, 6, &dec, &sign );
  5940.                          printf( "str=%s, dec=%d, sign=%d\n", str,dec,sign );
  5941.                       }
  5942.  
  5943.           produces the following: 
  5944.  
  5945.                     str=123457, dec=3, sign=0
  5946.  
  5947. Classification: WATCOM 
  5948.  
  5949.  
  5950. ΓòÉΓòÉΓòÉ 89. _enable ΓòÉΓòÉΓòÉ
  5951.  
  5952. Synopsis: 
  5953.  
  5954.                     #include <dos.h>
  5955.                     void _enable( void );
  5956.  
  5957. Description: The _enable function causes interrupts to become enabled. 
  5958.  
  5959.           The _enable function would be used in conjunction with the _disable 
  5960.           function to make sure that a sequence of instructions are executed 
  5961.           without any intervening interrupts occurring. 
  5962.  
  5963. Returns:  The _enable function returns no value. 
  5964.  
  5965. See Also: _disable 
  5966.  
  5967. Example: 
  5968.  
  5969.                     #include <stdio.h>
  5970.                     #include <stdlib.h>
  5971.                     #include <dos.h>
  5972.                     struct list_entry {
  5973.                         struct list_entry *next;
  5974.                         int    data;
  5975.                     };
  5976.                     struct list_entry *ListHead = NULL;
  5977.                     struct list_entry *ListTail = NULL;
  5978.                     void main()
  5979.                       {
  5980.                         struct list_entry *p;
  5981.                         int i;
  5982.  
  5983.                         for( i = 1; i <= 10; i++ ) {
  5984.                           p = malloc( sizeof( struct list_entry ) );
  5985.                           if( p == NULL ) break;
  5986.                           p->data = i;
  5987.                           insert( p );
  5988.                         }
  5989.                       }
  5990.                     void insert( struct list_entry *new_entry )
  5991.                       {
  5992.                         /* insert new_entry at end of linked list */
  5993.                         new_entry->next = NULL;
  5994.                         _disable();       /* disable interrupts */
  5995.                         if( ListTail == NULL ) {
  5996.                           ListHead = new_entry;
  5997.                         } else {
  5998.                           ListTail->next = new_entry;
  5999.                         }
  6000.                         ListTail = new_entry;
  6001.                         _enable();        /* enable interrupts now */
  6002.                       }
  6003.  
  6004. Classification: Intel 
  6005.  
  6006.  
  6007. ΓòÉΓòÉΓòÉ 90. _endthread ΓòÉΓòÉΓòÉ
  6008.  
  6009. Synopsis: 
  6010.  
  6011.                     #include <process.h>
  6012.                     void __far _endthread(void);
  6013.  
  6014. Description: The _endthread function uses the OS/2 function DosExit to end the 
  6015.           current thread of execution. 
  6016.  
  6017. Returns:  The _endthread function does not return any value. 
  6018.  
  6019. See Also: _beginthread 
  6020.  
  6021. Example: 
  6022.  
  6023.                     #include <stdio.h>
  6024.                     #include <stdlib.h>
  6025.                     #include <process.h>
  6026.                     #define  STACK_SIZE   4096
  6027.                     void __far child( char * __far *argv )
  6028.                       {
  6029.                         int  i;
  6030.                         for( i = 0; argv[i]; i++ ) {
  6031.                           printf( "argv[%d] = %s\n", i, argv[i] );
  6032.                         }
  6033.                         _endthread();
  6034.                       }
  6035.                     void main()
  6036.                       {
  6037.                         char *stack;
  6038.                         char *args[3];
  6039.                         int   tid;
  6040.                         args[0] = "child";
  6041.                         args[1] = "parm";
  6042.                         args[2] = NULL;
  6043.                         stack = malloc( STACK_SIZE );
  6044.                         tid = _beginthread( child, stack, STACK_SIZE, args );
  6045.                       }
  6046.  
  6047. Classification: OS/2 
  6048.  
  6049.  
  6050. ΓòÉΓòÉΓòÉ 91. eof ΓòÉΓòÉΓòÉ
  6051.  
  6052. Synopsis: 
  6053.  
  6054.                     #include <io.h>
  6055.                     int eof( int handle );
  6056.  
  6057. Description: The eof function determines, at the operating system level, if the 
  6058.           end of the file has been reached for the file whose file handle is 
  6059.           given by handle. Because the current file position is set following 
  6060.           an input operation, the eof function may be called to detect the end 
  6061.           of the file before an input operation beyond the end of the file is 
  6062.           attempted. 
  6063.  
  6064. Returns:  The eof function returns 1 if the current file position is at the end 
  6065.           of the file, 0 if the current file position is not at the end.  A 
  6066.           return value of -1 indicates an error, and in this case errno is set 
  6067.           to indicate the error. 
  6068.  
  6069. Errors:   When an error has occurred, errno contains a value indicating the 
  6070.           type of error that has been detected. 
  6071.  
  6072.    EBADF     The handle argument is not a valid file handle. 
  6073.  
  6074. See Also: read 
  6075.  
  6076. Example: 
  6077.  
  6078.                     #include <stdio.h>
  6079.                     #include <fcntl.h>
  6080.                     #include <io.h>
  6081.  
  6082.                     void main()
  6083.                       {
  6084.                         int handle, len;
  6085.                         char buffer[100];
  6086.  
  6087.                         handle = open( "file", O_RDONLY );
  6088.                         if( handle != -1 ) {
  6089.                           while( ! eof( handle ) ) {
  6090.                             len = read( handle, buffer, sizeof(buffer) - 1 );
  6091.                             buffer[ len ] = '\0';
  6092.                             printf( "%s", buffer );
  6093.                           }
  6094.                           close( handle );
  6095.                         }
  6096.                       }
  6097.  
  6098. Classification: WATCOM 
  6099.  
  6100.  
  6101. ΓòÉΓòÉΓòÉ 92. exec Functions ΓòÉΓòÉΓòÉ
  6102.  
  6103. Synopsis: 
  6104.  
  6105.                     #include <process.h>
  6106.                     int execl(   path, arg0, arg1..., argn, NULL );
  6107.                     int execle(  path, arg0, arg1..., argn, NULL, envp );
  6108.                     int execlp(  file, arg0, arg1..., argn, NULL );
  6109.                     int execlpe( file, arg0, arg1..., argn, NULL, envp );
  6110.                     int execv(   path, argv );
  6111.                     int execve(  path, argv, envp );
  6112.                     int execvp(  file, argv );
  6113.                     int execvpe( file, argv, envp );
  6114.                       const char *path;             /* file name incl. path */
  6115.                       const char *file;             /* file name            */
  6116.                       const char *arg0, ..., *argn; /* arguments            */
  6117.                       char *const argv[];           /* array of arguments   */
  6118.                       char *const envp[];           /* environment strings  */
  6119.  
  6120. Description: The exec functions load and execute a new child process, named by 
  6121.           path or file. If the child process is successfully loaded, it 
  6122.           replaces the current process in memory.  No return is made to the 
  6123.           original program. 
  6124.  
  6125.           The program is located by using the following logic in sequence: 
  6126.  
  6127.     1. An attempt is made to locate the program in the current working 
  6128.        directory if no directory specification precedes the program name; 
  6129.        otherwise, an attempt is made in the specified directory. 
  6130.  
  6131.     2. If no file extension is given, an attempt is made to find the program 
  6132.        name, in the directory indicated in the first point, with .COM 
  6133.        concatenated to the end of the program name. 
  6134.  
  6135.     3. If no file extension is given, an attempt is made to find the program 
  6136.        name, in the directory indicated in the first point, with .EXE 
  6137.        concatenated to the end of the program name. 
  6138.  
  6139.     4. When no directory specification is given as part of the program name, 
  6140.        the execlp, execlpe, execvp, and execvpe functions will repeat the 
  6141.        preceding three steps for each of the directories specified by the PATH 
  6142.        environment variable. The command 
  6143.  
  6144.               path c:\myapps;d:\lib\applns
  6145.  
  6146.        indicates that the two directories 
  6147.  
  6148.               c:\myapps
  6149.               d:\lib\applns
  6150.  
  6151.        are to be searched.  The DOS path command (without any directory 
  6152.        specification) will cause the current path definition to be displayed. 
  6153.  
  6154.           An error is detected when the program cannot be found. 
  6155.  
  6156.           Arguments are passed to the child process by supplying one or more 
  6157.           pointers to character strings as arguments in the exec call.  These 
  6158.           character strings are concatenated with spaces inserted to separate 
  6159.           the arguments to form one argument string for the child process.  The 
  6160.           length of this concatenated string must not exceed 128 bytes for DOS 
  6161.           systems. 
  6162.  
  6163.           The arguments may be passed as a list of arguments (execl, execle, 
  6164.           execlp, and execlpe) or as a vector of pointers (execv, execve, 
  6165.           execvp, and execvpe).  At least one argument, arg0 or argv[0] , must 
  6166.           be passed to the child process.  By convention, this first argument 
  6167.           is a pointer to the name of the program. 
  6168.  
  6169.           If the arguments are passed as a list, there must be a NULL pointer 
  6170.           to mark the end of the argument list.  Similarly, if a pointer to an 
  6171.           argument vector is passed, the argument vector must be terminated by 
  6172.           a NULL pointer. 
  6173.  
  6174.           The environment for the invoked program is inherited from the parent 
  6175.           process when you use the execl, execlp, execv, and execvp functions. 
  6176.           The execle, execlpe, execve, and execvpe functions allow a different 
  6177.           environment to be passed to the child process through the envp 
  6178.           argument.  The argument envp is a pointer to an array of character 
  6179.           pointers, each of which points to a string defining an environment 
  6180.           variable.  The array is terminated with a NULL pointer.  Each pointer 
  6181.           locates a character string of the form 
  6182.  
  6183.                         variable=value
  6184.  
  6185.           that is used to define an environment variable.  If the value of envp 
  6186.           is NULL , then the child process inherits the environment of the 
  6187.           parent process. 
  6188.  
  6189.           The environment is the collection of environment variables whose 
  6190.           values have been defined with the DOS SET command or by the 
  6191.           successful execution of the putenv function.  A program may read 
  6192.           these values with the getenv function. 
  6193.  
  6194.           The execvpe and execlpe functions are extensions to POSIX 1003.1. 
  6195.  
  6196. Returns:  When the invoked program is successfully initiated, no return occurs. 
  6197.           When an error is detected while invoking the indicated program, exec 
  6198.           returns -1 and errno is set to indicate the error. 
  6199.  
  6200. Errors:   When an error has occurred, errno contains a value indicating the 
  6201.           type of error that has been detected. 
  6202.  
  6203.    Constant      Meaning 
  6204.    E2BIG         The argument list exceeds 128 bytes, or the space required for 
  6205.                  the environment information exceeds 32K. 
  6206.    EACCES        The specified file has a locking or sharing violation. 
  6207.    EMFILE        Too many files open 
  6208.    ENOENT        Path or file not found 
  6209.    ENOMEM        Not enough memory is available to execute the child process. 
  6210.  
  6211. See Also: abort, atexit, exit, _exit, getcmd, getenv, main, putenv, spawn 
  6212.           Functions, system 
  6213.  
  6214. Example: 
  6215.  
  6216.                     #include <stddef.h>
  6217.                     #include <process.h>
  6218.  
  6219.                     execl( "myprog",
  6220.                             "myprog", "ARG1", "ARG2", NULL );
  6221.  
  6222.           The preceding invokes "myprog" as if 
  6223.  
  6224.                     myprog ARG1 ARG2
  6225.  
  6226.           had been entered as a command to DOS.  The program will be found if 
  6227.           one of 
  6228.  
  6229.                     myprog.
  6230.                     myprog.com
  6231.                     myprog.exe
  6232.  
  6233.           is found in the current working directory. 
  6234.  
  6235.                     #include <stddef.h>
  6236.                     #include <process.h>
  6237.  
  6238.                     char *env_list[] = { "SOURCE=MYDATA",
  6239.                                          "TARGET=OUTPUT",
  6240.                                          "lines=65",
  6241.                                          NULL
  6242.                                         };
  6243.  
  6244.                     execle( "myprog",
  6245.                             "myprog", "ARG1", "ARG2", NULL,
  6246.                              env_list );
  6247.  
  6248.           The preceding invokes "myprog" as if 
  6249.  
  6250.                     myprog ARG1 ARG2
  6251.  
  6252.           had been entered as a command to DOS.  The program will be found if 
  6253.           one of 
  6254.  
  6255.                     myprog.
  6256.                     myprog.com
  6257.                     myprog.exe
  6258.  
  6259.           is found in the current working directory.  The DOS environment for 
  6260.           the invoked program will consist of the three environment variables 
  6261.           SOURCE, TARGET and lines. 
  6262.  
  6263.                     #include <stddef.h>
  6264.                     #include <process.h>
  6265.  
  6266.                     char *arg_list[] = { "myprog", "ARG1", "ARG2", NULL };
  6267.  
  6268.                     execv( "myprog", arg_list );
  6269.  
  6270.           The preceding invokes "myprog" as if 
  6271.  
  6272.                     myprog ARG1 ARG2
  6273.  
  6274.           had been entered as a command to DOS.  The program will be found if 
  6275.           one of 
  6276.  
  6277.                     myprog.
  6278.                     myprog.com
  6279.                     myprog.exe
  6280.  
  6281.           is found in the current working directory. 
  6282.  
  6283. Classification: POSIX 1003.1 with extensions 
  6284.  
  6285.  
  6286. ΓòÉΓòÉΓòÉ 93. _exit ΓòÉΓòÉΓòÉ
  6287.  
  6288. Synopsis: 
  6289.  
  6290.                     #include <stdlib.h>
  6291.                     void _exit( int status );
  6292.  
  6293. Description: The _exit function causes normal program termination to occur. 
  6294.  
  6295.     1. The functions registered by the atexit or onexit functions are not 
  6296.        called. 
  6297.  
  6298.     2. Any unopened files are not closed and any buffered output is not flushed 
  6299.        to the associated files or devices. 
  6300.  
  6301.     3. Any files created by tmpfile are not removed. 
  6302.  
  6303.     4. The return status is made available to the parent process.  Only the low 
  6304.        order byte of status is available on DOS systems.  The status value is 
  6305.        typically set to 0 to indicate successful termination and set to some 
  6306.        other value to indicate an error. 
  6307.  
  6308. Returns:  The _exit function does not return to its caller. 
  6309.  
  6310. See Also: abort, atexit, exec Functions, exit, getcmd, getenv, main, onexit, 
  6311.           putenv, spawn Functions, system 
  6312.  
  6313. Example: 
  6314.  
  6315.                     #include <stdio.h>
  6316.                     #include <stdlib.h>
  6317.                     void main( int argc, char *argv[] )
  6318.                       {
  6319.                         FILE *fp;
  6320.                         if( argc <= 1 ) {
  6321.                           fprintf( stderr, "Missing argument\n" );
  6322.                           exit( EXIT_FAILURE );
  6323.                         }
  6324.                         fp = fopen( argv[1], "r" );
  6325.                         if( fp == NULL ) {
  6326.                           fprintf( stderr, "Unable to open '%s'\n", argv[1] );
  6327.                           _exit( EXIT_FAILURE );
  6328.                         }
  6329.                         fclose( fp );
  6330.                         _exit( EXIT_SUCCESS );
  6331.                       }
  6332.  
  6333. Classification: POSIX 1003.1 
  6334.  
  6335.  
  6336. ΓòÉΓòÉΓòÉ 94. exit ΓòÉΓòÉΓòÉ
  6337.  
  6338. Synopsis: 
  6339.  
  6340.                     #include <stdlib.h>
  6341.                     void exit( int status );
  6342.  
  6343. Description: The exit function causes normal program termination to occur. 
  6344.  
  6345.           First, all functions registered by the atexit function are called in 
  6346.           the reverse order of their registration.  Next, all open files are 
  6347.           flushed and closed, and all files created by the tmpfile function are 
  6348.           removed.  Finally, the return status is made available to the parent 
  6349.           process.  Only the low order byte of status is available on DOS 
  6350.           systems.  The status value is typically set to 0 to indicate 
  6351.           successful termination and set to some other value to indicate an 
  6352.           error. 
  6353.  
  6354. Returns:  The exit function does not return to its caller. 
  6355.  
  6356. See Also: abort, atexit, _exit, onexit 
  6357.  
  6358. Example: 
  6359.  
  6360.                     #include <stdio.h>
  6361.                     #include <stdlib.h>
  6362.  
  6363.                     void main( int argc, char *argv[] )
  6364.                       {
  6365.                         FILE *fp;
  6366.  
  6367.                         if( argc < 1 ) {
  6368.                           fprintf( stderr, "Missing argument\n" );
  6369.                           exit( EXIT_FAILURE );
  6370.                         }
  6371.                         fp = fopen( argv[1], "r" );
  6372.                         if( fp == NULL ) {
  6373.                           fprintf( stderr, "Unable to open '%s'\n",
  6374.                                    argv[1] );
  6375.                           exit( EXIT_FAILURE );
  6376.                         }
  6377.                         exit( EXIT_SUCCESS );
  6378.                       }
  6379.  
  6380. Classification: ANSI 
  6381.  
  6382.  
  6383. ΓòÉΓòÉΓòÉ 95. exp ΓòÉΓòÉΓòÉ
  6384.  
  6385. Synopsis: 
  6386.  
  6387.                     #include <math.h>
  6388.                     double exp( double x );
  6389.  
  6390. Description: The exp function computes the exponential function of x. A range 
  6391.           error occurs if the magnitude of x is too large. 
  6392.  
  6393. Returns:  The exp function returns the exponential value.  When the argument is 
  6394.           outside the permissible range, the matherr function is called. 
  6395.           Unless the default matherr function is replaced, it will set the 
  6396.           global variable errno to ERANGE, and print a "RANGE error" diagnostic 
  6397.           message using the stderr stream. 
  6398.  
  6399. See Also: log, matherr 
  6400.  
  6401. Example: 
  6402.  
  6403.                     #include <stdio.h>
  6404.                     #include <math.h>
  6405.  
  6406.                     void main()
  6407.                       {
  6408.                         printf( "%f\n", exp(.5) );
  6409.                       }
  6410.  
  6411.           produces the following: 
  6412.  
  6413.                     1.648721
  6414.  
  6415. Classification: ANSI 
  6416.  
  6417.  
  6418. ΓòÉΓòÉΓòÉ 96. _expand Functions ΓòÉΓòÉΓòÉ
  6419.  
  6420. Synopsis: 
  6421.  
  6422.                     #include <malloc.h>
  6423.                     void        * _expand( void *mem_blk, size_t size );
  6424.                     void __based(void) *_bexpand( __segment seg,
  6425.                                                   void __based(void) *mem_blk,
  6426.                                                   size_t size);
  6427.                     void __far  *_fexpand(void __far  *mem_blk,size_t size);
  6428.                     void __near *_nexpand(void __near *mem_blk,size_t size);
  6429.  
  6430. Description: The _expand functions change the size of the previously allocated 
  6431.           block pointed to by mem_blk by attempting to expand or contract the 
  6432.           memory block without moving its location in the heap.  The argument 
  6433.           size specifies the new desired size for the memory block.  The 
  6434.           contents of the memory block are unchanged up to the shorter of the 
  6435.           new and old sizes. 
  6436.  
  6437.           Each function expands the memory from a particular heap, as listed 
  6438.           below: 
  6439.  
  6440.    Function      Heap Expanded 
  6441.    _expand       Depends on data model of the program 
  6442.    _bexpand      Based heap specified by seg value 
  6443.    _fexpand      Far heap (outside the default data segment) 
  6444.    _nexpand      Near heap (inside the default data segment) 
  6445.  
  6446.           In a small data memory model, the _expand function is equivalent to 
  6447.           the _nexpand function; in a large data memory model, the _expand 
  6448.           function is equivalent to the _fexpand function. 
  6449.  
  6450. Returns:  The _expand functions return the value mem_blk if it was successful 
  6451.           in changing the size of the block.  The return value is NULL ( 
  6452.           _NULLOFF for _bexpand) if the memory block could not be expanded to 
  6453.           the desired size.  It will be expanded as much as possible in this 
  6454.           case. 
  6455.  
  6456.           The appropriate _msize function can be used to determine the new size 
  6457.           of the expanded block. 
  6458.  
  6459. See Also: calloc Functions, free Functions, halloc, hfree, malloc Functions, 
  6460.           _msize Functions, realloc Functions, sbrk 
  6461.  
  6462. Example: 
  6463.  
  6464.                     #include <stdio.h>
  6465.                     #include <malloc.h>
  6466.                     main()
  6467.                       {
  6468.                         char *buf;
  6469.                         char __far *buf2;
  6470.                         buf = malloc( 80 );
  6471.                         printf( "Size of buffer is %u\n", _msize(buf) );
  6472.                         if( _expand( buf, 100 ) == NULL ) {
  6473.                             printf( "Unable to expand buffer\n" );
  6474.                         }
  6475.                         printf( "New size of buffer is %u\n", _msize(buf) );
  6476.                         buf2 = _fmalloc( 2000 );
  6477.                         printf( "Size of far buffer is %u\n", _fmsize(buf2) );
  6478.                         if( _fexpand( buf2, 8000 ) == NULL ) {
  6479.                             printf( "Unable to expand far buffer\n" );
  6480.                         }
  6481.                         printf( "New size of far buffer is %u\n",
  6482.                                  _fmsize(buf2) );
  6483.                       }
  6484.  
  6485.           produces the following: 
  6486.  
  6487.                     Size of buffer is 80
  6488.                     Unable to expand buffer
  6489.                     New size of buffer is 80
  6490.                     Size of far buffer is 2000
  6491.                     New size of far buffer is 8000
  6492.  
  6493. Classification: WATCOM 
  6494.  
  6495.  
  6496. ΓòÉΓòÉΓòÉ 97. fabs ΓòÉΓòÉΓòÉ
  6497.  
  6498. Synopsis: 
  6499.  
  6500.                     #include <math.h>
  6501.                     double fabs( double x );
  6502.  
  6503. Description: The fabs function computes the absolute value of the argument x. 
  6504.  
  6505. Returns:  The fabs function returns the absolute value of x. 
  6506.  
  6507. See Also: abs, labs 
  6508.  
  6509. Example: 
  6510.  
  6511.                     #include <stdio.h>
  6512.                     #include <math.h>
  6513.  
  6514.                     void main()
  6515.                       {
  6516.                         printf( "%f %f\n", fabs(.5), fabs(-.5) );
  6517.                       }
  6518.  
  6519.           produces the following: 
  6520.  
  6521.                     0.500000 0.500000
  6522.  
  6523. Classification: ANSI 
  6524.  
  6525.  
  6526. ΓòÉΓòÉΓòÉ 98. fclose ΓòÉΓòÉΓòÉ
  6527.  
  6528. Synopsis: 
  6529.  
  6530.                     #include <stdio.h>
  6531.                     int fclose( FILE *fp );
  6532.  
  6533. Description: The fclose function closes the file fp. If there was any unwritten 
  6534.           buffered data for the file, it is written out before the file is 
  6535.           closed.  Any unread buffered data is discarded.  If the associated 
  6536.           buffer was automatically allocated, it is deallocated. 
  6537.  
  6538. Returns:  The fclose function returns zero if the file was successfully closed, 
  6539.           or non-zero if any errors were detected.  When an error has occurred, 
  6540.           errno contains a value indicating the type of error that has been 
  6541.           detected. 
  6542.  
  6543. See Also: fcloseall, fdopen, fopen, freopen 
  6544.  
  6545. Example: 
  6546.  
  6547.                     #include <stdio.h>
  6548.  
  6549.                     void main()
  6550.                       {
  6551.                         FILE *fp;
  6552.  
  6553.                         fp = fopen( "stdio.h", "r" );
  6554.                         if( fp != NULL ) {
  6555.                             fclose( fp );
  6556.                         }
  6557.                       }
  6558.  
  6559. Classification: ANSI 
  6560.  
  6561.  
  6562. ΓòÉΓòÉΓòÉ 99. fcloseall ΓòÉΓòÉΓòÉ
  6563.  
  6564. Synopsis: 
  6565.  
  6566.                     #include <stdio.h>
  6567.                     int fcloseall( void );
  6568.  
  6569. Description: The fcloseall function closes all open stream files, except stdin, 
  6570.           stdout, stderr, stdaux, and stdprn. This includes streams created 
  6571.           (and not yet closed) by fdopen, fopen and freopen. 
  6572.  
  6573. Returns:  The fcloseall function returns the number of streams that were closed 
  6574.           if no errors were encountered.  When an error occurs, EOF is 
  6575.           returned. 
  6576.  
  6577. See Also: fclose, fdopen, fopen, freopen 
  6578.  
  6579. Example: 
  6580.  
  6581.                     #include <stdio.h>
  6582.  
  6583.                     void main()
  6584.                       {
  6585.                         printf( "The number of files closed is %d\n",
  6586.                                 fcloseall() );
  6587.                       }
  6588.  
  6589. Classification: WATCOM 
  6590.  
  6591.  
  6592. ΓòÉΓòÉΓòÉ 100. fcvt ΓòÉΓòÉΓòÉ
  6593.  
  6594. Synopsis: 
  6595.  
  6596.                     #include <stdlib.h>
  6597.                     char *fcvt( double value,
  6598.                                 int ndigits,
  6599.                                 int *dec,
  6600.                                 int *sign );
  6601.  
  6602. Description: The fcvt function converts the floating-point number value into a 
  6603.           character string.  The parameter ndigits specifies the number of 
  6604.           digits desired after the decimal point.  The converted number will be 
  6605.           rounded to this position. 
  6606.  
  6607.           The character string will contain only digits and is terminated by a 
  6608.           null character.  The integer pointed to by dec will be filled in with 
  6609.           a value indicating the position of the decimal point relative to the 
  6610.           start of the string of digits.  A zero or negative value indicates 
  6611.           that the decimal point lies to the left of the first digit.  The 
  6612.           integer pointed to by sign will contain 0 if the number is positive, 
  6613.           and non-zero if the number is negative. 
  6614.  
  6615. Returns:  The fcvt function returns a pointer to a static buffer containing the 
  6616.           converted string of digits.  Note:  ecvt and fcvt both use the same 
  6617.           static buffer. 
  6618.  
  6619. See Also: ecvt, gcvt, printf 
  6620.  
  6621. Example: 
  6622.  
  6623.                     #include <stdio.h>
  6624.                     #include <stdlib.h>
  6625.  
  6626.                     void main()
  6627.                       {
  6628.                          char *str;
  6629.                          int  dec, sign;
  6630.  
  6631.                          str = fcvt( -123.456789, 5, &dec, &sign );
  6632.                          printf( "str=%s, dec=%d, sign=%d\n", str,dec,sign );
  6633.                       }
  6634.  
  6635.           produces the following: 
  6636.  
  6637.                     str=12345679, dec=3, sign=-1
  6638.  
  6639. Classification: WATCOM 
  6640.  
  6641.  
  6642. ΓòÉΓòÉΓòÉ 101. fdopen ΓòÉΓòÉΓòÉ
  6643.  
  6644. Synopsis: 
  6645.  
  6646.                     #include <stdio.h>
  6647.                     FILE *fdopen( int handle, const char *mode );
  6648.  
  6649. Description: The fdopen function associates a stream with the file handle 
  6650.           handle which represents an opened file or device.  The handle was 
  6651.           returned by one of creat, dup, dup2 or open. The open mode mode must 
  6652.           match the mode with which the file or device was originally opened. 
  6653.  
  6654.           The argument mode is described in the description of the fopen 
  6655.           function. 
  6656.  
  6657. Returns:  The fdopen function returns a pointer to the object controlling the 
  6658.           stream.  This pointer must be passed as a parameter to subsequent 
  6659.           functions for performing operations on the file.  If the open 
  6660.           operation fails, fdopen returns a NULL pointer.  When an error has 
  6661.           occurred, errno contains a value indicating the type of error that 
  6662.           has been detected. 
  6663.  
  6664. See Also: creat, dup, dup2, fopen, freopen, open, sopen 
  6665.  
  6666. Example: 
  6667.  
  6668.                     #include <stdio.h>
  6669.                     #include <fcntl.h>
  6670.  
  6671.                     void main()
  6672.                       {
  6673.                         int handle;
  6674.                         FILE *fp;
  6675.  
  6676.                         handle = open( "file", O_RDONLY | O_TEXT );
  6677.                         if( handle != -1 ) {
  6678.                           fp = fdopen( handle, "r" );
  6679.                           if( fp != NULL ) {
  6680.                               fclose( fp );
  6681.                           }
  6682.                           close( handle );
  6683.                         }
  6684.                       }
  6685.  
  6686. Classification: POSIX 1003.1 
  6687.  
  6688.  
  6689. ΓòÉΓòÉΓòÉ 102. feof ΓòÉΓòÉΓòÉ
  6690.  
  6691. Synopsis: 
  6692.  
  6693.                     #include <stdio.h>
  6694.                     int feof( FILE *fp );
  6695.  
  6696. Description: The feof function tests the end-of-file indicator for the stream 
  6697.           pointed to by fp. Because this indicator is set when an input 
  6698.           operation attempts to read past the end of the file the feof function 
  6699.           will detect the end of the file only after an attempt is made to read 
  6700.           beyond the end of the file. Thus, if a file contains 10 lines, the 
  6701.           feof will not detect end of file after the tenth line is read; it 
  6702.           will detect end of file once the program attempts to read more data. 
  6703.  
  6704. Returns:  The feof function returns non-zero if the end-of-file indicator is 
  6705.           set for fp. 
  6706.  
  6707. See Also: clearerr, fopen, freopen, read, ferror, perror 
  6708.  
  6709. Example: 
  6710.  
  6711.                     #include <stdio.h>
  6712.  
  6713.                     void main()
  6714.                       {
  6715.                         FILE *fp;
  6716.                         char buffer[100];
  6717.  
  6718.                         fp = fopen( "file", "r" );
  6719.                         fgets( buffer, sizeof( buffer ), fp );
  6720.                         while( ! feof( fp ) ) {
  6721.                           process_record( buffer );
  6722.                           fgets( buffer, sizeof( buffer ), fp );
  6723.                         }
  6724.                         fclose( fp );
  6725.                       }
  6726.  
  6727.                     void process_record( char *buf )
  6728.                       {
  6729.                         printf( "%s\n", buf );
  6730.                       }
  6731.  
  6732. Classification: ANSI 
  6733.  
  6734.  
  6735. ΓòÉΓòÉΓòÉ 103. ferror ΓòÉΓòÉΓòÉ
  6736.  
  6737. Synopsis: 
  6738.  
  6739.                     #include <stdio.h>
  6740.                     int ferror( FILE *fp );
  6741.  
  6742. Description: The ferror function tests the error indicator for the stream 
  6743.           pointed to by fp. 
  6744.  
  6745. Returns:  The ferror function returns non-zero if the error indicator is set 
  6746.           for fp. 
  6747.  
  6748. See Also: clearerr, feof, perror, strerror 
  6749.  
  6750. Example: 
  6751.  
  6752.                     #include <stdio.h>
  6753.  
  6754.                     void main()
  6755.                       {
  6756.                         FILE *fp;
  6757.                         int c;
  6758.  
  6759.                         fp = fopen( "myfile.dat", "r" );
  6760.                         c = fgetc( fp );
  6761.                         if( ferror( fp ) ) {
  6762.                             printf( "Error reading file\n" );
  6763.                         }
  6764.                         fclose( fp );
  6765.                       }
  6766.  
  6767. Classification: ANSI 
  6768.  
  6769.  
  6770. ΓòÉΓòÉΓòÉ 104. fflush ΓòÉΓòÉΓòÉ
  6771.  
  6772. Synopsis: 
  6773.  
  6774.                     #include <stdio.h>
  6775.                     int fflush( FILE *fp );
  6776.  
  6777. Description: If the file fp is open for output or update, the fflush function 
  6778.           causes any unwritten data to be written to the file.  If the file fp 
  6779.           is open for input or update, the fflush function undoes the effect of 
  6780.           any preceding ungetc operation on the stream.  If the value of fp is 
  6781.           NULL, then all files that are open will be flushed. 
  6782.  
  6783. Returns:  The fflush function returns non-zero if a write error occurs and zero 
  6784.           otherwise.  When an error has occurred, errno contains a value 
  6785.           indicating the type of error that has been detected. 
  6786.  
  6787. See Also: fopen, fgetc, fgets, flushall, getc, gets, setbuf, setvbuf 
  6788.  
  6789. Example: 
  6790.  
  6791.                     #include <stdio.h>
  6792.                     #include <conio.h>
  6793.  
  6794.                     void main()
  6795.                       {
  6796.                         printf( "Press any key to continue..." );
  6797.                         fflush( stdout );
  6798.                         getch();
  6799.                       }
  6800.  
  6801. Classification: ANSI 
  6802.  
  6803.  
  6804. ΓòÉΓòÉΓòÉ 105. fgetc ΓòÉΓòÉΓòÉ
  6805.  
  6806. Synopsis: 
  6807.  
  6808.                     #include <stdio.h>
  6809.                     int fgetc( FILE *fp );
  6810.  
  6811. Description: The fgetc function gets the next character from the file 
  6812.           designated by fp. The character is signed. 
  6813.  
  6814. Returns:  The fgetc function returns the next character from the input stream 
  6815.           pointed to by fp. If the stream is at end-of-file, the end-of-file 
  6816.           indicator is set and fgetc returns EOF. If a read error occurs, the 
  6817.           error indicator is set and fgetc returns EOF. When an error has 
  6818.           occurred, errno contains a value indicating the type of error that 
  6819.           has been detected. 
  6820.  
  6821. See Also: fgetchar, fgets, fopen, getc, gets, ungetc 
  6822.  
  6823. Example: 
  6824.  
  6825.                     #include <stdio.h>
  6826.  
  6827.                     void main()
  6828.                       {
  6829.                         FILE *fp;
  6830.                         int c;
  6831.  
  6832.                         fp = fopen( "file", "r" );
  6833.                         if( fp != NULL ) {
  6834.                           while( (c = fgetc( fp )) != EOF )
  6835.                             fputc( c, stdout );
  6836.                           fclose( fp );
  6837.                         }
  6838.                       }
  6839.  
  6840. Classification: ANSI 
  6841.  
  6842.  
  6843. ΓòÉΓòÉΓòÉ 106. fgetchar ΓòÉΓòÉΓòÉ
  6844.  
  6845. Synopsis: 
  6846.  
  6847.                     #include <stdio.h>
  6848.                     int fgetchar( void );
  6849.  
  6850. Description: The fgetchar function is equivalent to fgetc with the argument 
  6851.           stdin. 
  6852.  
  6853. Returns:  The fgetchar function returns the next character from the input 
  6854.           stream pointed to by stdin. If the stream is at end-of-file, the 
  6855.           end-of-file indicator is set and fgetchar returns EOF. If a read 
  6856.           error occurs, the error indicator is set and fgetchar returns EOF. 
  6857.           When an error has occurred, errno contains a value indicating the 
  6858.           type of error that has been detected. 
  6859.  
  6860. See Also: fgetc, getc, getchar 
  6861.  
  6862. Example: 
  6863.  
  6864.                     #include <stdio.h>
  6865.  
  6866.                     void main()
  6867.                       {
  6868.                         FILE *fp;
  6869.                         int c;
  6870.                         fp = freopen( "file", "r", stdin );
  6871.                         if( fp != NULL ) {
  6872.                           while( (c = fgetchar()) != EOF )
  6873.                             fputchar(c);
  6874.                           fclose( fp );
  6875.                         }
  6876.                       }
  6877.  
  6878. Classification: WATCOM 
  6879.  
  6880.  
  6881. ΓòÉΓòÉΓòÉ 107. fgetpos ΓòÉΓòÉΓòÉ
  6882.  
  6883. Synopsis: 
  6884.  
  6885.                     #include <stdio.h>
  6886.                     int fgetpos( FILE *fp, fpos_t *pos );
  6887.  
  6888. Description: The fgetpos function stores the current position of the file fp in 
  6889.           the object pointed to by pos. The value stored is usable by the 
  6890.           fsetpos function for repositioning the file to its position at the 
  6891.           time of the call to the fgetpos function. 
  6892.  
  6893. Returns:  The fgetpos function returns zero if successful, otherwise, the 
  6894.           fgetpos function returns a non-zero value.  When an error has 
  6895.           occurred, errno contains a value indicating the type of error that 
  6896.           has been detected. 
  6897.  
  6898. See Also: fopen, fseek, fsetpos, ftell 
  6899.  
  6900. Example: 
  6901.  
  6902.                     #include <stdio.h>
  6903.  
  6904.                     void main()
  6905.                       {
  6906.                         FILE *fp;
  6907.                         fpos_t position;
  6908.                         auto char buffer[80];
  6909.  
  6910.                         fp = fopen( "file", "r" );
  6911.                         if( fp != NULL ) {
  6912.                           fgetpos( fp, &position ); /* get position     */
  6913.                           fgets( buffer, 80, fp );  /* read record      */
  6914.                           fsetpos( fp, &position ); /* set position     */
  6915.                           fgets( buffer, 80, fp );  /* read same record */
  6916.                           fclose( fp );
  6917.                         }
  6918.                       }
  6919.  
  6920. Classification: ANSI 
  6921.  
  6922.  
  6923. ΓòÉΓòÉΓòÉ 108. fgets ΓòÉΓòÉΓòÉ
  6924.  
  6925. Synopsis: 
  6926.  
  6927.                     #include <stdio.h>
  6928.                     char *fgets( char *buf, size_t n, FILE *fp );
  6929.  
  6930. Description: The fgets function gets a string of characters from the file 
  6931.           designated by fp and stores them in the array pointed to by buf. The 
  6932.           fgets function stops reading characters when end-of-file is reached, 
  6933.           or when a newline character is read, or when n-1 characters have been 
  6934.           read, whichever comes first.  The new-line character is not 
  6935.           discarded.  A null character is placed immediately after the last 
  6936.           character read into the array. 
  6937.  
  6938.           A common programming error is to assume the presence of a new-line 
  6939.           character in every string that is read into the array.  A new-line 
  6940.           character will not be present when more than n-1 characters occur 
  6941.           before the new-line.  Also, a new-line character may not appear as 
  6942.           the last character in a file, just before end-of-file. 
  6943.  
  6944.           The gets is similar to fgets except that it operates with stdin , it 
  6945.           has no size argument and it replaces a newline character with the 
  6946.           null character. 
  6947.  
  6948. Returns:  The fgets function returns buf if successful. NULL is returned if 
  6949.           end-of-file is encountered, or a read error occurs.  When an error 
  6950.           has occurred, errno contains a value indicating the type of error 
  6951.           that has been detected. 
  6952.  
  6953. See Also: fopen, getc, gets, fgetc 
  6954.  
  6955. Example: 
  6956.  
  6957.                     #include <stdio.h>
  6958.  
  6959.                     void main()
  6960.                       {
  6961.                         FILE *fp;
  6962.                         char buffer[80];
  6963.  
  6964.                         fp = fopen( "file", "r" );
  6965.                         if( fp != NULL ) {
  6966.                           while( fgets( buffer, 80, fp ) != NULL )
  6967.                             fputs( buffer, stdout );
  6968.                           fclose( fp );
  6969.                         }
  6970.                       }
  6971.  
  6972. Classification: ANSI 
  6973.  
  6974.  
  6975. ΓòÉΓòÉΓòÉ 109. filelength ΓòÉΓòÉΓòÉ
  6976.  
  6977. Synopsis: 
  6978.  
  6979.                     #include <io.h>
  6980.                     long int filelength( int handle );
  6981.  
  6982. Description: The filelength function returns the number of bytes in the opened 
  6983.           file indicated by the file handle handle. 
  6984.  
  6985. Returns:  If an error occurs, (-1L) is returned.  When an error has occurred, 
  6986.           errno contains a value indicating the type of error that has been 
  6987.           detected. 
  6988.  
  6989.           Otherwise, the number of bytes written to the file is returned. 
  6990.  
  6991. See Also: fstat, lseek, tell 
  6992.  
  6993. Example: 
  6994.  
  6995.                     #include <sys/types.h>
  6996.                     #include <fcntl.h>
  6997.                     #include <stdio.h>
  6998.                     #include <io.h>
  6999.  
  7000.                     void main()
  7001.                       {
  7002.                         int handle;
  7003.  
  7004.                         /* open a file for input              */
  7005.                         handle = open( "file", O_RDONLY | O_TEXT );
  7006.                         if( handle != -1 ) {
  7007.                           printf( "Size of file is %ld bytes\n",
  7008.                                   filelength( handle ) );
  7009.                           close( handle );
  7010.                         }
  7011.                       }
  7012.  
  7013.           produces the following: 
  7014.  
  7015.                     Size of file is 461 bytes
  7016.  
  7017. Classification: WATCOM 
  7018.  
  7019.  
  7020. ΓòÉΓòÉΓòÉ 110. fileno ΓòÉΓòÉΓòÉ
  7021.  
  7022. Synopsis: 
  7023.  
  7024.                     #include <stdio.h>
  7025.                     int fileno( FILE *stream );
  7026.  
  7027. Description: The fileno function returns the number of the file handle for the 
  7028.           file designated by stream. This number can be used in POSIX 
  7029.           input/output calls anywhere the value returned by open can be used. 
  7030.           The following symbolic values in <io.h> define the file handles that 
  7031.           are associated with the C language stdin, stdout, stderr, stdaux, 
  7032.           and stdprn  files when the application is started. 
  7033.  
  7034.    Value               Meaning 
  7035.    STDIN_FILENO        Standard input file number, stdin  (0) 
  7036.    STDOUT_FILENO       Standard output file number, stdout  (1) 
  7037.    STDERR_FILENO       Standard error file number, stderr  (2) 
  7038.    STDAUX_FILENO       Standard auxiliary file number, stdaux  (3) 
  7039.    STDPRN_FILENO       Standard printer file number, stdprn  (4) 
  7040.  
  7041. Returns:  The fileno function returns the number of the file handle for the 
  7042.           file designated by stream. If an error occurs, a value of -1 is 
  7043.           returned and errno is set to indicate the error. 
  7044.  
  7045. See Also: open 
  7046.  
  7047. Example: 
  7048.  
  7049.                     #include <stdio.h>
  7050.  
  7051.                     void main()
  7052.                       {
  7053.                         FILE *stream;
  7054.  
  7055.                         stream = fopen( "file", "r" );
  7056.                         printf( "File number is %d\n", fileno( stream ) );
  7057.                         fclose( stream );
  7058.                       }
  7059.  
  7060.           produces the following: 
  7061.  
  7062.                     File number is 7
  7063.  
  7064. Classification: POSIX 1003.1 
  7065.  
  7066.  
  7067. ΓòÉΓòÉΓòÉ 111. floor ΓòÉΓòÉΓòÉ
  7068.  
  7069. Synopsis: 
  7070.  
  7071.                     #include <math.h>
  7072.                     double floor( double x );
  7073.  
  7074. Description: The floor function computes the largest integer not greater than 
  7075.           x. 
  7076.  
  7077. Returns:  The floor function computes the largest integer not greater than x, 
  7078.           expressed as a double. 
  7079.  
  7080. See Also: ceil, fmod 
  7081.  
  7082. Example: 
  7083.  
  7084.                     #include <stdio.h>
  7085.                     #include <math.h>
  7086.  
  7087.                     void main()
  7088.                       {
  7089.                         printf( "%f\n", floor( -3.14 ) );
  7090.                         printf( "%f\n", floor( -3. ) );
  7091.                         printf( "%f\n", floor( 0. ) );
  7092.                         printf( "%f\n", floor( 3.14 ) );
  7093.                         printf( "%f\n", floor( 3. ) );
  7094.                       }
  7095.  
  7096.           produces the following: 
  7097.  
  7098.                     -4.000000
  7099.                     -3.000000
  7100.                     0.000000
  7101.                     3.000000
  7102.                     3.000000
  7103.  
  7104. Classification: ANSI 
  7105.  
  7106.  
  7107. ΓòÉΓòÉΓòÉ 112. flushall ΓòÉΓòÉΓòÉ
  7108.  
  7109. Synopsis: 
  7110.  
  7111.                     #include <stdio.h>
  7112.                     int flushall( void );
  7113.  
  7114. Description: The flushall function clears all buffers associated with input 
  7115.           streams and writes any buffers associated with output streams.  A 
  7116.           subsequent read operation on an input file causes new data to be read 
  7117.           from the associated file or device. 
  7118.  
  7119.           The function is equivalent to calling the fflush for all open stream 
  7120.           files. 
  7121.  
  7122. Returns:  The flushall function returns the number of open streams. When an 
  7123.           output error occurs while writing to a file, the errno global 
  7124.           variable will be set. 
  7125.  
  7126. See Also: fopen, fflush 
  7127.  
  7128. Example: 
  7129.  
  7130.                     #include <stdio.h>
  7131.  
  7132.                     void main()
  7133.                       {
  7134.                         printf( "The number of open files is %d\n",
  7135.                                 flushall() );
  7136.                       }
  7137.  
  7138.           produces the following: 
  7139.  
  7140.                     The number of open files is 4
  7141.  
  7142. Classification: WATCOM 
  7143.  
  7144.  
  7145. ΓòÉΓòÉΓòÉ 113. fmod ΓòÉΓòÉΓòÉ
  7146.  
  7147. Synopsis: 
  7148.  
  7149.                     #include <math.h>
  7150.                     double fmod( double x, double y );
  7151.  
  7152. Description: The fmod function computes the floating-point remainder of x/y, 
  7153.           even if the quotient x/y is not representable. 
  7154.  
  7155. Returns:  The fmod function returns the value x - (i * y), for some integer i 
  7156.           such that, if y is non-zero, the result has the same sign as x and 
  7157.           magnitude less than the magnitude of y. If the value of y is zero, 
  7158.           then the value returned is zero. 
  7159.  
  7160. See Also: ceil, fabs, floor 
  7161.  
  7162. Example: 
  7163.  
  7164.                     #include <stdio.h>
  7165.                     #include <math.h>
  7166.  
  7167.                     void main()
  7168.                       {
  7169.                         printf( "%f\n", fmod(  4.5,  2.0 ) );
  7170.                         printf( "%f\n", fmod( -4.5,  2.0 ) );
  7171.                         printf( "%f\n", fmod(  4.5, -2.0 ) );
  7172.                         printf( "%f\n", fmod( -4.5, -2.0 ) );
  7173.                       }
  7174.  
  7175.           produces the following: 
  7176.  
  7177.                     0.500000
  7178.                     -0.500000
  7179.                     0.500000
  7180.                     -0.500000
  7181.  
  7182. Classification: ANSI 
  7183.  
  7184.  
  7185. ΓòÉΓòÉΓòÉ 114. fopen ΓòÉΓòÉΓòÉ
  7186.  
  7187. Synopsis: 
  7188.  
  7189.                     #include <stdio.h>
  7190.                     FILE *fopen( const char *filename, const char *mode );
  7191.  
  7192. Description: The fopen function opens the file whose name is the string pointed 
  7193.           to by filename, and associates a stream with it.  The argument mode 
  7194.           points to a string beginning with one of the following sequences: 
  7195.  
  7196.    Mode      Meaning 
  7197.    "r"       open file for reading; use default file translation 
  7198.    "w"       create file for writing, or truncate to zero length; use default 
  7199.              file translation 
  7200.    "a"       append:  open text file or create for writing at end-of-file; use 
  7201.              default file translation 
  7202.    "rb"      open binary file for reading 
  7203.    "rt"      open text file for reading 
  7204.    "wb"      create binary file for writing, or truncate to zero length 
  7205.    "wt"      create text file for writing, or truncate to zero length 
  7206.    "ab"      append; open binary file or create for writing at end-of-file 
  7207.    "at"      append; open text file or create for writing at end-of-file 
  7208.    "r+"      open file for update (reading and/or writing); use default file 
  7209.              translation 
  7210.    "w+"      create file for update, or truncate to zero length; use default 
  7211.              file translation 
  7212.    "a+"      append; open file or create for update, writing at end-of-file; 
  7213.              use default file translation 
  7214.    "r+b"     open binary file for update (reading and/or writing) 
  7215.    "r+t"     open text file for update (reading and/or writing) 
  7216.    "w+b"     create binary file for update, or truncate to zero length 
  7217.    "w+t"     create text file for update, or truncate to zero length 
  7218.    "a+b"     append; open binary file or create for update, writing at 
  7219.              end-of-file 
  7220.    "a+t"     append; open text file or create for update, writing at 
  7221.              end-of-file 
  7222.    "rb+"     open binary file for update (reading and/or writing) 
  7223.    "rt+"     open text file for update (reading and/or writing) 
  7224.    "wb+"     create binary file for update, or truncate to zero length 
  7225.    "wt+"     create text file for update, or truncate to zero length 
  7226.    "ab+"     append; open binary file or create for update, writing at 
  7227.              end-of-file 
  7228.    "at+"     append; open text file or create for update, writing at 
  7229.              end-of-file 
  7230.  
  7231.           When default file translation is specified, the value of the global 
  7232.           variable _fmode establishes whether the file is to treated as a 
  7233.           binary or a text file.  Unless this value is changed by the program, 
  7234.           the default will be text mode. 
  7235.  
  7236.           Opening a file with read mode ( 'r' as the first character in the 
  7237.           mode argument) fails if the file does not exist or it cannot be read. 
  7238.           Opening a file with append mode ( 'a' as the first character in the 
  7239.           mode argument) causes all subsequent writes to the file to be forced 
  7240.           to the current end-of-file, regardless of previous calls to the fseek 
  7241.           function.  When a file is opened with update mode ( '+' as the second 
  7242.           or third character of the mode argument), both input and output may 
  7243.           be performed on the associated stream. 
  7244.  
  7245. Returns:  The fopen function returns a pointer to the object controlling the 
  7246.           stream.  This pointer must be passed as a parameter to subsequent 
  7247.           functions for performing operations on the file.  If the open 
  7248.           operation fails, fopen returns NULL. When an error has occurred, 
  7249.           errno contains a value indicating the type of error that has been 
  7250.           detected. 
  7251.  
  7252. See Also: fclose, fcloseall, freopen 
  7253.  
  7254. Example: 
  7255.  
  7256.                     #include <stdio.h>
  7257.  
  7258.                     void main()
  7259.                       {
  7260.                         FILE *fp;
  7261.  
  7262.  
  7263.                         fp = fopen( "report.dat", "r" );
  7264.                         if( fp != NULL ) {
  7265.                           /* rest of code goes here */
  7266.                           fclose( fp );
  7267.                         }
  7268.                       }
  7269.  
  7270. Classification: ANSI, ('t' is a WATCOM extension) 
  7271.  
  7272.  
  7273. ΓòÉΓòÉΓòÉ 115. FP_OFF ΓòÉΓòÉΓòÉ
  7274.  
  7275. Synopsis: 
  7276.  
  7277.                     #include <dos.h>
  7278.                     unsigned FP_OFF( void __far *far_ptr );
  7279.  
  7280. Description: The FP_OFF macro can be used to obtain the offset portion of the 
  7281.           far pointer value given in far_ptr. 
  7282.  
  7283. Returns:  The macro returns an unsigned integer value which is the offset 
  7284.           portion of the pointer value. 
  7285.  
  7286. See Also: FP_SEG, MK_FP, segread 
  7287.  
  7288. Example: 
  7289.  
  7290.                     #include <stdio.h>
  7291.                     #include <dos.h>
  7292.  
  7293.                     char ColourTable[256][3];
  7294.  
  7295.                     void main()
  7296.                       {
  7297.                         union REGPACK r;
  7298.                         int i;
  7299.                         /* read block of colour registers */
  7300.                         r.h.ah = 0x10;
  7301.                         r.h.al = 0x17;
  7302.                         r.x.bx = 0;
  7303.                         r.x.cx = 256;
  7304.                         r.x.es = FP_SEG( ColourTable );
  7305.                         r.x.dx = FP_OFF( ColourTable );
  7306.                         intr( 0x10, &r );
  7307.                         for( i = 0; i < 256; i++ ) {
  7308.                           printf( "Colour index = %d "
  7309.                                   "{ Red=%d, Green=%d, Blue=%d }\n",
  7310.                                   i,
  7311.                                   ColourTable[i][0],
  7312.                                   ColourTable[i][1],
  7313.                                   ColourTable[i][2] );
  7314.                         }
  7315.                       }
  7316.  
  7317. Classification: Intel 
  7318.  
  7319.  
  7320. ΓòÉΓòÉΓòÉ 116. FP_SEG ΓòÉΓòÉΓòÉ
  7321.  
  7322. Synopsis: 
  7323.  
  7324.                     #include <dos.h>
  7325.                     unsigned FP_SEG( void __far *far_ptr );
  7326.  
  7327. Description: The FP_SEG macro can be used to obtain the segment portion of the 
  7328.           far pointer value given in far_ptr. 
  7329.  
  7330. Returns:  The macro returns an unsigned integer value which is the segment 
  7331.           portion of the pointer value. 
  7332.  
  7333. See Also: FP_OFF, MK_FP, segread 
  7334.  
  7335. Example: 
  7336.  
  7337.                     #include <stdio.h>
  7338.                     #include <dos.h>
  7339.  
  7340.                     char ColourTable[256][3];
  7341.  
  7342.                     void main()
  7343.                       {
  7344.                         union REGPACK r;
  7345.                         int i;
  7346.                         /* read block of colour registers */
  7347.                         r.h.ah = 0x10;
  7348.                         r.h.al = 0x17;
  7349.                         r.x.bx = 0;
  7350.                         r.x.cx = 256;
  7351.                         r.x.es = FP_SEG( ColourTable );
  7352.                         r.x.dx = FP_OFF( ColourTable );
  7353.                         intr( 0x10, &r );
  7354.                         for( i = 0; i < 256; i++ ) {
  7355.                           printf( "Colour index = %d "
  7356.                                   "{ Red=%d, Green=%d, Blue=%d }\n",
  7357.                                   i,
  7358.                                   ColourTable[i][0],
  7359.                                   ColourTable[i][1],
  7360.                                   ColourTable[i][2] );
  7361.                         }
  7362.                       }
  7363.  
  7364. Classification: Intel 
  7365.  
  7366.  
  7367. ΓòÉΓòÉΓòÉ 117. _fpreset ΓòÉΓòÉΓòÉ
  7368.  
  7369. Synopsis: 
  7370.  
  7371.                     #include <float.h>
  7372.                     void _fpreset( void );
  7373.  
  7374. Description: After a floating-point exception, it may be necessary to call the 
  7375.           _fpreset function before any further floating-point operations are 
  7376.           attempted. 
  7377.  
  7378. Returns:  No value is returned. 
  7379.  
  7380. See Also: _clear87, _status87 
  7381.  
  7382. Example: 
  7383.  
  7384.                     #include <stdio.h>
  7385.                     #include <float.h>
  7386.                     char *status[2] = { "No", "  " };
  7387.                     void main()
  7388.                       {
  7389.                         unsigned int fp_status;
  7390.                         fp_status = _status87();
  7391.                         printf( "80x87 status\n" );
  7392.                         printf( "%s invalid operation\n",
  7393.                                 status[ (fp_status & SW_INVALID) == 0 ] );
  7394.                         printf( "%s denormalized operand\n",
  7395.                                 status[ (fp_status & SW_DENORMAL) == 0 ] );
  7396.                         printf( "%s divide by zero\n",
  7397.                                 status[ (fp_status & SW_ZERODIVIDE) == 0 ] );
  7398.                         printf( "%s overflow\n",
  7399.                                 status[ (fp_status & SW_OVERFLOW) == 0 ] );
  7400.                         printf( "%s underflow\n",
  7401.                                 status[ (fp_status & SW_UNDERFLOW) == 0 ] );
  7402.                         printf( "%s inexact result\n",
  7403.                                 status[ (fp_status & SW_INEXACT) == 0 ] );
  7404.                         _fpreset();
  7405.                       }
  7406.  
  7407. Classification: Intel 
  7408.  
  7409.  
  7410. ΓòÉΓòÉΓòÉ 118. fprintf ΓòÉΓòÉΓòÉ
  7411.  
  7412. Synopsis: 
  7413.  
  7414.                     #include <stdio.h>
  7415.                     int fprintf( FILE *fp, const char *format, ... );
  7416.  
  7417. Description: The fprintf function writes output to the file pointed to by fp 
  7418.           under control of the argument format. The format string is described 
  7419.           under the description of the printf function. 
  7420.  
  7421. Returns:  The fprintf function returns the number of characters written, or a 
  7422.           negative value if an output error occurred.  When an error has 
  7423.           occurred, errno contains a value indicating the type of error that 
  7424.           has been detected. 
  7425.  
  7426. See Also: cprintf, printf, sprintf, vfprintf, vprintf, vsprintf 
  7427.  
  7428. Example: 
  7429.  
  7430.                     #include <stdio.h>
  7431.  
  7432.                     char *weekday = { "Saturday" };
  7433.                     char *month = { "April" };
  7434.  
  7435.                     void main()
  7436.                       {
  7437.                         fprintf( stdout, "%s, %s %d, %d\n",
  7438.                               weekday, month, 18, 1987 );
  7439.                       }
  7440.  
  7441.           produces the following: 
  7442.  
  7443.                     Saturday, April 18, 1987
  7444.  
  7445. Classification: ANSI 
  7446.  
  7447.  
  7448. ΓòÉΓòÉΓòÉ 119. fputc ΓòÉΓòÉΓòÉ
  7449.  
  7450. Synopsis: 
  7451.  
  7452.                     #include <stdio.h>
  7453.                     int fputc( int c, FILE *fp );
  7454.  
  7455. Description: The fputc function writes the character specified by the argument 
  7456.           c to the output stream designated by fp. 
  7457.  
  7458. Returns:  The fputc function returns the character written.  If a write error 
  7459.           occurs, the error indicator is set and fputc returns EOF. When an 
  7460.           error has occurred, errno contains a value indicating the type of 
  7461.           error that has been detected. 
  7462.  
  7463. See Also: fopen, fputchar, fputs, putc, putchar, puts 
  7464.  
  7465. Example: 
  7466.  
  7467.                     #include <stdio.h>
  7468.  
  7469.                     void main()
  7470.                       {
  7471.                         FILE *fp;
  7472.                         int c;
  7473.  
  7474.                         fp = fopen( "file", "r" );
  7475.                         if( fp != NULL ) {
  7476.                           while( (c = fgetc( fp )) != EOF )
  7477.                             fputc( c, stdout );
  7478.                           fclose( fp );
  7479.                         }
  7480.                       }
  7481.  
  7482. Classification: ANSI 
  7483.  
  7484.  
  7485. ΓòÉΓòÉΓòÉ 120. fputchar ΓòÉΓòÉΓòÉ
  7486.  
  7487. Synopsis: 
  7488.  
  7489.                     #include <stdio.h>
  7490.                     int fputchar( int c );
  7491.  
  7492. Description: The fputchar function writes the character specified by the 
  7493.           argument c to the output stream stdout. This function is identical to 
  7494.           the putchar function. 
  7495.  
  7496.           The function is equivalent to: 
  7497.  
  7498.                         fputc( c, stdout );
  7499.  
  7500. Returns:  The fputchar function returns the character written.  If a write 
  7501.           error occurs, the error indicator is set and fputchar returns EOF. 
  7502.           When an error has occurred, errno contains a value indicating the 
  7503.           type of error that has been detected. 
  7504.  
  7505. See Also: fputc, fputs, putc, putchar 
  7506.  
  7507. Example: 
  7508.  
  7509.                     #include <stdio.h>
  7510.  
  7511.                     void main()
  7512.                       {
  7513.                         FILE *fp;
  7514.                         int c;
  7515.  
  7516.                         fp = fopen( "file", "r" );
  7517.                         if( fp != NULL ) {
  7518.                           c = fgetc( fp );
  7519.                           while( c != EOF ) {
  7520.                             fputchar( c );
  7521.                             c = fgetc( fp );
  7522.                           }
  7523.                           fclose( fp );
  7524.                         }
  7525.                       }
  7526.  
  7527. Classification: WATCOM 
  7528.  
  7529.  
  7530. ΓòÉΓòÉΓòÉ 121. fputs ΓòÉΓòÉΓòÉ
  7531.  
  7532. Synopsis: 
  7533.  
  7534.                     #include <stdio.h>
  7535.                     int fputs( const char *buf, FILE *fp );
  7536.  
  7537. Description: The fputs function writes the character string pointed to by buf 
  7538.           to the output stream designated by fp. The terminating null character 
  7539.           is not written. 
  7540.  
  7541. Returns:  The fputs function returns EOF if an error occurs; otherwise it 
  7542.           returns a non-negative value.  When an error has occurred, errno 
  7543.           contains a value indicating the type of error that has been detected. 
  7544.  
  7545. See Also: fopen, fputc, putc, puts 
  7546.  
  7547. Example: 
  7548.  
  7549.                     #include <stdio.h>
  7550.  
  7551.                     void main()
  7552.                       {
  7553.                         FILE *fp;
  7554.                         char buffer[80];
  7555.  
  7556.                         fp = fopen( "file", "r" );
  7557.                         if( fp != NULL ) {
  7558.                           while( fgets( buffer, 80, fp ) != NULL )
  7559.                             fputs( buffer, stdout );
  7560.                           fclose( fp );
  7561.                         }
  7562.                       }
  7563.  
  7564. Classification: ANSI 
  7565.  
  7566.  
  7567. ΓòÉΓòÉΓòÉ 122. fread ΓòÉΓòÉΓòÉ
  7568.  
  7569. Synopsis: 
  7570.  
  7571.                     #include <stdio.h>
  7572.                     size_t fread( void *buf,
  7573.                                   size_t elsize,
  7574.                                   size_t nelem,
  7575.                                   FILE *fp );
  7576.  
  7577. Description: The fread function reads nelem elements of elsize bytes each from 
  7578.           the file specified by fp into the buffer specified by buf. 
  7579.  
  7580. Returns:  The fread function returns the number of complete elements 
  7581.           successfully read.  This value may be less than the requested number 
  7582.           of elements. 
  7583.  
  7584.           The feof and ferror functions can be used to determine whether the 
  7585.           end of the file was encountered or if an input/output error has 
  7586.           occurred.  When an error has occurred, errno contains a value 
  7587.           indicating the type of error that has been detected. 
  7588.  
  7589. See Also: fopen, feof, ferror 
  7590.  
  7591. Example: 
  7592.  
  7593.           The following example reads a simple student record containing binary 
  7594.           data.  The student record is described by the struct student_data 
  7595.           declaration. 
  7596.  
  7597.                     #include <stdio.h>
  7598.  
  7599.                     struct student_data {
  7600.                         int  student_id;
  7601.                         unsigned char marks[10];
  7602.                     };
  7603.                     void main()
  7604.                       {
  7605.                         FILE *fp;
  7606.                         struct student_data std;
  7607.                         int i;
  7608.                         fp = fopen( "file", "r" );
  7609.                         if( fp != NULL ) {
  7610.                           while( read_data( fp, &std ) != NULL ) {
  7611.                             printf( "id=%d ", std.student_id );
  7612.                             for( i = 0; i < 10; i++ )
  7613.                               printf( "%3d ", std.marks[ i ] );
  7614.                             printf( "\n" );
  7615.                           }
  7616.                           fclose( fp );
  7617.                         }
  7618.                       }
  7619.                     int read_data( FILE *fp, struct student_data *p )
  7620.                       {
  7621.                         return( fread( p, sizeof(*p), 1, fp ) );
  7622.                       }
  7623.  
  7624.  
  7625. Classification: ANSI 
  7626.  
  7627.  
  7628. ΓòÉΓòÉΓòÉ 123. free Functions ΓòÉΓòÉΓòÉ
  7629.  
  7630. Synopsis: 
  7631.  
  7632.                     #include <stdlib.h>  For ANSI compatibility (free only)
  7633.                     #include <malloc.h>  Required for other function prototypes
  7634.                     void free( void *ptr );
  7635.                     void _bfree( __segment seg, void __based(void) *ptr );
  7636.                     void _ffree( void __far  *ptr );
  7637.                     void _nfree( void __near *ptr );
  7638.  
  7639. Description: When the value of the argument ptr is NULL, the free function does 
  7640.           nothing; otherwise, the free function deallocates the memory block 
  7641.           located by the argument ptr which points to a memory block previously 
  7642.           allocated through a call to the appropriate version of calloc, malloc 
  7643.           or realloc. After the call, the freed block is available for 
  7644.           allocation. 
  7645.  
  7646.           Each function deallocates memory from a particular heap, as listed 
  7647.           below: 
  7648.  
  7649.    Function  Heap 
  7650.    free      Depends on data model of the program 
  7651.    _bfree    Based heap specified by seg value 
  7652.    _ffree    Far heap (outside the default data segment) 
  7653.    _nfree    Near heap (inside the default data segment) 
  7654.  
  7655.           In a large data memory model, the free function is equivalent to the 
  7656.           _ffree function; in a small data memory model, the free function is 
  7657.           equivalent to the _nfree function. 
  7658.  
  7659. Returns:  The free functions return no value. 
  7660.  
  7661. See Also: calloc Functions, _expand Functions, halloc, hfree, malloc Functions, 
  7662.           _msize Functions, realloc Functions, sbrk 
  7663.  
  7664. Example: 
  7665.  
  7666.                     #include <stdio.h>
  7667.                     #include <stdlib.h>
  7668.  
  7669.                     void main()
  7670.                       {
  7671.                         char *buffer;
  7672.                         buffer = (char *)malloc( 80 );
  7673.                         if( buffer == NULL ) {
  7674.                           printf( "Unable to allocate memory\n" );
  7675.                         } else {
  7676.  
  7677.                           /* rest of code goes here */
  7678.  
  7679.                           free( buffer );  /* deallocate buffer */
  7680.                         }
  7681.                       }
  7682.  
  7683. Classification: free is ANSI; _bfree, _ffree, and _nfree are not ANSI 
  7684.  
  7685.  
  7686. ΓòÉΓòÉΓòÉ 124. _freect ΓòÉΓòÉΓòÉ
  7687.  
  7688. Synopsis: 
  7689.  
  7690.                     #include <malloc.h>
  7691.                     unsigned int _freect( size_t size );
  7692.  
  7693. Description: The _freect function returns the number of times that _nmalloc (or 
  7694.           malloc in small data models) can be called to allocate a item of size 
  7695.           bytes.  In the tiny, small and medium memory models, the default data 
  7696.           segment is only extended as needed to satisfy requests for memory 
  7697.           allocation.  Therefore, you will need to call _nheapgrow in these 
  7698.           memory models before calling _freect in order to get a meaningful 
  7699.           result. 
  7700.  
  7701. Returns:  The _freect function returns the number of calls as an unsigned 
  7702.           integer. 
  7703.  
  7704. See Also: calloc, _heapgrow Functions, malloc Functions, _memavl, _memmax 
  7705.  
  7706. Example: 
  7707.  
  7708.                     #include <stdio.h>
  7709.                     #include <malloc.h>
  7710.                     void main()
  7711.                       {
  7712.                         int  i;
  7713.                         printf( "Can allocate %u longs before _nheapgrow\n",
  7714.                                 _freect( sizeof(long) ) );
  7715.                         _nheapgrow();
  7716.                         printf( "Can allocate %u longs after _nheapgrow\n",
  7717.                                 _freect( sizeof(long) ) );
  7718.                         for( i = 1; i < 1000; i++ ) {
  7719.                           _nmalloc( sizeof(long) );
  7720.                         }
  7721.                         printf( "After allocating 1000 longs:\n" );
  7722.                         printf( "Can still allocate %u longs\n",
  7723.                                 _freect( sizeof(long) ) );
  7724.                       }
  7725.  
  7726.           produces the following: 
  7727.  
  7728.                     Can allocate 0 longs before _nheapgrow
  7729.                     Can allocate 10447 longs after _nheapgrow
  7730.                     After allocating 1000 longs:
  7731.                     Can still allocate 9447 longs
  7732.  
  7733. Classification: WATCOM 
  7734.  
  7735.  
  7736. ΓòÉΓòÉΓòÉ 125. freopen ΓòÉΓòÉΓòÉ
  7737.  
  7738. Synopsis: 
  7739.  
  7740.                     #include <stdio.h>
  7741.                     FILE *freopen( const char *filename,
  7742.                                    const char *mode,
  7743.                                    FILE *fp );
  7744.  
  7745. Description: The stream located by the fp pointer is closed.  The freopen 
  7746.           function opens the file whose name is the string pointed to by 
  7747.           filename, and associates a stream with it.  The stream information is 
  7748.           placed in the structure located by the fp pointer. 
  7749.  
  7750.           The argument mode is described in the description of the fopen 
  7751.           function. 
  7752.  
  7753. Returns:  The freopen function returns a pointer to the object controlling the 
  7754.           stream.  This pointer must be passed as a parameter to subsequent 
  7755.           functions for performing operations on the file.  If the open 
  7756.           operation fails, freopen returns NULL. When an error has occurred, 
  7757.           errno contains a value indicating the type of error that has been 
  7758.           detected. 
  7759.  
  7760. See Also: fopen, fdopen 
  7761.  
  7762. Example: 
  7763.  
  7764.                     #include <stdio.h>
  7765.  
  7766.                     void main()
  7767.                       {
  7768.                         FILE *fp;
  7769.                         int c;
  7770.  
  7771.                         fp = freopen( "file", "r", stdin );
  7772.                         if( fp != NULL ) {
  7773.                           while( (c = fgetchar()) != EOF )
  7774.                             fputchar(c);
  7775.                           fclose( fp );
  7776.                         }
  7777.                       }
  7778.  
  7779. Classification: ANSI 
  7780.  
  7781.  
  7782. ΓòÉΓòÉΓòÉ 126. frexp ΓòÉΓòÉΓòÉ
  7783.  
  7784. Synopsis: 
  7785.  
  7786.                     #include <math.h>
  7787.                     double frexp( double value, int *exp );
  7788.  
  7789. Description: The frexp function breaks a floating-point number into a 
  7790.           normalized fraction and an integral power of 2.  It stores the 
  7791.           integral power of 2 in the int object pointed to by exp. 
  7792.  
  7793. Returns:  The frexp function returns the value of x, such that x is a double 
  7794.           with magnitude in the interval [0.5,1) or zero, and value equals x 
  7795.           times 2 raised to the power *exp. If value is zero, then both parts 
  7796.           of the result are zero. 
  7797.  
  7798. See Also: ldexp, modf 
  7799.  
  7800. Example: 
  7801.  
  7802.                     #include <stdio.h>
  7803.                     #include <math.h>
  7804.  
  7805.                     void main()
  7806.                       {
  7807.                         int    expon;
  7808.                         double value;
  7809.  
  7810.                         value = frexp(  4.25, &expon );
  7811.                         printf( "%f %d\n", value, expon );
  7812.                         value = frexp( -4.25, &expon );
  7813.                         printf( "%f %d\n", value, expon );
  7814.                       }
  7815.  
  7816.           produces the following: 
  7817.  
  7818.                     0.531250 3
  7819.                     -0.531250 3
  7820.  
  7821. Classification: ANSI 
  7822.  
  7823.  
  7824. ΓòÉΓòÉΓòÉ 127. fscanf ΓòÉΓòÉΓòÉ
  7825.  
  7826. Synopsis: 
  7827.  
  7828.                     #include <stdio.h>
  7829.                     int fscanf( FILE *fp, const char *format, ... );
  7830.  
  7831. Description: The fscanf function scans input from the file designated by fp 
  7832.           under control of the argument format. Following the format string is 
  7833.           a list of addresses to receive values.  The format string is 
  7834.           described under the description of the scanf function. 
  7835.  
  7836. Returns:  The fscanf function returns EOF when the scanning is terminated by 
  7837.           reaching the end of the input stream.  Otherwise, the number of input 
  7838.           arguments for which values were successfully scanned and stored is 
  7839.           returned.  When a file input error occurs, the errno global variable 
  7840.           may be set. 
  7841.  
  7842. See Also: scanf, sscanf 
  7843.  
  7844. Example: 
  7845.  
  7846.           To scan a date in the form "Saturday April 18 1987": 
  7847.  
  7848.                     #include <stdio.h>
  7849.  
  7850.                     void main()
  7851.                       {
  7852.                         int day, year;
  7853.                         char weekday[10], month[10];
  7854.                         FILE *in_data;
  7855.  
  7856.                         in_data = fopen( "file", "r" );
  7857.                         if( in_data != NULL ) {
  7858.                           fscanf( in_data, "%s %s %d %d",
  7859.                                   weekday, month, &day, &year );
  7860.                           printf( "Weekday=%s Month=%s Day=%d Year=%d\n",
  7861.                                   weekday, month, day, year );
  7862.                           fclose( in_data );
  7863.                         }
  7864.                       }
  7865.  
  7866.  
  7867. Classification: ANSI 
  7868.  
  7869.  
  7870. ΓòÉΓòÉΓòÉ 128. fseek ΓòÉΓòÉΓòÉ
  7871.  
  7872. Synopsis: 
  7873.  
  7874.                     #include <stdio.h>
  7875.                     int fseek( FILE *fp, long int offset, int where );
  7876.  
  7877. Description: The fseek function changes the read/write position of the file 
  7878.           specified by fp. This position defines the character that will be 
  7879.           read or written on the next I/O operation on the file.  The argument 
  7880.           fp is a file pointer returned by fopen or freopen. The argument 
  7881.           offset is the position to seek to relative to one of three positions 
  7882.           specified by the argument where. Allowable values for where are: 
  7883.  
  7884.    Value         Meaning 
  7885.  
  7886.    SEEK_SET      The new file position is computed relative to the start of the 
  7887.                  file.  The value of offset must not be negative. 
  7888.  
  7889.    SEEK_CUR      The new file position is computed relative to the current file 
  7890.                  position. The value of offset may be positive, negative or 
  7891.                  zero. 
  7892.  
  7893.    SEEK_END      The new file position is computed relative to the end of the 
  7894.                  file. 
  7895.  
  7896.           The fseek function clears the end-of-file indicator and undoes any 
  7897.           effects of the ungetc function on the same file. 
  7898.  
  7899.           The ftell function can be used to obtain the current position in the 
  7900.           file before changing it.  The position can be restored by using the 
  7901.           value returned by ftell in a subsequent call to fseek with the where 
  7902.           parameter set to SEEK_SET. 
  7903.  
  7904. Returns:  The fseek function returns zero if successful, non-zero otherwise. 
  7905.           When an error has occurred, errno contains a value indicating the 
  7906.           type of error that has been detected. 
  7907.  
  7908. See Also: fgetpos, fopen, fsetpos, ftell 
  7909.  
  7910. Example: 
  7911.  
  7912.           The size of a file can be determined by the following example which 
  7913.           saves and restores the current position of the file. 
  7914.  
  7915.                     #include <stdio.h>
  7916.                     long int filesize( FILE *fp )
  7917.                       {
  7918.                         long int save_pos, size_of_file;
  7919.                         save_pos = ftell( fp );
  7920.                         fseek( fp, 0L, SEEK_END );
  7921.                         size_of_file = ftell( fp );
  7922.                         fseek( fp, save_pos, SEEK_SET );
  7923.                         return( size_of_file );
  7924.                       }
  7925.                     void main()
  7926.                       {
  7927.                         FILE *fp;
  7928.  
  7929.                         fp = fopen( "file", "r" );
  7930.                         if( fp != NULL ) {
  7931.                           printf( "File size=%ld\n", filesize( fp ) );
  7932.                           fclose( fp );
  7933.                         }
  7934.                       }
  7935.  
  7936.  
  7937. Classification: ANSI 
  7938.  
  7939.  
  7940. ΓòÉΓòÉΓòÉ 129. fsetpos ΓòÉΓòÉΓòÉ
  7941.  
  7942. Synopsis: 
  7943.  
  7944.                     #include <stdio.h>
  7945.                     int fsetpos( FILE *fp, fpos_t *pos );
  7946.  
  7947. Description: The fsetpos function positions the file fp according to the value 
  7948.           of the object pointed to by pos, which shall be a value returned by 
  7949.           an earlier call to the fgetpos function on the same file. 
  7950.  
  7951. Returns:  The fsetpos function returns zero if successful, otherwise, the 
  7952.           fsetpos function returns a non-zero value.  When an error has 
  7953.           occurred, errno contains a value indicating the type of error that 
  7954.           has been detected. 
  7955.  
  7956. See Also: fgetpos, fopen, fseek, ftell 
  7957.  
  7958. Example: 
  7959.  
  7960.                     #include <stdio.h>
  7961.  
  7962.                     void main()
  7963.                       {
  7964.                         FILE *fp;
  7965.                         fpos_t position;
  7966.                         auto char buffer[80];
  7967.  
  7968.                         fp = fopen( "file", "r" );
  7969.                         if( fp != NULL ) {
  7970.                           fgetpos( fp, &position ); /* get position     */
  7971.                           fgets( buffer, 80, fp );      /* read record      */
  7972.                           fsetpos( fp, &position ); /* set position     */
  7973.                           fgets( buffer, 80, fp );      /* read same record */
  7974.                           fclose( fp );
  7975.                         }
  7976.                       }
  7977.  
  7978. Classification: ANSI 
  7979.  
  7980.  
  7981. ΓòÉΓòÉΓòÉ 130. fstat ΓòÉΓòÉΓòÉ
  7982.  
  7983. Synopsis: 
  7984.  
  7985.                     #include <sys\types.h>
  7986.                     #include <sys\stat.h>
  7987.                     int fstat( int handle, struct stat *buf );
  7988.  
  7989. Description: The fstat function obtains information about an open file whose 
  7990.           file handle is handle. This information is placed in the structure 
  7991.           located at the address indicated by buf. 
  7992.  
  7993.           The file <sys\stat.h> contains definitions for the structure stat. 
  7994.  
  7995.                     struct stat {
  7996.                        dev_t   st_dev;    /* disk drive file resides on */
  7997.                        ino_t   st_ino;    /* this inode's number        */
  7998.                        unsigned short st_mode; /* file mode             */
  7999.                        short   st_nlink;  /* # of hard links            */
  8000.                        short   st_uid;    /* user-id, always 'root'     */
  8001.                        short   st_gid;    /* group-id, always 'root'    */
  8002.                        dev_t   st_rdev;   /* drive #, same as st_dev    */
  8003.                        off_t   st_size;   /* total file size            */
  8004.                        time_t  st_atime;  /* time of last access        */
  8005.                        time_t  st_mtime;  /* time of last modification  */
  8006.                        time_t  st_ctime;  /* time of last status change */
  8007.                     };
  8008.  
  8009.  
  8010. Returns:  The fstat function returns zero when the information is successfully 
  8011.           obtained.  Otherwise, -1 is returned. 
  8012.  
  8013. Errors:   When an error has occurred, errno contains a value indicating the 
  8014.           type of error that has been detected. 
  8015.  
  8016.    EBADF     The handle argument is not a valid file handle. 
  8017.  
  8018. See Also: creat, dup, dup2, open, sopen, stat 
  8019.  
  8020. Example: 
  8021.  
  8022.                     #include <stdio.h>
  8023.                     #include <sys\types.h>
  8024.                     #include <sys\stat.h>
  8025.                     #include <fcntl.h>
  8026.                     #include <io.h>
  8027.                     void main()
  8028.                       {
  8029.                         int handle, rc;
  8030.                         struct stat buf;
  8031.                         handle = open( "file", O_RDONLY );
  8032.                         if( handle != -1 ) {
  8033.                           rc = fstat( handle, &buf );
  8034.                           if( rc != -1 )
  8035.                             printf( "File size = %d\n", buf.st_size );
  8036.                           close( handle );
  8037.                         }
  8038.                       }
  8039.  
  8040. Classification: POSIX 1003.1 
  8041.  
  8042.  
  8043. ΓòÉΓòÉΓòÉ 131. ftell ΓòÉΓòÉΓòÉ
  8044.  
  8045. Synopsis: 
  8046.  
  8047.                     #include <stdio.h>
  8048.                     long int ftell( FILE *fp );
  8049.  
  8050. Description: The ftell function returns the current read/write position of the 
  8051.           file specified by fp. This position defines the character that will 
  8052.           be read or written by the next I/O operation on the file.  The value 
  8053.           returned by ftell can be used in a subsequent call to fseek to set 
  8054.           the file to the same position. 
  8055.  
  8056. Returns:  The ftell function returns the current read/write position of the 
  8057.           file specified by fp. When an error is detected, -1L is returned. 
  8058.           When an error has occurred, errno contains a value indicating the 
  8059.           type of error that has been detected. 
  8060.  
  8061. See Also: fgetpos, fopen, fsetpos, fseek 
  8062.  
  8063. Example: 
  8064.  
  8065.                     #include <stdio.h>
  8066.                     long int filesize( FILE *fp )
  8067.                       {
  8068.                         long int save_pos, size_of_file;
  8069.                         save_pos = ftell( fp );
  8070.                         fseek( fp, 0L, SEEK_END );
  8071.                         size_of_file = ftell( fp );
  8072.                         fseek( fp, save_pos, SEEK_SET );
  8073.                         return( size_of_file );
  8074.                       }
  8075.                     void main()
  8076.                       {
  8077.                         FILE *fp;
  8078.  
  8079.                         fp = fopen( "file", "r" );
  8080.                         if( fp != NULL ) {
  8081.                           printf( "File size=%ld\n", filesize( fp ) );
  8082.                           fclose( fp );
  8083.                         }
  8084.                       }
  8085.  
  8086. Classification: ANSI 
  8087.  
  8088.  
  8089. ΓòÉΓòÉΓòÉ 132. ftime ΓòÉΓòÉΓòÉ
  8090.  
  8091. Synopsis: 
  8092.  
  8093.                     #include <sys\timeb.h>
  8094.                     void ftime( struct timeb *timeptr );
  8095.  
  8096.                     struct timeb {
  8097.                      time_t time;  /* time in seconds since Jan 1, 1970 UTC */
  8098.                      unsigned short millitm; /* milliseconds */
  8099.                      short timezone; /* difference in minutes from UTC */
  8100.                      short dstflag;  /* nonzero if in daylight savings time */
  8101.                     };
  8102.  
  8103. Description: The ftime function gets the current time and stores it in the 
  8104.           structure pointed to by timeptr. 
  8105.  
  8106. Returns:  The ftime function fills in the fields of the structure pointed to by 
  8107.           timeptr. There is no return value. 
  8108.  
  8109. See Also: asctime, clock, ctime, difftime, gmtime, localtime, mktime, strftime, 
  8110.           time, tzset 
  8111.  
  8112. Example: 
  8113.  
  8114.                     #include <stdio.h>
  8115.                     #include <time.h>
  8116.                     #include <sys\timeb.h>
  8117.                     void main()
  8118.                       {
  8119.                         struct timeb timebuf;
  8120.                         char   *tod;
  8121.                         ftime( &timebuf );
  8122.                         tod = ctime( &timebuf.time );
  8123.                         printf( "The time is %.19s.%hu %s",
  8124.                             tod, timebuf.millitm, &tod[20] );
  8125.                       }
  8126.  
  8127.           produces the following: 
  8128.  
  8129.                     The time is Tue Dec 25 15:58:42.870 1990
  8130.  
  8131. Classification: WATCOM 
  8132.  
  8133.  
  8134. ΓòÉΓòÉΓòÉ 133. _fullpath ΓòÉΓòÉΓòÉ
  8135.  
  8136. Synopsis: 
  8137.  
  8138.                     #include <stdlib.h>
  8139.                     char *_fullpath( char *buff,
  8140.                                      const char *path,
  8141.                                      size_t size );
  8142.  
  8143. Description: The _fullpath function returns the full pathname of the file 
  8144.           specification in path in the specified buffer buff of length size. 
  8145.  
  8146.           The maximum size that might be required for buff is PATH_MAX. If the 
  8147.           buffer provided is too small, NULL is returned and errno is set.  If 
  8148.           buff is NULL then a buffer of size PATH_MAX is allocated using 
  8149.           malloc. 
  8150.  
  8151.           If path is NULL or points to a null string ("") then the current 
  8152.           working directory is returned in buff. 
  8153.  
  8154. Returns:  The _fullpath function returns a pointer to the full path 
  8155.           specification if no error occurred.  Otherwise NULL is returned. 
  8156.  
  8157. Errors:   When an error has occurred, errno contains a value indicating the 
  8158.           type of error that has been detected. 
  8159.  
  8160.    Constant      Meaning 
  8161.    ENOENT        The current working directory could not be obtained. 
  8162.    ENOMEM        The buffer could not be allocated. 
  8163.    ERANGE        The buffer passed was too small. 
  8164.  
  8165. See Also: _makepath, _splitpath 
  8166.  
  8167. Example: 
  8168.  
  8169.                     #include <stdio.h>
  8170.                     #include <stdlib.h>
  8171.                     void main( int argc, char *argv[] )
  8172.                       {
  8173.                         int i;
  8174.                         char buff[ PATH_MAX ];
  8175.                         for( i = 1; i < argc; ++i ) {
  8176.                           puts( argv[i] );
  8177.                           if( _fullpath( buff, argv[i], PATH_MAX ) ) {
  8178.                             puts( buff );
  8179.                           } else {
  8180.                             puts( "FAIL!" );
  8181.                           }
  8182.                         }
  8183.                       }
  8184.  
  8185. Classification: WATCOM 
  8186.  
  8187.  
  8188. ΓòÉΓòÉΓòÉ 134. fwrite ΓòÉΓòÉΓòÉ
  8189.  
  8190. Synopsis: 
  8191.  
  8192.                     #include <stdio.h>
  8193.                     size_t fwrite( const void *buf,
  8194.                                    size_t elsize,
  8195.                                    size_t nelem,
  8196.                                    FILE *fp );
  8197.  
  8198. Description: The fwrite function writes nelem elements of elsize bytes each to 
  8199.           the file specified by fp. 
  8200.  
  8201. Returns:  The fwrite function returns the number of complete elements 
  8202.           successfully written.  This value will be less than the requested 
  8203.           number of elements only if a write error occurs.  When an error has 
  8204.           occurred, errno contains a value indicating the type of error that 
  8205.           has been detected. 
  8206.  
  8207. See Also: ferror, fopen 
  8208.  
  8209. Example: 
  8210.  
  8211.                     #include <stdio.h>
  8212.  
  8213.                     struct student_data {
  8214.                         int  student_id;
  8215.                         unsigned char marks[10];
  8216.                     };
  8217.                     void main()
  8218.                       {
  8219.                         FILE *fp;
  8220.                         struct student_data std;
  8221.                         int i;
  8222.                         fp = fopen( "file", "w" );
  8223.                         if( fp != NULL ) {
  8224.                           std.student_id = 1001;
  8225.                           for( i = 0; i < 10; i++ )
  8226.                             std.marks[ i ] = 85 + i;
  8227.                           /* write student record with marks */
  8228.                           i = fwrite( &std, sizeof(std), 1, fp );
  8229.                           printf( "%d record written\n", i );
  8230.                           fclose( fp );
  8231.                         }
  8232.                       }
  8233.  
  8234. Classification: ANSI 
  8235.  
  8236.  
  8237. ΓòÉΓòÉΓòÉ 135. gcvt ΓòÉΓòÉΓòÉ
  8238.  
  8239. Synopsis: 
  8240.  
  8241.                     #include <stdlib.h>
  8242.                     char *gcvt( double value,
  8243.                                 int ndigits,
  8244.                                 char *buffer );
  8245.  
  8246. Description: The gcvt function converts the floating-point number value into a 
  8247.           character string and stores the result in buffer. The parameter 
  8248.           ndigits specifies the number of significant digits desired.  The 
  8249.           converted number will be rounded to this position. 
  8250.  
  8251.           If the exponent of the number is less than -4 or is greater than or 
  8252.           equal to the number of significant digits wanted, then the number is 
  8253.           converted into E-format, otherwise the number is formatted using 
  8254.           F-format. 
  8255.  
  8256. Returns:  The gcvt function returns a pointer to the string of digits. 
  8257.  
  8258. See Also: ecvt, fcvt, printf 
  8259.  
  8260. Example: 
  8261.  
  8262.                     #include <stdio.h>
  8263.                     #include <stdlib.h>
  8264.  
  8265.                     void main()
  8266.                       {
  8267.                         char buffer[80];
  8268.  
  8269.                         printf( "%s\n", gcvt( -123.456789, 5, buffer ) );
  8270.                         printf( "%s\n", gcvt( 123.456789E+12, 5, buffer ) );
  8271.                       }
  8272.  
  8273.           produces the following: 
  8274.  
  8275.                     -123.46
  8276.                     1.2346E+014
  8277.  
  8278. Classification: WATCOM 
  8279.  
  8280.  
  8281. ΓòÉΓòÉΓòÉ 136. getc ΓòÉΓòÉΓòÉ
  8282.  
  8283. Synopsis: 
  8284.  
  8285.                     #include <stdio.h>
  8286.                     int getc( FILE *fp );
  8287.  
  8288. Description: The getc function gets the next character from the file designated 
  8289.           by fp. The character is returned as an int value.  The getc function 
  8290.           is equivalent to fgetc, except that it may be implemented as a macro. 
  8291.  
  8292. Returns:  The getc function returns the next character from the input stream 
  8293.           pointed to by fp. If the stream is at end-of-file, the end-of-file 
  8294.           indicator is set and getc returns EOF. If a read error occurs, the 
  8295.           error indicator is set and getc returns EOF. When an error has 
  8296.           occurred, errno contains a value indicating the type of error that 
  8297.           has been detected. 
  8298.  
  8299. See Also: fgetc, fgetchar, fgets, fopen, getchar, gets, ungetc 
  8300.  
  8301. Example: 
  8302.  
  8303.                     #include <stdio.h>
  8304.  
  8305.                     void main()
  8306.                       {
  8307.                         FILE *fp;
  8308.                         int c;
  8309.  
  8310.                         fp = fopen( "file", "r" );
  8311.                         if( fp != NULL ) {
  8312.                           while( (c = getc( fp )) != EOF )
  8313.                             putchar(c);
  8314.                           fclose( fp );
  8315.                         }
  8316.                       }
  8317.  
  8318. Classification: ANSI 
  8319.  
  8320.  
  8321. ΓòÉΓòÉΓòÉ 137. getch ΓòÉΓòÉΓòÉ
  8322.  
  8323. Synopsis: 
  8324.  
  8325.                     #include <conio.h>
  8326.                     int getch( void );
  8327.  
  8328. Description: The getch function obtains the next available keystroke from the 
  8329.           console.  Nothing is echoed on the screen (the function getche will 
  8330.           echo the keystroke, if possible).  When no keystroke is available, 
  8331.           the function waits until a key is depressed. 
  8332.  
  8333.           The kbhit function can be used to determine if a keystroke is 
  8334.           available. 
  8335.  
  8336. Returns:  A value of EOF is returned when an error is detected; otherwise the 
  8337.           getch function returns the value of the keystroke (or character). 
  8338.  
  8339.           When the keystroke represents an extended function key (for example, 
  8340.           a function key, a cursor-movement key or the ALT key with a letter or 
  8341.           a digit), zero is returned and the next call to getch returns a value 
  8342.           for the extended function. 
  8343.  
  8344. See Also: getche, kbhit, putch, ungetch 
  8345.  
  8346. Example: 
  8347.  
  8348.                     #include <stdio.h>
  8349.                     #include <conio.h>
  8350.  
  8351.                     void main()
  8352.                       {
  8353.                         int c;
  8354.  
  8355.                         printf( "Press any key\n" );
  8356.                         c = getch();
  8357.                         printf( "You pressed %c(%d)\n", c, c );
  8358.                       }
  8359.  
  8360. Classification: WATCOM 
  8361.  
  8362.  
  8363. ΓòÉΓòÉΓòÉ 138. getchar ΓòÉΓòÉΓòÉ
  8364.  
  8365. Synopsis: 
  8366.  
  8367.                     #include <stdio.h>
  8368.                     int getchar( void );
  8369.  
  8370. Description: The getchar function is equivalent to getc with the argument 
  8371.           stdin. 
  8372.  
  8373. Returns:  The getchar function returns the next character from the input stream 
  8374.           pointed to by stdin. If the stream is at end-of-file, the end-of-file 
  8375.           indicator is set and getchar returns EOF. If a read error occurs, the 
  8376.           error indicator is set and getchar returns EOF. When an error has 
  8377.           occurred, errno contains a value indicating the type of error that 
  8378.           has been detected. 
  8379.  
  8380. See Also: fgetc, fgetchar, getc 
  8381.  
  8382. Example: 
  8383.  
  8384.                     #include <stdio.h>
  8385.                     void main()
  8386.                       {
  8387.                         FILE *fp;
  8388.                         int c;
  8389.  
  8390.                         fp = freopen( "file", "r", stdin );
  8391.                         while( (c = getchar()) != EOF )
  8392.                           putchar(c);
  8393.                         fclose( fp );
  8394.                       }
  8395.  
  8396. Classification: ANSI 
  8397.  
  8398.  
  8399. ΓòÉΓòÉΓòÉ 139. getche ΓòÉΓòÉΓòÉ
  8400.  
  8401. Synopsis: 
  8402.  
  8403.                     #include <conio.h>
  8404.                     int getche( void );
  8405.  
  8406. Description: The getche function obtains the next available keystroke from the 
  8407.           console.  The function will wait until a keystroke is available. That 
  8408.           character is echoed on the screen at the position of the cursor (use 
  8409.           getch when it is not desired to echo the keystroke). 
  8410.  
  8411.           The kbhit function can be used to determine if a keystroke is 
  8412.           available. 
  8413.  
  8414. Returns:  A value of EOF is returned when an error is detected; otherwise, the 
  8415.           getche function returns the value of the keystroke (or character). 
  8416.  
  8417.           When the keystroke represents an extended function key (for example, 
  8418.           a function key, a cursor-movement key or the ALT key with a letter or 
  8419.           a digit), zero is returned and the next call to getche returns a 
  8420.           value for the extended function. 
  8421.  
  8422. See Also: getch, kbhit, putch, ungetch 
  8423.  
  8424. Classification: WATCOM 
  8425.  
  8426.  
  8427. ΓòÉΓòÉΓòÉ 140. getcmd ΓòÉΓòÉΓòÉ
  8428.  
  8429. Synopsis: 
  8430.  
  8431.                     #include <process.h>
  8432.                     char *getcmd( char *cmd_line );
  8433.  
  8434. Description: The getcmd function causes the command line information, with the 
  8435.           program name removed, to be copied to cmd_line. The information is 
  8436.           terminated with a '\0' character.  This provides a method of 
  8437.           obtaining the original parameters to a program unchanged (with the 
  8438.           white space intact). 
  8439.  
  8440.           This information can also be obtained by examining the vector of 
  8441.           program parameters passed to the main function in the program. 
  8442.  
  8443. Returns:  The address of the target cmd_line is returned. 
  8444.  
  8445. See Also: abort, atexit, exec Functions, exit, _exit, getenv, main, onexit, 
  8446.           putenv, spawn Functions, system 
  8447.  
  8448. Example: 
  8449.  
  8450.           Suppose a program were invoked with the DOS command line 
  8451.  
  8452.                     myprog arg-1 ( my   stuff ) here
  8453.  
  8454.           where that program contains 
  8455.  
  8456.                     #include <stdio.h>
  8457.                     #include <process.h>
  8458.  
  8459.                     void main()
  8460.                       {
  8461.                         char cmds[128];
  8462.  
  8463.                         printf( "%s\n", getcmd( cmds ) );
  8464.                       }
  8465.  
  8466.           produces the following: 
  8467.  
  8468.                     arg-1 ( my   stuff ) here
  8469.  
  8470. Classification: WATCOM 
  8471.  
  8472.  
  8473. ΓòÉΓòÉΓòÉ 141. getcwd ΓòÉΓòÉΓòÉ
  8474.  
  8475. Synopsis: 
  8476.  
  8477.                     #include <direct.h>
  8478.                     char *getcwd( char *buffer, int size );
  8479.  
  8480. Description: The getcwd function returns the name of the current working 
  8481.           directory.  The buffer address is either NULL or is the location at 
  8482.           which a string containing the name of the current working directory 
  8483.           is placed.  In the latter case, the value of size is the length 
  8484.           (including the delimiting '\0' character) which can be be used to 
  8485.           store this name. 
  8486.  
  8487.           Extension:  When buffer has a value of NULL, a string is allocated to 
  8488.           contain the name of the current working directory. This string may be 
  8489.           freed using the free function. 
  8490.  
  8491. Returns:  The getcwd function returns the address of the string containing the 
  8492.           name of the current working directory, unless an error occurs, in 
  8493.           which case NULL is returned. 
  8494.  
  8495. Errors:   When an error has occurred, errno contains a value indicating the 
  8496.           type of error that has been detected. 
  8497.  
  8498.    Constant      Meaning 
  8499.    EINVAL        The argument size is negative. 
  8500.    ENOMEM        Not enough memory to allocate a buffer. 
  8501.    ERANGE        The buffer is too small (specified by size ) to contain the 
  8502.                  name of the current working directory. 
  8503.  
  8504. See Also: chdir, mkdir, rmdir 
  8505.  
  8506. Example: 
  8507.  
  8508.                     #include <stdio.h>
  8509.                     #include <stdlib.h>
  8510.                     #include <direct.h>
  8511.  
  8512.                     void main()
  8513.                       {
  8514.                         char *cwd;
  8515.  
  8516.                         cwd = getcwd( NULL, 0 );
  8517.                         if( cwd != NULL ) {
  8518.                           printf( "My working directory is %s\n", cwd );
  8519.                           free( cwd );
  8520.                         }
  8521.                       }
  8522.  
  8523.           produces the following: 
  8524.  
  8525.                     My working directory is C:\PROJECT\C
  8526.  
  8527. Classification: POSIX 1003.1 with extensions 
  8528.  
  8529.  
  8530. ΓòÉΓòÉΓòÉ 142. getenv ΓòÉΓòÉΓòÉ
  8531.  
  8532. Synopsis: 
  8533.  
  8534.                     #include <stdlib.h>
  8535.                     char *getenv( const char *name );
  8536.  
  8537. Description: The getenv function searches the environment list for an entry 
  8538.           matching the string pointed to by name. The matching is 
  8539.           case-insensitive; all lower-case letters are treated as if they were 
  8540.           in upper case. 
  8541.  
  8542.           Entries can be added to the environment list with the DOS set command 
  8543.           or with the putenv or setenv functions.  All entries in the 
  8544.           environment list can be displayed by using the DOS set command with 
  8545.           no arguments. 
  8546.  
  8547.           To assign a string to a variable and place it in the environment 
  8548.           list: 
  8549.  
  8550.                         C>SET INCLUDE=C:\WATCOM\H
  8551.  
  8552.           To see what variables are in the environment list, and their current 
  8553.           assignments: 
  8554.  
  8555.                         C>SET
  8556.                         COMSPEC=C:\COMMAND.COM
  8557.                         PATH=C:\;C:\WATCOM
  8558.                         INCLUDE=C:\WATCOM\H
  8559.  
  8560. Returns:  The getenv function returns a pointer to the string assigned to the 
  8561.           environment variable if found, and NULL if no match was found.  Note: 
  8562.           the value returned should be duplicated if you intend to modify the 
  8563.           contents of the string. 
  8564.  
  8565. See Also: clearenv, exec Functions, putenv, setenv, spawn Functions, system 
  8566.  
  8567. Example: 
  8568.  
  8569.                     #include <stdio.h>
  8570.                     #include <stdlib.h>
  8571.  
  8572.                     void main()
  8573.                       {
  8574.                         char *path;
  8575.  
  8576.                         path = getenv( "INCLUDE" );
  8577.                         if( path != NULL )
  8578.                           printf( "INCLUDE=%s\n", path );
  8579.                       }
  8580.  
  8581. Classification: ANSI 
  8582.  
  8583.  
  8584. ΓòÉΓòÉΓòÉ 143. getpid ΓòÉΓòÉΓòÉ
  8585.  
  8586. Synopsis: 
  8587.  
  8588.                     #include <process.h>
  8589.                     int getpid(void);
  8590.  
  8591. Description: The getpid function returns the process id for the current 
  8592.           process. 
  8593.  
  8594. Returns:  The getpid function returns the process id for the current process. 
  8595.  
  8596. Example: 
  8597.  
  8598.                     #include <stdio.h>
  8599.                     #include <process.h>
  8600.  
  8601.                     void main()
  8602.                       {
  8603.                         unsigned int process_id;
  8604.                         auto char filename[13];
  8605.  
  8606.                         process_id = getpid();
  8607.                         /* use this to create a unique file name */
  8608.                         sprintf( filename, "TMP%4.4x.TMP", process_id );
  8609.                       }
  8610.  
  8611. Classification: POSIX 1003.1 
  8612.  
  8613.  
  8614. ΓòÉΓòÉΓòÉ 144. gets ΓòÉΓòÉΓòÉ
  8615.  
  8616. Synopsis: 
  8617.  
  8618.                     #include <stdio.h>
  8619.                     char *gets( char *buf );
  8620.  
  8621. Description: The gets function gets a string of characters from the file 
  8622.           designated by stdin and stores them in the array pointed to by buf 
  8623.           until end-of-file is encountered or a new-line character is read. 
  8624.           Any new-line character is discarded, and a null character is placed 
  8625.           immediately after the last character read into the array. 
  8626.  
  8627.           It is recommended that fgets be used instead of gets because data 
  8628.           beyond the array buf will be destroyed if a new-line character is not 
  8629.           read from the input stream stdin before the end of the array buf is 
  8630.           reached. 
  8631.  
  8632.           A common programming error is to assume the presence of a new-line 
  8633.           character in every string that is read into the array.  A new-line 
  8634.           character may not appear as the last character in a file, just before 
  8635.           end-of-file. 
  8636.  
  8637. Returns:  The gets function returns buf if successful. NULL is returned if 
  8638.           end-of-file is encountered, or if a read error occurs.  When an error 
  8639.           has occurred, errno contains a value indicating the type of error 
  8640.           that has been detected. 
  8641.  
  8642. See Also: fopen, getc, fgetc, fgets, ungetc 
  8643.  
  8644. Example: 
  8645.  
  8646.                     #include <stdio.h>
  8647.  
  8648.                     void main()
  8649.                       {
  8650.                         char buffer[80];
  8651.  
  8652.                         while( gets( buffer ) != NULL )
  8653.                           puts( buffer );
  8654.                       }
  8655.  
  8656. Classification: ANSI 
  8657.  
  8658.  
  8659. ΓòÉΓòÉΓòÉ 145. gmtime, _gmtime ΓòÉΓòÉΓòÉ
  8660.  
  8661. Synopsis: 
  8662.  
  8663.                     #include <time.h>
  8664.                     struct tm * gmtime( const time_t *timer );
  8665.                     struct tm *_gmtime( const time_t *timer,
  8666.                                         struct tm *tmbuf );
  8667.  
  8668.                     struct tm {
  8669.                       int tm_sec;   /* seconds after the minute -- [0,61] */
  8670.                       int tm_min;   /* minutes after the hour -- [0,59] */
  8671.                       int tm_hour;  /* hours after midnight -- [0,23] */
  8672.                       int tm_mday;  /* day of the month -- [1,31] */
  8673.                       int tm_mon;   /* months since January -- [0,11] */
  8674.                       int tm_year;  /* years since 1900 */
  8675.                       int tm_wday;  /* days since Sunday -- [0,6] */
  8676.                       int tm_yday;  /* days since January 1 -- [0,365]*/
  8677.                       int tm_isdst; /* Daylight Savings Time flag */
  8678.                     };
  8679.  
  8680. Description: The gmtime functions convert the calendar time pointed to by timer 
  8681.           into a broken-down time, expressed as Coordinated Universal Time 
  8682.           (UTC) (formerly known as Greenwich Mean Time (GMT)). 
  8683.  
  8684.           The function _gmtime places the converted time in the tm structure 
  8685.           pointed to by tmbuf, and the function gmtime places the converted 
  8686.           time in a static structure that is re-used each time gmtime is 
  8687.           called. 
  8688.  
  8689.           The time set on the computer with the DOS time command and the DOS 
  8690.           date command reflects the local time.  The environment variable TZ is 
  8691.           used to establish the time zone to which this local time applies. 
  8692.           See the section The TZ Environment Variable  for a discussion of how 
  8693.           to set the time zone. 
  8694.  
  8695. Returns:  The gmtime functions return a pointer to a structure containing the 
  8696.           broken-down time. 
  8697.  
  8698. See Also: asctime, clock, ctime, difftime, localtime, mktime, strftime, time, 
  8699.           tzset 
  8700.  
  8701. Example: 
  8702.  
  8703.                     #include <stdio.h>
  8704.                     #include <time.h>
  8705.  
  8706.                     void main()
  8707.                       {
  8708.                         time_t time_of_day;
  8709.                         auto char buf[26];
  8710.                         auto struct tm tmbuf;
  8711.                         time_of_day = time( NULL );
  8712.                         _gmtime( &time_of_day, &tmbuf );
  8713.                         printf( "It is now: %.24s GMT\n",
  8714.                                 _asctime( &tmbuf, buf ) );
  8715.                       }
  8716.  
  8717.           produces the following: 
  8718.  
  8719.                     It is now: Fri Dec 25 15:58:27 1987 GMT
  8720.  
  8721. Classification: gmtime is ANSI, _gmtime is not ANSI 
  8722.  
  8723.  
  8724. ΓòÉΓòÉΓòÉ 146. halloc ΓòÉΓòÉΓòÉ
  8725.  
  8726. Synopsis: 
  8727.  
  8728.                     #include <malloc.h>
  8729.                     void __huge *halloc( long int numb, size_t size );
  8730.  
  8731. Description: The halloc function allocates space for an array of numb objects 
  8732.           of size bytes each and initializes each object to 0.  When the size 
  8733.           of the array is greater than 128K bytes, the size must be a power of 
  8734.           2. 
  8735.  
  8736. Returns:  The halloc function returns a far pointer (of type void huge * ) to 
  8737.           the start of the allocated memory.  The return value is NULL if there 
  8738.           is insufficient memory available. 
  8739.  
  8740. See Also: calloc Functions, _expand Functions, free Functions, hfree, malloc 
  8741.           Functions, _msize Functions, realloc Functions, sbrk 
  8742.  
  8743. Example: 
  8744.  
  8745.                     #include <stdio.h>
  8746.                     #include <malloc.h>
  8747.  
  8748.                     void main()
  8749.                       {
  8750.                         long int __huge *big_buffer;
  8751.  
  8752.                         big_buffer = (long int __huge *)
  8753.                                       halloc( 1024L, sizeof(long) );
  8754.                         if( big_buffer == NULL ) {
  8755.                           printf( "Unable to allocate memory\n" );
  8756.                         } else {
  8757.  
  8758.                           /* rest of code goes here */
  8759.  
  8760.                           hfree( big_buffer );  /* deallocate */
  8761.                         }
  8762.                       }
  8763.  
  8764. Classification: WATCOM 
  8765.  
  8766.  
  8767. ΓòÉΓòÉΓòÉ 147. _harderr ΓòÉΓòÉΓòÉ
  8768.  
  8769. Synopsis: 
  8770.  
  8771.                     #include <dos.h>
  8772.                     void _harderr( int (__far *funcptr)() );
  8773.                     void _hardresume( int action );
  8774.  
  8775. Description: The _harderr routine installs a critical error handler (for INT 
  8776.           0x24) to handle hardware errors.  This critical error handler will 
  8777.           call the function specified by funcptr when a critical error occurs 
  8778.           (for example, attempting to open a file on a floppy disk when the 
  8779.           drive door is open).  The parameters to this function are as follows: 
  8780.  
  8781.                     int handler( unsigned deverror,
  8782.                                  unsigned errcode,
  8783.                                  unsigned __far *devhdr );
  8784.  
  8785.           The low-order byte of errcode can be one of the following values: 
  8786.  
  8787.    Value     Meaning 
  8788.    0x00      Attempt to write to a write-protected disk 
  8789.    0x01      Unknown unit 
  8790.    0x02      Drive not ready 
  8791.    0x03      Unknown command 
  8792.    0x04      CRC error in data 
  8793.    0x05      Bad drive-request structure length 
  8794.    0x06      Seek error 
  8795.    0x07      Unknown media type 
  8796.    0x08      Sector not found 
  8797.    0x09      Printer out of paper 
  8798.    0x0A      Write fault 
  8799.    0x0B      Read fault 
  8800.    0x0C      General failure 
  8801.  
  8802.           The devhdr argument points to a device header control-block that 
  8803.           contains information about the device on which the error occurred. 
  8804.           Your error handler may inspect the information in this control-block 
  8805.           but must not change it. 
  8806.  
  8807.           If the error occurred on a disk device, bit 15 of the deverror 
  8808.           argument will be 0 and the deverror argument will indicate the 
  8809.           following: 
  8810.  
  8811.    Bit       Meaning 
  8812.    bit 15    0 indicates disk error 
  8813.    bit 14    not used 
  8814.    bit 13    0 indicates "Ignore" response not allowed 
  8815.    bit 12    0 indicates "Retry" response not allowed 
  8816.    bit 11    0 indicates "Fail" response not allowed 
  8817.    bit 9,10  location of error 
  8818.  
  8819.       Value     Meaning 
  8820.       00        MS-DOS 
  8821.       01        File Allocation Table (FAT) 
  8822.       10        Directory 
  8823.       11        Data area 
  8824.    bit 8     0 indicates read error, 1 indicates write error 
  8825.  
  8826.           The low-order byte of deverror indicates the drive where the error 
  8827.           occurred; (0 = drive A, 1 = drive B, etc.). 
  8828.  
  8829.           The handler is very restricted in the type of system calls that it 
  8830.           can perform.  System calls 0x01 through 0x0C, and 0x59 are the only 
  8831.           system calls allowed to be issued by the handler.  Therefore, many of 
  8832.           the standard C run-time functions such as stream I/O and low-level 
  8833.           I/O cannot be used by the handler.  Console I/O is allowed (eg. 
  8834.           cprintf, cputs). 
  8835.  
  8836.           The handler must indicate what action to take by returning one of the 
  8837.           following values or calling _hardresume with one of the following 
  8838.           values: 
  8839.  
  8840.    Value                   Meaning 
  8841.    _HARDERR_IGNORE         Ignore the error 
  8842.    _HARDERR_RETRY          Retry the operation 
  8843.    _HARDERR_ABORT          Abort the program issuing INT 0x23 
  8844.    _HARDERR_FAIL           Fail the system call that is in progress (DOS 3.0 or 
  8845.                            higher) 
  8846.  
  8847.           See The MS-DOS Encyclopedia  for more detailed information on 
  8848.           determining the type of error that has occurred. 
  8849.  
  8850. Returns:  The _harderr routine does not return a value. 
  8851.  
  8852. See Also: _chain_intr, _dos_getvect, _dos_setvect 
  8853.  
  8854. Example: 
  8855.  
  8856.                     #include <stdio.h>
  8857.                     #include <conio.h>
  8858.                     #include <dos.h>
  8859.                     int __far critical_error_handler( unsigned deverr,
  8860.                                                       unsigned errcode,
  8861.                                                       unsigned far *devhdr )
  8862.                       {
  8863.                         cprintf( "Critical error: " );
  8864.                         cprintf( "deverr=%4.4X errcode=%d\r\n",
  8865.                                  deverr, errcode );
  8866.                         cprintf( "devhdr = %Fp\r\n", devhdr );
  8867.                         return( _HARDERR_IGNORE );
  8868.                       }
  8869.                     main()
  8870.                       {
  8871.                         FILE *fp;
  8872.  
  8873.                         _harderr( critical_error_handler );
  8874.                         fp = fopen( "a:tmp.tmp", "r" );
  8875.                         printf( "fp = %p\n", fp );
  8876.                       }
  8877.  
  8878.           produces the following: 
  8879.  
  8880.                     Critical error: deverr=1A00 errcode=2
  8881.                     devhdr = 0070:01b6
  8882.                     fp = 0000
  8883.  
  8884. Classification: DOS 
  8885.  
  8886.  
  8887. ΓòÉΓòÉΓòÉ 148. _heapchk Functions ΓòÉΓòÉΓòÉ
  8888.  
  8889. Synopsis: 
  8890.  
  8891.                     #include <malloc.h>
  8892.                     int  _heapchk( void );
  8893.                     int _bheapchk( __segment seg );
  8894.                     int _fheapchk( void );
  8895.                     int _nheapchk( void );
  8896.  
  8897. Description: The _heapchk functions along with _heapset and _heapwalk are 
  8898.           provided for debugging heap related problems in programs. 
  8899.  
  8900.           The _heapchk functions perform a consistency check on the unallocated 
  8901.           memory space or "heap".  The consistency check determines whether all 
  8902.           the heap entries are valid.  Each function checks a particular heap, 
  8903.           as listed below: 
  8904.  
  8905.    Function        Heap Checked 
  8906.    _heapchk        Depends on data model of the program 
  8907.    _bheapchk       Based heap specified by seg value; _NULLSEG specifies all 
  8908.                    based heaps 
  8909.    _fheapchk       Far heap (outside the default data segment) 
  8910.    _nheapchk       Near heap (inside the default data segment) 
  8911.  
  8912.           In a small data memory model, the _heapchk function is equivalent to 
  8913.           the _nheapchk function; in a large data memory model, the _heapchk 
  8914.           function is equivalent to the _fheapchk function. 
  8915.  
  8916. Returns:  All four functions return one of the following manifest constants 
  8917.           which are defined in <malloc.h>. 
  8918.  
  8919.    Constant            Meaning 
  8920.    _HEAPOK             The heap appears to be consistent. 
  8921.    _HEAPEMPTY          The heap is empty. 
  8922.    _HEAPBADBEGIN       The heap has been damaged. 
  8923.    _HEAPBADNODE        The heap contains a bad node, or is damaged. 
  8924.  
  8925. See Also: _heapset, _heapwalk 
  8926.  
  8927. Example: 
  8928.  
  8929.                     #include <stdio.h>
  8930.                     #include <malloc.h>
  8931.                     void main()
  8932.                       {
  8933.                         char *buffer;
  8934.                         buffer = (char *)malloc( 80 );
  8935.                         malloc( 1024 );
  8936.                         free( buffer );
  8937.                         switch( _heapchk() ) {
  8938.                         case _HEAPOK:
  8939.                           printf( "OK - heap is good\n" );
  8940.                           break;
  8941.                         case _HEAPEMPTY:
  8942.                           printf( "OK - heap is empty\n" );
  8943.                           break;
  8944.                         case _HEAPBADBEGIN:
  8945.                           printf( "ERROR - heap is damaged\n" );
  8946.                           break;
  8947.                         case _HEAPBADNODE:
  8948.                           printf( "ERROR - bad node in heap\n" );
  8949.                           break;
  8950.                         }
  8951.                       }
  8952.  
  8953. Classification: WATCOM 
  8954.  
  8955.  
  8956. ΓòÉΓòÉΓòÉ 149. _heapgrow Functions ΓòÉΓòÉΓòÉ
  8957.  
  8958. Synopsis: 
  8959.  
  8960.                     #include <malloc.h>
  8961.                     void  _heapgrow( void );
  8962.                     void _nheapgrow( void );
  8963.                     void _fheapgrow( void );
  8964.  
  8965. Description: The _nheapgrow function attempts to grow the near heap to the 
  8966.           maximum size of 64K.  You will want to do this in the small data 
  8967.           models if you are using both malloc and _fmalloc or halloc. Once a 
  8968.           call to _fmalloc or halloc has been made, you may not be able to 
  8969.           allocate any memory with malloc unless space has been reserved for 
  8970.           the near heap using either malloc, sbrk or _nheapgrow. 
  8971.  
  8972.           The _fheapgrow function doesn't do anything to the heap because the 
  8973.           far heap will be extended automatically when needed.  If the current 
  8974.           far heap cannot be extended, then another far heap will be started. 
  8975.  
  8976.           In a small data memory model, the _heapgrow function is equivalent to 
  8977.           the _nheapgrow function; in a large data memory model, the _heapgrow 
  8978.           function is equivalent to the _fheapgrow function. 
  8979.  
  8980. Returns:  The _heapgrow functions do not return a value. 
  8981.  
  8982. See Also: _heapmin, _heapshrink 
  8983.  
  8984. Example: 
  8985.  
  8986.                     #include <stdio.h>
  8987.                     #include <malloc.h>
  8988.  
  8989.                     void main()
  8990.                       {
  8991.                          char *p, *fmt_string;
  8992.                          fmt_string = "Amount of memory available is %u\n";
  8993.                          printf( fmt_string, _memavl() );
  8994.                          _nheapgrow();
  8995.                          printf( fmt_string, _memavl() );
  8996.                          p = malloc( 2000 );
  8997.                          printf( fmt_string, _memavl() );
  8998.                       }
  8999.  
  9000.           produces the following: 
  9001.  
  9002.                     Amount of memory available is 0
  9003.                     Amount of memory available is 62732
  9004.                     Amount of memory available is 60730
  9005.  
  9006. Classification: WATCOM 
  9007.  
  9008.  
  9009. ΓòÉΓòÉΓòÉ 150. _heapmin Functions ΓòÉΓòÉΓòÉ
  9010.  
  9011. Synopsis: 
  9012.  
  9013.                     #include <malloc.h>
  9014.                     int  _heapmin( void );
  9015.                     int _bheapmin( __segment seg );
  9016.                     int _fheapmin( void );
  9017.                     int _nheapmin( void );
  9018.  
  9019. Description: The _heapmin functions attempt to shrink the specified heap to its 
  9020.           smallest possible size by returning all free entries at the end of 
  9021.           the heap back to the system.  This can be used to free up as much 
  9022.           memory as possible before using the system function or one of the 
  9023.           spawn functions. 
  9024.  
  9025.           The various _heapmin functions shrink the following heaps: 
  9026.  
  9027.    Function        Heap Minimized 
  9028.    _heapmin        Depends on data model of the program 
  9029.    _bheapmin       Based heap specified by seg value; _NULLSEG specifies all 
  9030.                    based heaps 
  9031.    _fheapmin       Far heap (outside the default data segment) 
  9032.    _nheapmin       Near heap (inside the default data segment) 
  9033.  
  9034.           In a small data memory model, the _heapmin function is equivalent to 
  9035.           the _nheapmin function; in a large data memory model, the _heapmin 
  9036.           function is equivalent to the _fheapmin function.  It is identical to 
  9037.           the _heapshrink function. 
  9038.  
  9039. Returns:  The _heapmin functions return zero if successful, and non-zero if 
  9040.           some error occurred. 
  9041.  
  9042. See Also: _heapgrow, _heapshrink 
  9043.  
  9044. Example: 
  9045.  
  9046.                     #include <stdlib.h>
  9047.                     #include <malloc.h>
  9048.  
  9049.                     void main()
  9050.                       {
  9051.                         _heapmin();
  9052.                         system( "chdir c:\\watcomc" );
  9053.                       }
  9054.  
  9055.           Note the use of two adjacent backslash characters (\) within 
  9056.           character-string constants to signify a single backslash. 
  9057.  
  9058.  
  9059. Classification: WATCOM 
  9060.  
  9061.  
  9062. ΓòÉΓòÉΓòÉ 151. _heapset Functions ΓòÉΓòÉΓòÉ
  9063.  
  9064. Synopsis: 
  9065.  
  9066.                     #include <malloc.h>
  9067.                     int  _heapset( unsigned char fill_char );
  9068.                     int _bheapset( __segment seg, unsigned char fill_char );
  9069.                     int _fheapset( unsigned char fill_char );
  9070.                     int _nheapset( unsigned char fill_char );
  9071.  
  9072. Description: The _heapset functions along with _heapchk and _heapwalk are 
  9073.           provided for debugging heap related problems in programs. 
  9074.  
  9075.           The _heapset functions perform a consistency check on the unallocated 
  9076.           memory space or "heap" just as _heapchk does, and sets the heap's 
  9077.           free entries with the fill_char value. 
  9078.  
  9079.           Each function checks and sets a particular heap, as listed below: 
  9080.  
  9081.    Function        Heap Filled 
  9082.    _heapset        Depends on data model of the program 
  9083.    _bheapset       Based heap specified by seg value; _NULLSEG specifies all 
  9084.                    based heaps 
  9085.    _fheapset       Far heap (outside the default data segment) 
  9086.    _nheapset       Near heap (inside the default data segment) 
  9087.  
  9088.           In a small data memory model, the _heapset function is equivalent to 
  9089.           the _nheapset function; in a large data memory model, the _heapset 
  9090.           function is equivalent to the _fheapset function. 
  9091.  
  9092. Returns:  The _heapset functions return one of the following manifest constants 
  9093.           which are defined in <malloc.h>. 
  9094.  
  9095.    Constant            Meaning 
  9096.    _HEAPOK             The heap appears to be consistent. 
  9097.    _HEAPEMPTY          The heap is empty. 
  9098.    _HEAPBADBEGIN       The heap has been damaged. 
  9099.    _HEAPBADNODE        The heap contains a bad node, or is damaged. 
  9100.  
  9101. See Also: _heapchk, _heapwalk 
  9102.  
  9103. Example: 
  9104.  
  9105.                     #include <stdio.h>
  9106.                     #include <malloc.h>
  9107.                     void main()
  9108.                       {
  9109.                         int heap_status;
  9110.                         char *buffer;
  9111.                         buffer = (char *)malloc( 80 );
  9112.                         malloc( 1024 );
  9113.                         free( buffer );
  9114.                         heap_status = _heapset( 0xff );
  9115.                         switch( heap_status ) {
  9116.                         case _HEAPOK:
  9117.                           printf( "OK - heap is good\n" );
  9118.                           break;
  9119.                         case _HEAPEMPTY:
  9120.                           printf( "OK - heap is empty\n" );
  9121.                           break;
  9122.                         case _HEAPBADBEGIN:
  9123.                           printf( "ERROR - heap is damaged\n" );
  9124.                           break;
  9125.                         case _HEAPBADNODE:
  9126.                           printf( "ERROR - bad node in heap\n" );
  9127.                           break;
  9128.                         }
  9129.                       }
  9130.  
  9131. Classification: WATCOM 
  9132.  
  9133.  
  9134. ΓòÉΓòÉΓòÉ 152. _heapshrink Functions ΓòÉΓòÉΓòÉ
  9135.  
  9136. Synopsis: 
  9137.  
  9138.                     #include <malloc.h>
  9139.                     int  _heapshrink( void );
  9140.                     int _bheapshrink( __segment seg );
  9141.                     int _fheapshrink( void );
  9142.                     int _nheapshrink( void );
  9143.  
  9144. Description: The _heapshrink functions attempt to shrink the heap to its 
  9145.           smallest possible size by returning all free entries at the end of 
  9146.           the heap back to the system.  This can be used to free up as much 
  9147.           memory as possible before using the system function or one of the 
  9148.           spawn functions. 
  9149.  
  9150.           The various _heapshrink functions shrink the following heaps: 
  9151.  
  9152.    Function        Heap Shrinked 
  9153.    _heapshrink     Depends on data model of the program 
  9154.    _bheapshrink    Based heap specified by seg value; _NULLSEG specifies all 
  9155.                    based heaps 
  9156.    _fheapshrink    Far heap (outside the default data segment) 
  9157.    _nheapshrink    Near heap (inside the default data segment) 
  9158.  
  9159.           In a small data memory model, the _heapshrink function is equivalent 
  9160.           to the _nheapshrink function; in a large data memory model, the 
  9161.           _heapshrink function is equivalent to the _fheapshrink function.  It 
  9162.           is identical to the _heapmin function. 
  9163.  
  9164. Returns:  The _heapshrink functions return zero if successful, and non-zero if 
  9165.           some error occurred. 
  9166.  
  9167. See Also: _heapgrow, _heapmin 
  9168.  
  9169. Example: 
  9170.  
  9171.                     #include <stdlib.h>
  9172.                     #include <malloc.h>
  9173.  
  9174.                     void main()
  9175.                       {
  9176.                         _heapshrink();
  9177.                         system( "chdir c:\\watcomc" );
  9178.                       }
  9179.  
  9180.           Note the use of two adjacent backslash characters (\) within 
  9181.           character-string constants to signify a single backslash. 
  9182.  
  9183.  
  9184. Classification: WATCOM 
  9185.  
  9186.  
  9187. ΓòÉΓòÉΓòÉ 153. _heapwalk Functions ΓòÉΓòÉΓòÉ
  9188.  
  9189. Synopsis: 
  9190.  
  9191.                     #include <malloc.h>
  9192.                     int  _heapwalk( struct _heapinfo *entry );
  9193.                     int _bheapwalk( __segment seg, struct _heapinfo *entry );
  9194.                     int _fheapwalk( struct _heapinfo *entry );
  9195.                     int _nheapwalk( struct _heapinfo *entry );
  9196.  
  9197.                     struct _heapinfo {
  9198.                         void __far *_pentry;   /* heap pointer */
  9199.                         size_t     _size;      /* heap entry size */
  9200.                         int        _useflag;   /* heap entry 'in-use' flag */
  9201.                     };
  9202.                     #define _USEDENTRY      0
  9203.                     #define _FREEENTRY      1
  9204.  
  9205. Description: The _heapwalk functions along with _heapchk and _heapset are 
  9206.           provided for debugging heap related problems in programs. 
  9207.  
  9208.           The _heapwalk functions walk through the heap, one entry per call, 
  9209.           updating the _heapinfo structure with information on the next heap 
  9210.           entry.  The structure is defined in <malloc.h>. You must initialize 
  9211.           the _pentry field with NULL to start the walk through the heap. 
  9212.  
  9213.           Each function walks a particular heap, as listed below: 
  9214.  
  9215.    Function        Heap Walked 
  9216.    _heapwalk       Depends on data model of the program 
  9217.    _bheapwalk      Based heap specified by seg value; _NULLSEG specifies all 
  9218.                    based heaps 
  9219.    _fheapwalk      Far heap (outside the default data segment) 
  9220.    _nheapwalk      Near heap (inside the default data segment) 
  9221.  
  9222.           In a small data memory model, the _heapwalk function is equivalent to 
  9223.           the _nheapwalk function; in a large data memory model, the _heapwalk 
  9224.           function is equivalent to the _fheapwalk function. 
  9225.  
  9226. Returns:  The _heapwalk functions return one of the following manifest 
  9227.           constants which are defined in <malloc.h>. 
  9228.  
  9229.    Constant            Meaning 
  9230.    _HEAPOK             The heap is OK so far, and the _heapinfo structure 
  9231.                        contains information about the next entry in the heap. 
  9232.    _HEAPEMPTY          The heap is empty. 
  9233.    _HEAPBADPTR         The _pentry field of the entry structure does not 
  9234.                        contain a valid pointer into the heap. 
  9235.    _HEAPBADBEGIN       The header information for the heap was not found or has 
  9236.                        been damaged. 
  9237.    _HEAPBADNODE        The heap contains a bad node, or is damaged. 
  9238.    _HEAPEND            The end of the heap was reached successfully. 
  9239.  
  9240. See Also: _heapchk, _heapset 
  9241.  
  9242. Example: 
  9243.  
  9244.                     #include <stdio.h>
  9245.                     #include <malloc.h>
  9246.  
  9247.                     void main()
  9248.                       {
  9249.                         char *p;
  9250.                         heap_dump();   p = malloc( 80 );
  9251.                         heap_dump();   free( p );
  9252.                         heap_dump();
  9253.                       }
  9254.                     heap_dump()
  9255.                       {
  9256.                         struct _heapinfo h_info;
  9257.                         int heap_status;
  9258.  
  9259.                         h_info._pentry = NULL;
  9260.                         for(;;) {
  9261.                           heap_status = _heapwalk( &h_info );
  9262.                           if( heap_status != _HEAPOK ) break;
  9263.                           printf( "  %s block at %Fp of size %4.4X\n",
  9264.                             (h_info._useflag == _USEDENTRY ? "USED" : "FREE"),
  9265.                             h_info._pentry, h_info._size );
  9266.                         }
  9267.                         switch( heap_status ) {
  9268.                         case _HEAPEND:
  9269.                           printf( "OK - end of heap\n" );
  9270.                           break;
  9271.                         case _HEAPEMPTY:
  9272.                           printf( "OK - heap is empty\n" );
  9273.                           break;
  9274.                         case _HEAPBADBEGIN:
  9275.                           printf( "ERROR - heap is damaged\n" );
  9276.                           break;
  9277.                         case _HEAPBADPTR:
  9278.                           printf( "ERROR - bad pointer to heap\n" );
  9279.                           break;
  9280.                         case _HEAPBADNODE:
  9281.                           printf( "ERROR - bad node in heap\n" );
  9282.                         }
  9283.                       }
  9284.  
  9285.           On 16-bit 80x86 systems, the following output is produced: 
  9286.  
  9287.                     OK - heap is empty
  9288.                       USED block at 23f8:0ab6 of size 0202
  9289.                       USED block at 23f8:0cb8 of size 0052
  9290.                       FREE block at 23f8:0d0a of size 1DA2
  9291.                     OK - end of heap
  9292.                       USED block at 23f8:0ab6 of size 0202
  9293.                       FREE block at 23f8:0cb8 of size 1DF4
  9294.                     OK - end of heap
  9295.  
  9296.           On 32-bit 80386/486 systems, the following output is produced: 
  9297.  
  9298.                     OK - heap is empty
  9299.                       USED block at 0014:00002a7c of size 0204
  9300.                       USED block at 0014:00002c80 of size 0054
  9301.                       FREE block at 0014:00002cd4 of size 1D98
  9302.                     OK - end of heap
  9303.                       USED block at 0014:00002a7c of size 0204
  9304.                       FREE block at 0014:00002c80 of size 1DEC
  9305.                     OK - end of heap
  9306.  
  9307.  
  9308. Classification: WATCOM 
  9309.  
  9310.  
  9311. ΓòÉΓòÉΓòÉ 154. hfree ΓòÉΓòÉΓòÉ
  9312.  
  9313. Synopsis: 
  9314.  
  9315.                     #include <malloc.h>
  9316.                     void hfree( void __huge *ptr );
  9317.  
  9318. Description: The hfree function deallocates a memory block previously allocated 
  9319.           by the halloc function.  The argument ptr points to a memory block to 
  9320.           be deallocated.  After the call, the freed block is available for 
  9321.           allocation. 
  9322.  
  9323. Returns:  The hfree function returns no value. 
  9324.  
  9325. See Also: calloc Functions, _expand Functions, free Functions, halloc, malloc 
  9326.           Functions, _msize Functions, realloc Functions, sbrk 
  9327.  
  9328. Example: 
  9329.  
  9330.                     #include <stdio.h>
  9331.                     #include <malloc.h>
  9332.  
  9333.                     void main()
  9334.                       {
  9335.                         long int __huge *big_buffer;
  9336.  
  9337.                         big_buffer = (long int __huge *)
  9338.                                       halloc( 1024L, sizeof(long) );
  9339.                         if( big_buffer == NULL ) {
  9340.                           printf( "Unable to allocate memory\n" );
  9341.                         } else {
  9342.  
  9343.                           /* rest of code goes here */
  9344.  
  9345.                           hfree( big_buffer );  /* deallocate */
  9346.                         }
  9347.                       }
  9348.  
  9349. Classification: WATCOM 
  9350.  
  9351.  
  9352. ΓòÉΓòÉΓòÉ 155. hypot ΓòÉΓòÉΓòÉ
  9353.  
  9354. Synopsis: 
  9355.  
  9356.                     #include <math.h>
  9357.                     double hypot( double x, double y );
  9358.  
  9359. Description: The hypot function computes the length of the hypotenuse of a 
  9360.           right triangle whose sides are x and y adjacent to that right angle. 
  9361.           The calculation is equivalent to 
  9362.  
  9363.                         sqrt( x*x + y*y )
  9364.  
  9365.           The computation may cause an overflow, in which case the matherr 
  9366.           function will be invoked. 
  9367.  
  9368. Returns:  The value of the hypotenuse is returned.  When an error has occurred, 
  9369.           errno contains a value indicating the type of error that has been 
  9370.           detected. 
  9371.  
  9372. Example: 
  9373.  
  9374.                     #include <stdio.h>
  9375.                     #include <math.h>
  9376.  
  9377.                     void main()
  9378.                       {
  9379.                         printf( "%f\n", hypot( 3.0, 4.0 ) );
  9380.                       }
  9381.  
  9382.           produces the following: 
  9383.  
  9384.                     5.000000
  9385.  
  9386. Classification: WATCOM 
  9387.  
  9388.  
  9389. ΓòÉΓòÉΓòÉ 156. inp ΓòÉΓòÉΓòÉ
  9390.  
  9391. Synopsis: 
  9392.  
  9393.                     #include <conio.h>
  9394.                     unsigned int inp( int port );
  9395.  
  9396. Description: The inp function reads one byte from the 80x86 hardware port whose 
  9397.           number is given by port. 
  9398.  
  9399.           A hardware port is used to communicate with a device.  One or two 
  9400.           bytes can be read and/or written from each port, depending upon the 
  9401.           hardware.  Consult the technical documentation for your computer to 
  9402.           determine the port numbers for a device and the expected usage of 
  9403.           each port for a device. 
  9404.  
  9405. Returns:  The value returned is the byte that was read. 
  9406.  
  9407. See Also: inpw, outp, outpw 
  9408.  
  9409. Example: 
  9410.  
  9411.                     #include <conio.h>
  9412.  
  9413.                     void main()
  9414.                       {
  9415.                         /* turn off speaker */
  9416.                         outp( 0x61, inp( 0x61 ) & 0xFC );
  9417.                       }
  9418.  
  9419. Classification: Intel 
  9420.  
  9421.  
  9422. ΓòÉΓòÉΓòÉ 157. inpw ΓòÉΓòÉΓòÉ
  9423.  
  9424. Synopsis: 
  9425.  
  9426.                     #include <conio.h>
  9427.                     unsigned int inpw( int port );
  9428.  
  9429. Description: The inpw function reads a word (two bytes) from the 80x86 hardware 
  9430.           port whose number is given by port. 
  9431.  
  9432.           A hardware port is used to communicate with a device.  One or two 
  9433.           bytes can be read and/or written from each port, depending upon the 
  9434.           hardware.  Consult the technical documentation for your computer to 
  9435.           determine the port numbers for a device and the expected usage of 
  9436.           each port for a device. 
  9437.  
  9438. Returns:  The value returned is the word that was read. 
  9439.  
  9440. See Also: inp, outp, outpw 
  9441.  
  9442. Example: 
  9443.  
  9444.                     #include <conio.h>
  9445.  
  9446.                     #define DEVICE 34
  9447.  
  9448.                     void main()
  9449.                       {
  9450.                         unsigned int transmitted;
  9451.  
  9452.                         transmitted = inpw( DEVICE );
  9453.                       }
  9454.  
  9455. Classification: Intel 
  9456.  
  9457.  
  9458. ΓòÉΓòÉΓòÉ 158. int386 ΓòÉΓòÉΓòÉ
  9459.  
  9460. Synopsis: 
  9461.  
  9462.                     #include <dos.h>
  9463.                     int int386( int inter_no,
  9464.                                const union REGS *in_regs,
  9465.                                union REGS *out_regs );
  9466.  
  9467. Description: The int386 function causes the computer's central processor (CPU) 
  9468.           to be interrupted with an interrupt whose number is given by 
  9469.           inter_no. This function is present in the 386 C libraries and may be 
  9470.           executed on 80386/486 systems.  Before the interrupt, the CPU 
  9471.           registers are loaded from the structure located by in_regs. Following 
  9472.           the interrupt, the structure located by out_regs is filled with the 
  9473.           contents of the CPU registers.  These structures may be located at 
  9474.           the same location in memory. 
  9475.  
  9476.           You should consult the technical documentation for the computer that 
  9477.           you are using to determine the expected register contents before and 
  9478.           after the interrupt in question. 
  9479.  
  9480. Returns:  The function returns the value of the CPU EAX register after the 
  9481.           interrupt. 
  9482.  
  9483. See Also: bdos, int386x, int86, int86x, intdos, intdosx, intr 
  9484.  
  9485. Example: 
  9486.  
  9487.                     /*
  9488.                      * This example clears the screen on DOS
  9489.                      */
  9490.                     #include <dos.h>
  9491.  
  9492.                     void main()
  9493.                       {
  9494.                         union REGS  regs;
  9495.  
  9496.                         regs.w.cx = 0;
  9497.                         regs.w.dx = 0x1850;
  9498.                         regs.h.bh = 7;
  9499.                         regs.w.ax = 0x0600;
  9500.                     #ifdef __386__
  9501.                         int386( 0x10, ®s, ®s );
  9502.                     #else
  9503.                         int86( 0x10, ®s, ®s );
  9504.                     #endif
  9505.                       }
  9506.  
  9507. Classification: Intel 
  9508.  
  9509.  
  9510. ΓòÉΓòÉΓòÉ 159. int386x ΓòÉΓòÉΓòÉ
  9511.  
  9512. Synopsis: 
  9513.  
  9514.                     #include <dos.h>
  9515.                     int int386x( int inter_no,
  9516.                                  const union REGS *in_regs,
  9517.                                  union REGS *out_regs,
  9518.                                  struct SREGS *seg_regs );
  9519.  
  9520. Description: The int386x function causes the computer's central processor (CPU) 
  9521.           to be interrupted with an interrupt whose number is given by 
  9522.           inter_no. This function is present in the 386 C libraries and may be 
  9523.           executed on 80386/486 systems.  Before the interrupt, the CPU 
  9524.           registers are loaded from the structure located by in_regs and the 
  9525.           DS, ES, FS and GS segment registers are loaded from the structure 
  9526.           located by seg_regs. All of the segment registers must contain valid 
  9527.           values.  Failure to do so will cause a segment violation when running 
  9528.           in protect mode.  If you don't care about a particular segment 
  9529.           register, then it can be set to 0 which will not cause a segment 
  9530.           violation.  The function segread can be used to initialize seg_regs 
  9531.           to their current values. 
  9532.  
  9533.           Following the interrupt, the structure located by out_regs is filled 
  9534.           with the contents of the CPU registers.  The in_regs and out_regs 
  9535.           structures may be located at the same location in memory.  The 
  9536.           original values of the DS, ES, FS and GS registers are restored.  The 
  9537.           structure seg_regs is updated with the values of the segment 
  9538.           registers following the interrupt. 
  9539.  
  9540.           You should consult the technical documentation for the computer that 
  9541.           you are using to determine the expected register contents before and 
  9542.           after the interrupt in question. 
  9543.  
  9544. Returns:  The function returns the value of the CPU EAX register after the 
  9545.           interrupt. 
  9546.  
  9547. See Also: bdos, int386, int86, int86x, intdos, intdosx, intr 
  9548.  
  9549. Classification: Intel 
  9550.  
  9551.  
  9552. ΓòÉΓòÉΓòÉ 160. int86 ΓòÉΓòÉΓòÉ
  9553.  
  9554. Synopsis: 
  9555.  
  9556.                     #include <dos.h>
  9557.                     int int86( int inter_no,
  9558.                                const union REGS *in_regs,
  9559.                                union REGS *out_regs );
  9560.  
  9561. Description: The int86 function causes the computer's central processor (CPU) 
  9562.           to be interrupted with an interrupt whose number is given by 
  9563.           inter_no. Before the interrupt, the CPU registers are loaded from the 
  9564.           structure located by in_regs. Following the interrupt, the structure 
  9565.           located by out_regs is filled with the contents of the CPU registers. 
  9566.           These structures may be located at the same location in memory. 
  9567.  
  9568.           You should consult the technical documentation for the computer that 
  9569.           you are using to determine the expected register contents before and 
  9570.           after the interrupt in question. 
  9571.  
  9572. Returns:  The function returns the value of the CPU AX register after the 
  9573.           interrupt. 
  9574.  
  9575. See Also: bdos, int386, int386x, int86x, intdos, intdosx, intr 
  9576.  
  9577. Example: 
  9578.  
  9579.                     /*
  9580.                      * This example clears the screen on DOS
  9581.                      */
  9582.                     #include <dos.h>
  9583.  
  9584.                     void main()
  9585.                       {
  9586.                         union REGS  regs;
  9587.  
  9588.                         regs.w.cx = 0;
  9589.                         regs.w.dx = 0x1850;
  9590.                         regs.h.bh = 7;
  9591.                         regs.w.ax = 0x0600;
  9592.                     #ifdef __386__
  9593.                         int386( 0x10, ®s, ®s );
  9594.                     #else
  9595.                         int86( 0x10, ®s, ®s );
  9596.                     #endif
  9597.                       }
  9598.  
  9599. Classification: Intel 
  9600.  
  9601.  
  9602. ΓòÉΓòÉΓòÉ 161. int86x ΓòÉΓòÉΓòÉ
  9603.  
  9604. Synopsis: 
  9605.  
  9606.                     #include <dos.h>
  9607.                     int int86x( int inter_no,
  9608.                                 const union REGS *in_regs,
  9609.                                 union REGS *out_regs,
  9610.                                 struct SREGS *seg_regs );
  9611.  
  9612. Description: The int86x function causes the computer's central processor (CPU) 
  9613.           to be interrupted with an interrupt whose number is given by 
  9614.           inter_no. Before the interrupt, the CPU registers are loaded from the 
  9615.           structure located by in_regs and the DS and ES segment registers are 
  9616.           loaded from the structure located by seg_regs. All of the segment 
  9617.           registers must contain valid values.  Failure to do so will cause a 
  9618.           segment violation when running in protect mode.  If you don't care 
  9619.           about a particular segment register, then it can be set to 0 which 
  9620.           will not cause a segment violation.  The function segread can be used 
  9621.           to initialize seg_regs to their current values. 
  9622.  
  9623.           Following the interrupt, the structure located by out_regs is filled 
  9624.           with the contents of the CPU registers.  The in_regs and out_regs 
  9625.           structures may be located at the same location in memory.  The 
  9626.           original values of the DS and ES registers are restored.  The 
  9627.           structure seg_regs is updated with the values of the segment 
  9628.           registers following the interrupt. 
  9629.  
  9630.           You should consult the technical documentation for the computer that 
  9631.           you are using to determine the expected register contents before and 
  9632.           after the interrupt in question. 
  9633.  
  9634. Returns:  The function returns the value of the CPU AX register after the 
  9635.           interrupt. 
  9636.  
  9637. See Also: bdos, int386, int386x, int86, intdos, intdosx, intr 
  9638.  
  9639. Classification: Intel 
  9640.  
  9641.  
  9642. ΓòÉΓòÉΓòÉ 162. intdos ΓòÉΓòÉΓòÉ
  9643.  
  9644. Synopsis: 
  9645.  
  9646.                     #include <dos.h>
  9647.                     int intdos( const union REGS *in_regs,
  9648.                                 union REGS *out_regs );
  9649.  
  9650. Description: The intdos function causes the computer's central processor (CPU) 
  9651.           to be interrupted with an interrupt number hexadecimal 21 ( 0x21 ), 
  9652.           which is a request to invoke a specific DOS function.  Before the 
  9653.           interrupt, the CPU registers are loaded from the structure located by 
  9654.           in_regs. The AH register contains a number indicating the function 
  9655.           requested. Following the interrupt, the structure located by out_regs 
  9656.           is filled with the contents of the CPU registers.  These structures 
  9657.           may be located at the same location in memory. 
  9658.  
  9659.           You should consult the technical documentation for the DOS operating 
  9660.           system that you are using to determine the expected register contents 
  9661.           before and after the interrupt in question. 
  9662.  
  9663. Returns:  The function returns the value of the AX (EAX in 386 library) 
  9664.           register after the interrupt has completed.  The CARRY flag (when 
  9665.           set, an error has occurred) is copied into the structure located by 
  9666.           out_regs. When an error has occurred, errno contains a value 
  9667.           indicating the type of error that has been detected. 
  9668.  
  9669. See Also: bdos, int386, int386x, int86, int86x, intdosx, intr 
  9670.  
  9671. Example: 
  9672.  
  9673.                     #include <dos.h>
  9674.  
  9675.                     #define DISPLAY_OUTPUT  2
  9676.  
  9677.                     void main()
  9678.                       {
  9679.                         union REGS  in_regs, out_regs;
  9680.                         int         rc;
  9681.  
  9682.                         in_regs.h.ah = DISPLAY_OUTPUT;
  9683.                         in_regs.h.al = 0;
  9684.  
  9685.                         in_regs.w.dx = 'I';
  9686.                         rc = intdos( &in_regs, &out_regs );
  9687.                         in_regs.w.dx = 'N';
  9688.                         rc = intdos( &in_regs, &out_regs );
  9689.                         in_regs.w.dx = 'T';
  9690.                         rc = intdos( &in_regs, &out_regs );
  9691.                         in_regs.w.dx = 'D';
  9692.                         rc = intdos( &in_regs, &out_regs );
  9693.                         in_regs.w.dx = 'O';
  9694.                         rc = intdos( &in_regs, &out_regs );
  9695.                         in_regs.w.dx = 'S';
  9696.                         rc = intdos( &in_regs, &out_regs );
  9697.                       }
  9698.  
  9699. Classification: DOS 
  9700.  
  9701.  
  9702. ΓòÉΓòÉΓòÉ 163. intdosx ΓòÉΓòÉΓòÉ
  9703.  
  9704. Synopsis: 
  9705.  
  9706.                     #include <dos.h>
  9707.                     int intdosx( const union REGS *in_regs,
  9708.                                  union REGS *out_regs,
  9709.                                  struct SREGS *seg_regs );
  9710.  
  9711. Description: The intdosx function causes the computer's central processor (CPU) 
  9712.           to be interrupted with an interrupt number hexadecimal 21 ( 0x21 ), 
  9713.           which is a request to invoke a specific DOS function.  Before the 
  9714.           interrupt, the CPU registers are loaded from the structure located by 
  9715.           in_regs and the segment registers DS and ES are loaded from the 
  9716.           structure located by seg_regs. The AH register contains a number 
  9717.           indicating the function requested.  All of the segment registers must 
  9718.           contain valid values.  Failure to do so will cause a segment 
  9719.           violation when running in protect mode.  If you don't care about a 
  9720.           particular segment register, then it can be set to 0 which will not 
  9721.           cause a segment violation.  The function segread can be used to 
  9722.           initialize seg_regs to their current values. 
  9723.  
  9724.           Following the interrupt, the structure located by out_regs is filled 
  9725.           with the contents of the CPU registers.  The in_regs and out_regs 
  9726.           structures may be located at the same location in memory.  The 
  9727.           original values for the DS and ES registers are restored.  The 
  9728.           structure seg_regs is updated with the values of the segment 
  9729.           registers following the interrupt. 
  9730.  
  9731.           You should consult the technical documentation for the DOS operating 
  9732.           system that you are using to determine the expected register contents 
  9733.           before and after the interrupt in question. 
  9734.  
  9735. Returns:  The function returns the value of the AX (EAX in 386 library) 
  9736.           register after the interrupt has completed.  The CARRY flag (when 
  9737.           set, an error has occurred) is copied into the structure located by 
  9738.           out_regs. When an error has occurred, errno contains a value 
  9739.           indicating the type of error that has been detected. 
  9740.  
  9741. See Also: bdos, int386, int386x, int86, int86x, intdos, intr 
  9742.  
  9743. Classification: DOS 
  9744.  
  9745.  
  9746. ΓòÉΓòÉΓòÉ 164. intr ΓòÉΓòÉΓòÉ
  9747.  
  9748. Synopsis: 
  9749.  
  9750.                     #include <dos.h>
  9751.                     void intr( int inter_no, union REGPACK *regs );
  9752.  
  9753. Description: The intr function causes the computer's central processor (CPU) to 
  9754.           be interrupted with an interrupt whose number is given by inter_no. 
  9755.           Before the interrupt, the CPU registers are loaded from the structure 
  9756.           located by regs. All of the segment registers must contain valid 
  9757.           values.  Failure to do so will cause a segment violation when running 
  9758.           in protect mode.  If you don't care about a particular segment 
  9759.           register, then it can be set to 0 which will not cause a segment 
  9760.           violation.  Following the interrupt, the structure located by regs is 
  9761.           filled with the contents of the CPU registers. 
  9762.  
  9763.           This function is similar to the int86x function, except that only one 
  9764.           structure is used for the register values and that the BP (EBP in 386 
  9765.           library) register is included in the set of registers that are passed 
  9766.           and saved. 
  9767.  
  9768.           You should consult the technical documentation for the computer that 
  9769.           you are using to determine the expected register contents before and 
  9770.           after the interrupt in question. 
  9771.  
  9772. Returns:  The function does not return a value. 
  9773.  
  9774. See Also: bdos, int386, int386x, int86, int86x, intdos, intdosx 
  9775.  
  9776. Example: 
  9777.  
  9778.                     #include <stdio.h>
  9779.                     #include <string.h>
  9780.                     #include <dos.h>
  9781.  
  9782.                     void main() /* Print location of Break Key Vector */
  9783.                       {
  9784.                         union REGPACK regs;
  9785.                         memset( ®s, 0, sizeof(union REGPACK) );
  9786.                         regs.w.ax = 0x3523;
  9787.                         intr( 0x21, ®s );
  9788.                         printf( "Break Key vector is %x:%x\n",
  9789.                                 regs.x.es, regs.x.bx );
  9790.                       }
  9791.  
  9792.           produces the following: 
  9793.  
  9794.                     Break Key vector is eef:13c
  9795.  
  9796. Classification: Intel 
  9797.  
  9798.  
  9799. ΓòÉΓòÉΓòÉ 165. isalnum ΓòÉΓòÉΓòÉ
  9800.  
  9801. Synopsis: 
  9802.  
  9803.                     #include <ctype.h>
  9804.                     int isalnum( int c );
  9805.  
  9806. Description: The isalnum tests if the argument c is an alphanumeric character 
  9807.           (a to z, A to Z, or 0 to 9).  An alphanumeric character is any 
  9808.           character for which isalpha or isdigit is true. 
  9809.  
  9810. Returns:  The isalnum returns zero if the argument is neither an alphabetic 
  9811.           character nor a digit.  Otherwise, a non-zero value is returned. 
  9812.  
  9813. See Also: isalpha, isdigit, islower 
  9814.  
  9815. Example: 
  9816.  
  9817.                     #include <stdio.h>
  9818.                     #include <ctype.h>
  9819.  
  9820.                     void main()
  9821.                       {
  9822.                         if( isalnum( getchar() ) ) {
  9823.                           printf( "is alpha-numeric\n" );
  9824.                         }
  9825.                       }
  9826.  
  9827. Classification: ANSI 
  9828.  
  9829.  
  9830. ΓòÉΓòÉΓòÉ 166. isalpha ΓòÉΓòÉΓòÉ
  9831.  
  9832. Synopsis: 
  9833.  
  9834.                     #include <ctype.h>
  9835.                     int isalpha( int c );
  9836.  
  9837. Description: The isalpha tests for an alphabetic character (a to z and A to Z). 
  9838.           An alphabetic character is any character for which isupper or islower 
  9839.           is true. 
  9840.  
  9841. Returns:  The isalpha returns zero if the argument is not an alphabetic 
  9842.           character; otherwise, a non-zero value is returned. 
  9843.  
  9844. See Also: isalnum, iscntrl, isdigit, isgraph, islower, isprint, ispunct, 
  9845.           isspace, isupper, isxdigit, tolower, toupper 
  9846.  
  9847. Example: 
  9848.  
  9849.                     #include <stdio.h>
  9850.                     #include <ctype.h>
  9851.  
  9852.                     void main()
  9853.                       {
  9854.                         if( isalpha( getchar() ) ) {
  9855.                           printf( "is alphabetic\n" );
  9856.                         }
  9857.                       }
  9858.  
  9859. Classification: ANSI 
  9860.  
  9861.  
  9862. ΓòÉΓòÉΓòÉ 167. isascii ΓòÉΓòÉΓòÉ
  9863.  
  9864. Synopsis: 
  9865.  
  9866.                     #include <ctype.h>
  9867.                     int isascii( int c );
  9868.  
  9869. Description: The isascii function tests for a character in the range from 0 to 
  9870.           127. 
  9871.  
  9872. Returns:  A non-zero value is returned when the character is in the range 0 to 
  9873.           127; otherwise, zero is returned. 
  9874.  
  9875. See Also: isalpha, isalnum, iscntrl, isdigit, isgraph, islower, isprint, 
  9876.           ispunct, isspace, isupper, isxdigit, tolower, toupper 
  9877.  
  9878. Classification: WATCOM 
  9879.  
  9880.  
  9881. ΓòÉΓòÉΓòÉ 168. isatty ΓòÉΓòÉΓòÉ
  9882.  
  9883. Synopsis: 
  9884.  
  9885.                     #include <io.h>
  9886.                     int isatty( int handle );
  9887.  
  9888. Description: The isatty function tests if the opened file or device referenced 
  9889.           by the file handle handle is a character device (for example, a 
  9890.           console, printer or port). 
  9891.  
  9892. Returns:  The isatty function returns zero if the device or file is not a 
  9893.           character device; otherwise, a non-zero value is returned.  When an 
  9894.           error has occurred, errno contains a value indicating the type of 
  9895.           error that has been detected. 
  9896.  
  9897. See Also: open 
  9898.  
  9899. Classification: POSIX 1003.1 
  9900.  
  9901.  
  9902. ΓòÉΓòÉΓòÉ 169. iscntrl ΓòÉΓòÉΓòÉ
  9903.  
  9904. Synopsis: 
  9905.  
  9906.                     #include <ctype.h>
  9907.                     int iscntrl( int c );
  9908.  
  9909. Description: The iscntrl function tests for any control character.  A control 
  9910.           character is any character whose value is from 0 through 31. 
  9911.  
  9912. Returns:  The iscntrl returns a non-zero value when the argument is a control 
  9913.           character; otherwise, zero is returned. 
  9914.  
  9915. See Also: isalnum, isalpha, isdigit, isgraph, islower, isprint, ispunct, 
  9916.           isspace, isupper, isxdigit, tolower, toupper 
  9917.  
  9918. Classification: ANSI 
  9919.  
  9920.  
  9921. ΓòÉΓòÉΓòÉ 170. isdigit ΓòÉΓòÉΓòÉ
  9922.  
  9923. Synopsis: 
  9924.  
  9925.                     #include <ctype.h>
  9926.                     int isdigit( int c );
  9927.  
  9928. Description: The isdigit function tests for any decimal-digit character '0' 
  9929.           through '9'. 
  9930.  
  9931. Returns:  The isdigit function returns a non-zero value when the argument is a 
  9932.           digit; otherwise, zero is returned. 
  9933.  
  9934. See Also: isalnum, isalpha, iscntrl, isgraph, islower, isprint, ispunct, 
  9935.           isspace, isupper, isxdigit, tolower, toupper 
  9936.  
  9937. Classification: ANSI 
  9938.  
  9939.  
  9940. ΓòÉΓòÉΓòÉ 171. isgraph ΓòÉΓòÉΓòÉ
  9941.  
  9942. Synopsis: 
  9943.  
  9944.                     #include <ctype.h>
  9945.                     int isgraph( int c );
  9946.  
  9947. Description: The isgraph function tests for any printable character except 
  9948.           space (' ').  The isprint function is similar, except that the space 
  9949.           character is also included in the character set being tested. 
  9950.  
  9951. Returns:  The isgraph function returns non-zero when the argument is a 
  9952.           printable character (except a space); otherwise, zero is returned. 
  9953.  
  9954. See Also: isalnum, isalpha, iscntrl, isdigit, islower, isprint, ispunct, 
  9955.           isspace, isupper, isxdigit, tolower, toupper 
  9956.  
  9957. Classification: ANSI 
  9958.  
  9959.  
  9960. ΓòÉΓòÉΓòÉ 172. islower ΓòÉΓòÉΓòÉ
  9961.  
  9962. Synopsis: 
  9963.  
  9964.                     #include <ctype.h>
  9965.                     int islower( int c );
  9966.  
  9967. Description: The islower function tests for any lower-case letter 'a' through 
  9968.           'z'. 
  9969.  
  9970. Returns:  The islower function returns a non-zero value when argument is a 
  9971.           lower-case letter; otherwise, zero is returned. 
  9972.  
  9973. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, isprint, ispunct, 
  9974.           isspace, isupper, isxdigit, tolower, toupper 
  9975.  
  9976. Classification: ANSI 
  9977.  
  9978.  
  9979. ΓòÉΓòÉΓòÉ 173. isprint ΓòÉΓòÉΓòÉ
  9980.  
  9981. Synopsis: 
  9982.  
  9983.                     #include <ctype.h>
  9984.                     int isprint( int c );
  9985.  
  9986. Description: The isprint function tests for any printable character including 
  9987.           space (' ').  The isgraph function is similar, except that the space 
  9988.           character is excluded from the character set being tested. 
  9989.  
  9990. Returns:  The isprint function returns a non-zero value when the argument is a 
  9991.           printable character; otherwise, zero is returned. 
  9992.  
  9993. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, ispunct, 
  9994.           isspace, isupper, isxdigit, tolower, toupper 
  9995.  
  9996. Classification: ANSI 
  9997.  
  9998.  
  9999. ΓòÉΓòÉΓòÉ 174. ispunct ΓòÉΓòÉΓòÉ
  10000.  
  10001. Synopsis: 
  10002.  
  10003.                     #include <ctype.h>
  10004.                     int ispunct( int c );
  10005.  
  10006. Description: The ispunct function tests for any punctuation character such as a 
  10007.           comma (,) or a period (.). 
  10008.  
  10009. Returns:  The ispunct function returns a non-zero value when the argument is a 
  10010.           punctuation character; otherwise, zero is returned. 
  10011.  
  10012. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, 
  10013.           isspace, isupper, isxdigit, tolower, toupper 
  10014.  
  10015. Classification: ANSI 
  10016.  
  10017.  
  10018. ΓòÉΓòÉΓòÉ 175. isspace ΓòÉΓòÉΓòÉ
  10019.  
  10020. Synopsis: 
  10021.  
  10022.                     #include <ctype.h>
  10023.                     int isspace( int c );
  10024.  
  10025. Description: The isspace function tests for the following white-space 
  10026.           characters: 
  10027.  
  10028.    Constant    Character 
  10029.    ' '         space 
  10030.    '\f'        form feed 
  10031.    '\n'        new-line or linefeed 
  10032.    '\r'        carriage return 
  10033.    '\t'        horizontal tab 
  10034.    '\v'        vertical tab 
  10035.  
  10036. Returns:  The isspace function returns a non-zero character when the argument 
  10037.           is one of the indicated white-space characters; otherwise, zero is 
  10038.           returned. 
  10039.  
  10040. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, 
  10041.           ispunct, isupper, isxdigit, tolower, toupper 
  10042.  
  10043. Classification: ANSI 
  10044.  
  10045.  
  10046. ΓòÉΓòÉΓòÉ 176. isupper ΓòÉΓòÉΓòÉ
  10047.  
  10048. Synopsis: 
  10049.  
  10050.                     #include <ctype.h>
  10051.                     int isupper( int c );
  10052.  
  10053. Description: The isupper function tests for any upper-case letter 'A' through 
  10054.           'Z'. 
  10055.  
  10056. Returns:  The isupper returns a non-zero value when the argument is an 
  10057.           upper-case letter; otherwise, zero is returned. 
  10058.  
  10059. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, 
  10060.           ispunct, isspace, isxdigit, tolower, toupper 
  10061.  
  10062. Classification: ANSI 
  10063.  
  10064.  
  10065. ΓòÉΓòÉΓòÉ 177. isxdigit ΓòÉΓòÉΓòÉ
  10066.  
  10067. Synopsis: 
  10068.  
  10069.                     #include <ctype.h>
  10070.                     int isxdigit( int c );
  10071.  
  10072. Description: The isxdigit function tests for any hexadecimal-digit character. 
  10073.           These characters are the digits ('0' through '9') and the letters 
  10074.           ('a' through 'f') and ('A' through 'F'). 
  10075.  
  10076. Returns:  The isxdigit function returns a non-zero value when the argument is a 
  10077.           hexadecimal digit; otherwise, zero is returned. 
  10078.  
  10079. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, 
  10080.           ispunct, isspace, isupper, tolower, toupper 
  10081.  
  10082. Classification: ANSI 
  10083.  
  10084.  
  10085. ΓòÉΓòÉΓòÉ 178. itoa ΓòÉΓòÉΓòÉ
  10086.  
  10087. Synopsis: 
  10088.  
  10089.                     #include <stdlib.h>
  10090.                     char *itoa( int value, char *buffer, int radix );
  10091.  
  10092. Description: The itoa function converts the binary integer value into the 
  10093.           equivalent string in base radix notation storing the result in the 
  10094.           character array pointed to by buffer. A null character is appended to 
  10095.           the result.  The size of buffer must be at least (8 * sizeof(int) + 
  10096.           1) bytes when converting values in base 2.  That makes the size 17 
  10097.           bytes on 16-bit machines, and 33 bytes on 32-bit machines.  If the 
  10098.           value of radix is 10 and value is negative, then a minus sign is 
  10099.           prepended to the result. 
  10100.  
  10101. Returns:  The itoa function returns the pointer to the result. 
  10102.  
  10103. See Also: atoi, strtol, utoa 
  10104.  
  10105. Example: 
  10106.  
  10107.                     #include <stdio.h>
  10108.                     #include <stdlib.h>
  10109.  
  10110.                     void main()
  10111.                       {
  10112.                         char buffer[20];
  10113.                         int base;
  10114.  
  10115.                         for ( base=8; base<=16; base=base+2 )
  10116.                           printf( "%2d %s\n", base,
  10117.                                   itoa( 12765, buffer, base ) );
  10118.                       }
  10119.  
  10120.           produces the following: 
  10121.  
  10122.                      8 30735
  10123.                     10 12765
  10124.                     12 7479
  10125.                     14 491b
  10126.                     16 31dd
  10127.  
  10128. Classification: WATCOM 
  10129.  
  10130.  
  10131. ΓòÉΓòÉΓòÉ 179. kbhit ΓòÉΓòÉΓòÉ
  10132.  
  10133. Synopsis: 
  10134.  
  10135.                     #include <conio.h>
  10136.                     int kbhit( void );
  10137.  
  10138. Description: The kbhit function tests whether or not a keystroke is currently 
  10139.           available.  When one is available, the function getch or getche may 
  10140.           be used to obtain the keystroke in question. 
  10141.  
  10142.           With a stand-alone program, the kbhit function may be called 
  10143.           continuously until a keystroke is available. 
  10144.  
  10145. Returns:  The kbhit function returns zero when no keystroke is available; 
  10146.           otherwise, a non-zero value is returned. 
  10147.  
  10148. See Also: getch, getche, putch, ungetch 
  10149.  
  10150. Example: 
  10151.  
  10152.                     /*
  10153.                      * This program loops until a key is pressed
  10154.                      * or a count is exceeded.
  10155.                      */
  10156.                     #include <stdio.h>
  10157.                     #include <conio.h>
  10158.  
  10159.                     void main()
  10160.                       {
  10161.                         unsigned long i;
  10162.  
  10163.                         printf( "Program looping. Press any key.\n" );
  10164.                         for( i = 0; i < 10000; i++ ) {
  10165.                           if( kbhit() ) {
  10166.                             getch();
  10167.                             break;
  10168.                           }
  10169.                         }
  10170.                       }
  10171.  
  10172. Classification: WATCOM 
  10173.  
  10174.  
  10175. ΓòÉΓòÉΓòÉ 180. labs ΓòÉΓòÉΓòÉ
  10176.  
  10177. Synopsis: 
  10178.  
  10179.                     #include <stdlib.h>
  10180.                     long int labs( long int j );
  10181.  
  10182. Description: The labs function returns the absolute value of its long-integer 
  10183.           argument j. 
  10184.  
  10185. Returns:  The labs function returns the absolute value of its argument. 
  10186.  
  10187. See Also: abs, fabs 
  10188.  
  10189. Example: 
  10190.  
  10191.                     #include <stdio.h>
  10192.                     #include <stdlib.h>
  10193.  
  10194.                     void main()
  10195.                       {
  10196.                         long x, y;
  10197.  
  10198.                         x = -50000L;
  10199.                         y = labs( x );
  10200.                         printf( "labs(%ld) = %ld\n", x, y );
  10201.                       }
  10202.  
  10203.           produces the following: 
  10204.  
  10205.                     labs(-50000) = 50000
  10206.  
  10207. Classification: ANSI 
  10208.  
  10209.  
  10210. ΓòÉΓòÉΓòÉ 181. ldexp ΓòÉΓòÉΓòÉ
  10211.  
  10212. Synopsis: 
  10213.  
  10214.                     #include <math.h>
  10215.                     double ldexp( double x, int exp );
  10216.  
  10217. Description: The ldexp function multiplies a floating-point number by an 
  10218.           integral power of 2.  A range error may occur. 
  10219.  
  10220. Returns:  The ldexp function returns the value of x times 2 raised to the power 
  10221.           exp. 
  10222.  
  10223. See Also: frexp, modf 
  10224.  
  10225. Example: 
  10226.  
  10227.                     #include <stdio.h>
  10228.                     #include <math.h>
  10229.  
  10230.                     void main()
  10231.                       {
  10232.                         double value;
  10233.  
  10234.                         value = ldexp( 4.7072345, 5 );
  10235.                         printf( "%f\n", value );
  10236.                       }
  10237.  
  10238.           produces the following: 
  10239.  
  10240.                     150.631504
  10241.  
  10242. Classification: ANSI 
  10243.  
  10244.  
  10245. ΓòÉΓòÉΓòÉ 182. ldiv ΓòÉΓòÉΓòÉ
  10246.  
  10247. Synopsis: 
  10248.  
  10249.                     #include <stdlib.h>
  10250.                     ldiv_t ldiv( long int numer, long int denom );
  10251.  
  10252.                     typedef struct {
  10253.                         long int quot;     /* quotient */
  10254.                         long int rem;      /* remainder */
  10255.                     } ldiv_t;
  10256.  
  10257. Description: The ldiv function calculates the quotient and remainder of the 
  10258.           division of the numerator numer by the denominator denom. 
  10259.  
  10260. Returns:  The ldiv function returns a structure of type ldiv_t that contains 
  10261.           the fields quot and rem, which are both of type long int. 
  10262.  
  10263. See Also: div 
  10264.  
  10265. Example: 
  10266.  
  10267.                     #include <stdio.h>
  10268.                     #include <stdlib.h>
  10269.  
  10270.                     void main()
  10271.                       {
  10272.                         print_time( 86712L );
  10273.                       }
  10274.  
  10275.                     void print_time( long int ticks )
  10276.                       {
  10277.                         ldiv_t sec_ticks;
  10278.                         ldiv_t min_sec;
  10279.  
  10280.                         sec_ticks = ldiv( ticks, 100L );
  10281.                         min_sec   = ldiv( sec_ticks.quot, 60L );
  10282.                         printf( "It took %ld minutes and %ld seconds\n",
  10283.                                  min_sec.quot, min_sec.rem );
  10284.                       }
  10285.  
  10286.           produces the following: 
  10287.  
  10288.                     It took 14 minutes and 27 seconds
  10289.  
  10290. Classification: ANSI 
  10291.  
  10292.  
  10293. ΓòÉΓòÉΓòÉ 183. lfind ΓòÉΓòÉΓòÉ
  10294.  
  10295. Synopsis: 
  10296.  
  10297.                     #include <search.h>
  10298.                     void *lfind( const void *key, /* object to search for  */
  10299.                                  const void *base,/* base of search data   */
  10300.                                  unsigned *num,   /* number of elements    */
  10301.                                  unsigned width,  /* width of each element */
  10302.                                  int (*compare)( const void *element1,
  10303.                                                  const void *element2 ) );
  10304.  
  10305. Description: The lfind function performs a linear search for the value key in 
  10306.           the array of num elements pointed to by base. Each element of the 
  10307.           array is width bytes in size.  The argument compare is a pointer to a 
  10308.           user-supplied routine that will be called by lfind to determine the 
  10309.           relationship of an array element with the key. One of the arguments 
  10310.           to the compare function will be an array element, and the other will 
  10311.           be key. 
  10312.  
  10313.           The compare function should return 0 if element1 is identical to 
  10314.           element2 and non-zero if the elements are not identical. 
  10315.  
  10316. Returns:  The lfind function returns a pointer to the array element in base 
  10317.           that matches key if it is found, otherwise NULL is returned 
  10318.           indicating that the key was not found. 
  10319.  
  10320. See Also: bsearch, lsearch 
  10321.  
  10322. Example: 
  10323.  
  10324.                     #include <stdio.h>
  10325.                     #include <stdlib.h>
  10326.                     #include <string.h>
  10327.                     #include <search.h>
  10328.                     static char *keywords[] = {
  10329.                             "auto",
  10330.                             "break",
  10331.                             "case",
  10332.                             "char",
  10333.                             "while"
  10334.                     };
  10335.                     void main( int argc, char *argv[] )
  10336.                       {
  10337.                         unsigned num = 5;
  10338.                         int compare( char **, char ** );
  10339.                         if( argc <= 1 ) exit( EXIT_FAILURE );
  10340.                         if( lfind( &argv[1], keywords, &num, sizeof(char **),
  10341.                                         compare ) == NULL ) {
  10342.                           printf( "'%s' is not a C keyword\n", argv[1] );
  10343.                           exit( EXIT_FAILURE );
  10344.                         } else {
  10345.                           printf( "'%s' is a C keyword\n", argv[1] );
  10346.                           exit( EXIT_SUCCESS );
  10347.                         }
  10348.                       }
  10349.                     int compare( char **op1, char **op2 )
  10350.                       {
  10351.                         return( strcmp( *op1, *op2 ) );
  10352.                       }
  10353.  
  10354. Classification: WATCOM 
  10355.  
  10356.  
  10357. ΓòÉΓòÉΓòÉ 184. localeconv ΓòÉΓòÉΓòÉ
  10358.  
  10359. Synopsis: 
  10360.  
  10361.                     #include <locale.h>
  10362.                     struct lconv *localeconv( void );
  10363.  
  10364. Description: The localeconv function sets the components of an object of type 
  10365.           struct lconv with values appropriate for the formatting of numeric 
  10366.           quantities according to the current locale.  The components of the 
  10367.           struct lconv and their meanings are as follows: 
  10368.  
  10369.    Component                Meaning 
  10370.  
  10371.    char *decimal_point      The decimal-point character used to format 
  10372.                             non-monetary quantities. 
  10373.  
  10374.    char *thousands_sep      The character used to separate groups of digits to 
  10375.                             the left of the decimal-point character in 
  10376.                             formatted non-monetary quantities. 
  10377.  
  10378.    char *grouping           A string whose elements indicate the size of each 
  10379.                             group of digits in formatted non-monetary 
  10380.                             quantities. 
  10381.  
  10382.    char *int_curr_symbol    The international currency symbol applicable to the 
  10383.                             current locale. The first three characters contain 
  10384.                             the alphabetic international currency symbol in 
  10385.                             accordance with those specified in ISO 4217 Codes 
  10386.                             for the Representation of Currency and Funds.  The 
  10387.                             fourth character (immediately preceding the null 
  10388.                             character) is the character used to separate the 
  10389.                             international currency symbol from the monetary 
  10390.                             quantity. 
  10391.  
  10392.    char *currency_symbol    The local currency symbol applicable to the current 
  10393.                             locale. 
  10394.  
  10395.    char *mon_decimal_point  The decimal-point character used to format monetary 
  10396.                             quantities. 
  10397.  
  10398.    char *mon_thousands_sep  The character used to separate groups of digits to 
  10399.                             the left of the decimal-point character in 
  10400.                             formatted monetary quantities. 
  10401.  
  10402.    char *mon_grouping       A string whose elements indicate the size of each 
  10403.                             group of digits in formatted monetary quantities. 
  10404.  
  10405.    char *positive_sign      The string used to indicate a nonnegative-valued 
  10406.                             monetary quantity. 
  10407.  
  10408.    char *negative_sign      The string used to indicate a negative-valued 
  10409.                             monetary quantity. 
  10410.  
  10411.    char int_frac_digits     The number of fractional digits (those to the right 
  10412.                             of the decimal-point) to be displayed in an 
  10413.                             internationally formatted monetary quantity. 
  10414.  
  10415.    char frac_digits         The number of fractional digits (those to the right 
  10416.                             of the decimal-point) to be displayed in a 
  10417.                             formatted monetary quantity. 
  10418.  
  10419.    char p_cs_precedes       Set to 1 or 0 if the currency_symbol respectively 
  10420.                             precedes or follows the value for a nonnegative 
  10421.                             formatted monetary quantity. 
  10422.  
  10423.    char p_sep_by_space      Set to 1 or 0 if the currency_symbol respectively 
  10424.                             is or is not separated by a space from the value 
  10425.                             for a nonnegative formatted monetary quantity. 
  10426.  
  10427.    char n_cs_precedes       Set to 1 or 0 if the currency_symbol respectively 
  10428.                             precedes or follows the value for a negative 
  10429.                             formatted monetary quantity. 
  10430.  
  10431.    char n_sep_by_space      Set to 1 or 0 if the currency_symbol respectively 
  10432.                             is or is not separated by a space from the value 
  10433.                             for a negative formatted monetary quantity. 
  10434.  
  10435.    char p_sign_posn         The position of the positive_sign for a nonnegative 
  10436.                             formatted monetary quantity. 
  10437.  
  10438.    char n_sign_posn         The position of the positive_sign for a negative 
  10439.                             formatted monetary quantity. 
  10440.  
  10441.           The elements of grouping and mon_grouping are interpreted according 
  10442.           to the following: 
  10443.  
  10444.    Value         Meaning 
  10445.    CHAR_MAX      No further grouping is to be performed. 
  10446.    0             The previous element is to be repeatedly used for the 
  10447.                  remainder of the digits. 
  10448.    other         The value is the number of digits that comprise the current 
  10449.                  group. The next element is examined to determine the size of 
  10450.                  the next group of digits to the left of the current group. 
  10451.  
  10452.           The value of p_sign_posn and n_sign_posn is interpreted as follows: 
  10453.  
  10454.    Value     Meaning 
  10455.    0         Parentheses surround the quantity and currency_symbol. 
  10456.    1         The sign string precedes the quantity and currency_symbol. 
  10457.    2         The sign string follows the quantity and currency_symbol. 
  10458.    3         The sign string immediately precedes the quantity and 
  10459.              currency_symbol. 
  10460.    4         The sign string immediately follows the quantity and 
  10461.              currency_symbol. 
  10462.  
  10463. Returns:  The localeconv function returns a pointer to the filled-in object. 
  10464.  
  10465. See Also: setlocale 
  10466.  
  10467. Classification: ANSI 
  10468.  
  10469.  
  10470. ΓòÉΓòÉΓòÉ 185. localtime, _localtime ΓòÉΓòÉΓòÉ
  10471.  
  10472. Synopsis: 
  10473.  
  10474.                     #include <time.h>
  10475.                     struct tm * localtime( const time_t *timer );
  10476.                     struct tm *_localtime( const time_t *timer,
  10477.                                            struct tm *tmbuf );
  10478.  
  10479.                     struct tm {
  10480.                       int tm_sec;   /* seconds after the minute -- [0,61] */
  10481.                       int tm_min;   /* minutes after the hour -- [0,59] */
  10482.                       int tm_hour;  /* hours after midnight -- [0,23] */
  10483.                       int tm_mday;  /* day of the month -- [1,31] */
  10484.                       int tm_mon;   /* months since January -- [0,11] */
  10485.                       int tm_year;  /* years since 1900 */
  10486.                       int tm_wday;  /* days since Sunday -- [0,6] */
  10487.                       int tm_yday;  /* days since January 1 -- [0,365]*/
  10488.                       int tm_isdst; /* Daylight Savings Time flag */
  10489.                     };
  10490.  
  10491. Description: The localtime functions convert the calendar time pointed to by 
  10492.           timer into a structure of type tm, of time information, expressed as 
  10493.           local time.  Whenever localtime is called, the tzset function is also 
  10494.           called. 
  10495.  
  10496.           The calendar time is usually obtained by using the time function. 
  10497.           That time is Coordinated Universal Time (UTC) (formerly known as 
  10498.           Greenwich Mean Time (GMT)). 
  10499.  
  10500.           The function _localtime places the converted time in the tm structure 
  10501.           pointed to by tmbuf, and the function localtime places the converted 
  10502.           time in a static structure that is re-used each time localtime is 
  10503.           called. 
  10504.  
  10505.           The time set on the computer with the DOS time command and the DOS 
  10506.           date command reflects the local time.  The environment variable TZ is 
  10507.           used to establish the time zone to which this local time applies. 
  10508.           See the section The TZ Environment Variable  for a discussion of how 
  10509.           to set the time zone. 
  10510.  
  10511. Returns:  The localtime functions return a pointer to a tm structure containing 
  10512.           the time information. 
  10513.  
  10514. See Also: asctime, clock, ctime, difftime, gmtime, mktime, strftime, time, 
  10515.           tzset 
  10516.  
  10517. Example: 
  10518.  
  10519.                     #include <stdio.h>
  10520.                     #include <time.h>
  10521.                     void main()
  10522.                       {
  10523.                         time_t time_of_day;
  10524.                         auto char buf[26];
  10525.                         auto struct tm tmbuf;
  10526.                         time_of_day = time( NULL );
  10527.                         _localtime( &time_of_day, &tmbuf );
  10528.                         printf( "It is now: %s", _asctime( &tmbuf, buf ) );
  10529.                       }
  10530.  
  10531.           produces the following: 
  10532.  
  10533.                     It is now: Sat Mar 21 15:58:27 1987
  10534.  
  10535. Classification: localtime is ANSI, _localtime is not ANSI 
  10536.  
  10537.  
  10538. ΓòÉΓòÉΓòÉ 186. lock ΓòÉΓòÉΓòÉ
  10539.  
  10540. Synopsis: 
  10541.  
  10542.                     #include <io.h>
  10543.                     int lock( int handle,
  10544.                               unsigned long offset,
  10545.                               unsigned long nbytes );
  10546.  
  10547. Description: The lock function locks nbytes amount of data in the file 
  10548.           designated by handle starting at byte offset in the file.  This 
  10549.           prevents other processes from reading or writing into the locked 
  10550.           region until an unlock has been done for this locked region of the 
  10551.           file.  All locked regions of a file must be unlocked before a file is 
  10552.           closed. 
  10553.  
  10554. Returns:  The lock function returns zero if successful, and -1 when an error 
  10555.           occurs.  When an error has occurred, errno contains a value 
  10556.           indicating the type of error that has been detected. 
  10557.  
  10558. See Also: locking, open, sopen, unlock 
  10559.  
  10560. Example: 
  10561.  
  10562.                     #include <stdio.h>
  10563.                     #include <fcntl.h>
  10564.                     #include <io.h>
  10565.  
  10566.                     void main()
  10567.                       {
  10568.                         int handle;
  10569.                         char buffer[20];
  10570.  
  10571.                         handle = open( "file", O_RDWR | O_TEXT );
  10572.                         if( handle != -1 ) {
  10573.                           if( lock( handle, 0L, 20L ) ) {
  10574.                             printf( "Lock failed\n" );
  10575.                           } else {
  10576.                             read( handle, buffer, 20 );
  10577.                             /* update the buffer here */
  10578.                             lseek( handle, 0L, SEEK_SET );
  10579.                             write( handle, buffer, 20 );
  10580.                             unlock( handle, 0L, 20L );
  10581.                           }
  10582.                           close( handle );
  10583.                         }
  10584.                       }
  10585.  
  10586. Classification: WATCOM 
  10587.  
  10588.  
  10589. ΓòÉΓòÉΓòÉ 187. locking ΓòÉΓòÉΓòÉ
  10590.  
  10591. Synopsis: 
  10592.  
  10593.                     #include <sys\locking.h>
  10594.                     int locking( int handle, int mode, long nbyte );
  10595.  
  10596. Description: The locking function locks or unlocks nbyte bytes of the file 
  10597.           specified by handle. Locking a region of a file prevents other 
  10598.           processes from reading or writing the locked region until the region 
  10599.           has been unlocked.  The locking and unlocking takes place at the 
  10600.           current file position.  The argument mode specifies the action to be 
  10601.           performed.  The possible values for mode are: 
  10602.  
  10603.    Mode            Meaning 
  10604.  
  10605.    LK_LOCK         Locks the specified region.  The function will retry to lock 
  10606.                    the region after 1 second intervals until successful or 
  10607.                    until 10 attempts have been made. 
  10608.  
  10609.    LK_RLCK         Same action as LK_LOCK. 
  10610.  
  10611.    LK_NBLCK        Non-blocking lock:  makes only 1 attempt to lock the 
  10612.                    specified region. 
  10613.  
  10614.    LK_NBRLCK       Same action as LK_NBLCK. 
  10615.  
  10616.    LK_UNLCK        Unlocks the specified region.  The region must have been 
  10617.                    previously locked. 
  10618.  
  10619.           Multiple regions of a file can be locked, but no overlapping regions 
  10620.           are allowed.  You cannot unlock multiple regions in the same call, 
  10621.           even if the regions are contiguous.  All locked regions should be 
  10622.           unlocked before closing a file or exiting the program.  Locking 
  10623.           requires MS-DOS Version 3.0 or later, and that SHARE.COM or SHARE.EXE 
  10624.           is installed. 
  10625.  
  10626. Returns:  The locking function returns zero if successful. Otherwise, it 
  10627.           returns -1 and errno is set to indicate the error. 
  10628.  
  10629. Errors:   When an error has occurred, errno contains a value indicating the 
  10630.           type of error that has been detected. 
  10631.  
  10632.    Constant      Meaning 
  10633.  
  10634.    EACCES        Indicates a locking violation (file already locked or 
  10635.                  unlocked). 
  10636.  
  10637.    EBADF         Indicates an invalid file handle. 
  10638.  
  10639.    EDEADLOCK     Indicates a locking violation.  This error is returned when 
  10640.                  mode is LK_LOCK or LK_RLCK and the file cannot be locked after 
  10641.                  10 attempts. 
  10642.  
  10643.    EINVAL        Indicates that an invalid argument was given to the function. 
  10644.  
  10645. See Also: creat, _dos_creat, _dos_open, lock, open, sopen, unlock 
  10646.  
  10647. Example: 
  10648.  
  10649.                     #include <stdio.h>
  10650.                     #include <sys\locking.h>
  10651.                     #include <share.h>
  10652.                     #include <fcntl.h>
  10653.                     #include <io.h>
  10654.  
  10655.                     void main()
  10656.                       {
  10657.                         int handle;
  10658.                         unsigned nbytes;
  10659.                         unsigned long offset;
  10660.                         auto char buffer[512];
  10661.  
  10662.                         nbytes = 512;
  10663.                         offset = 1024;
  10664.                         handle = sopen( "db.fil", O_RDWR, SH_DENYNO );
  10665.                         if( handle != -1 ) {
  10666.                           lseek( handle, offset, SEEK_SET );
  10667.                           locking( handle, LK_LOCK, nbytes );
  10668.                           read( handle, buffer, nbytes );
  10669.                           /* update data in the buffer */
  10670.                           lseek( handle, offset, SEEK_SET );
  10671.                           write( handle, buffer, nbytes );
  10672.                           lseek( handle, offset, SEEK_SET );
  10673.                           locking( handle, LK_UNLCK, nbytes );
  10674.                           close( handle );
  10675.                         }
  10676.                       }
  10677.  
  10678. Classification: WATCOM 
  10679.  
  10680.  
  10681. ΓòÉΓòÉΓòÉ 188. log ΓòÉΓòÉΓòÉ
  10682.  
  10683. Synopsis: 
  10684.  
  10685.                     #include <math.h>
  10686.                     double log( double x );
  10687.  
  10688. Description: The log function computes the natural logarithm (base e) of x. A 
  10689.           domain error occurs if the argument is negative.  A range error 
  10690.           occurs if the argument is zero. 
  10691.  
  10692. Returns:  The log function returns the natural logarithm of the argument.  When 
  10693.           the argument is outside the permissible range, the matherr function 
  10694.           is called.  Unless the default matherr function is replaced, it will 
  10695.           set the global variable errno to EDOM, and print a "DOMAIN error" 
  10696.           diagnostic message using the stderr stream. 
  10697.  
  10698. See Also: exp, log10, log2, pow, matherr 
  10699.  
  10700. Example: 
  10701.  
  10702.                     #include <stdio.h>
  10703.                     #include <math.h>
  10704.  
  10705.                     void main()
  10706.                       {
  10707.                         printf( "%f\n", log(.5) );
  10708.                       }
  10709.  
  10710.           produces the following: 
  10711.  
  10712.                     -0.693147
  10713.  
  10714. Classification: ANSI 
  10715.  
  10716.  
  10717. ΓòÉΓòÉΓòÉ 189. log10 ΓòÉΓòÉΓòÉ
  10718.  
  10719. Synopsis: 
  10720.  
  10721.                     #include <math.h>
  10722.                     double log10( double x );
  10723.  
  10724. Description: The log10 function computes the logarithm (base 10) of x. A domain 
  10725.           error occurs if the argument is negative.  A range error occurs if 
  10726.           the argument is zero. 
  10727.  
  10728. Returns:  The log10 function returns the logarithm (base 10) of the argument. 
  10729.           When the argument is outside the permissible range, the matherr 
  10730.           function is called.  Unless the default matherr function is replaced, 
  10731.           it will set the global variable errno to EDOM, and print a "DOMAIN 
  10732.           error" diagnostic message using the stderr stream. 
  10733.  
  10734. See Also: exp, log, log2, pow, matherr 
  10735.  
  10736. Example: 
  10737.  
  10738.                     #include <stdio.h>
  10739.                     #include <math.h>
  10740.  
  10741.                     void main()
  10742.                       {
  10743.                         printf( "%f\n", log10(.5) );
  10744.                       }
  10745.  
  10746.           produces the following: 
  10747.  
  10748.                     -0.301030
  10749.  
  10750. Classification: ANSI 
  10751.  
  10752.  
  10753. ΓòÉΓòÉΓòÉ 190. log2 ΓòÉΓòÉΓòÉ
  10754.  
  10755. Synopsis: 
  10756.  
  10757.                     #include <math.h>
  10758.                     double log2( double x );
  10759.  
  10760. Description: The log2 function computes the logarithm (base 2) of x. A domain 
  10761.           error occurs if the argument is negative.  A range error occurs if 
  10762.           the argument is zero. 
  10763.  
  10764. Returns:  The log2 function returns the logarithm (base 2) of the argument. 
  10765.           When the argument is outside the permissible range, the matherr 
  10766.           function is called.  Unless the default matherr function is replaced, 
  10767.           it will set the global variable errno to EDOM, and print a "DOMAIN 
  10768.           error" diagnostic message using the stderr stream. 
  10769.  
  10770. See Also: exp, log, log10, pow, matherr 
  10771.  
  10772. Example: 
  10773.  
  10774.                     #include <stdio.h>
  10775.                     #include <math.h>
  10776.  
  10777.                     void main()
  10778.                       {
  10779.                         printf( "%f\n", log2(.25) );
  10780.                       }
  10781.  
  10782.           produces the following: 
  10783.  
  10784.                     -2.000000
  10785.  
  10786. Classification: WATCOM 
  10787.  
  10788.  
  10789. ΓòÉΓòÉΓòÉ 191. longjmp ΓòÉΓòÉΓòÉ
  10790.  
  10791. Synopsis: 
  10792.  
  10793.                     #include <setjmp.h>
  10794.                     void longjmp( jmp_buf env, int return_value );
  10795.  
  10796. Description: The longjmp function restores the environment saved by the most 
  10797.           recent call to the setjmp function with the corresponding jmp_buf 
  10798.           argument. 
  10799.  
  10800. Returns:  After the longjmp function restores the environment, program 
  10801.           execution continues as if the corresponding call to setjmp had just 
  10802.           returned the value specified by return_value. If the value of 
  10803.           return_value is 0, the value returned is 1. 
  10804.  
  10805. See Also: setjmp 
  10806.  
  10807. Example: 
  10808.  
  10809.                     #include <stdio.h>
  10810.                     #include <setjmp.h>
  10811.                     jmp_buf env;
  10812.                     void main()
  10813.                       {
  10814.                         int ret_val = 293;
  10815.  
  10816.                         if( 0 == ( ret_val = setjmp( env ) ) ) {
  10817.                           printf( "after setjmp %d\n", ret_val );
  10818.                           rtn();
  10819.                           printf( "back from rtn %d\n", ret_val );
  10820.                         } else {
  10821.                           printf( "back from longjmp %d\n", ret_val );
  10822.                         }
  10823.                       }
  10824.                     rtn()
  10825.                       {
  10826.                         printf( "about to longjmp\n" );
  10827.                         longjmp( env, 14 );
  10828.                       }
  10829.  
  10830.           produces the following: 
  10831.  
  10832.                     after setjmp 0
  10833.                     about to longjmp
  10834.                     back from longjmp 14
  10835.  
  10836. Classification: ANSI 
  10837.  
  10838.  
  10839. ΓòÉΓòÉΓòÉ 192. _lrotl ΓòÉΓòÉΓòÉ
  10840.  
  10841. Synopsis: 
  10842.  
  10843.                     #include <stdlib.h>
  10844.                     unsigned long _lrotl( unsigned long value,
  10845.                                           unsigned int shift );
  10846.  
  10847. Description: The _lrotl function rotates the unsigned long integer, determined 
  10848.           by value, to the left by the number of bits specified in shift. 
  10849.  
  10850. Returns:  The rotated value is returned. 
  10851.  
  10852. See Also: _lrotr, _rotl, _rotr 
  10853.  
  10854. Example: 
  10855.  
  10856.                     #include <stdio.h>
  10857.                     #include <stdlib.h>
  10858.  
  10859.                     unsigned long mask = 0x12345678;
  10860.  
  10861.                     void main()
  10862.                       {
  10863.                         mask = _lrotl( mask, 4 );
  10864.                         printf( "%08lX\n", mask );
  10865.                       }
  10866.  
  10867.           produces the following: 
  10868.  
  10869.                     23456781
  10870.  
  10871. Classification: WATCOM 
  10872.  
  10873.  
  10874. ΓòÉΓòÉΓòÉ 193. _lrotr ΓòÉΓòÉΓòÉ
  10875.  
  10876. Synopsis: 
  10877.  
  10878.                     #include <stdlib.h>
  10879.                     unsigned long _lrotr( unsigned long value,
  10880.                                           unsigned int shift );
  10881.  
  10882. Description: The _lrotr function rotates the unsigned long integer, determined 
  10883.           by value, to the right by the number of bits specified in shift. 
  10884.  
  10885. Returns:  The rotated value is returned. 
  10886.  
  10887. See Also: _lrotl, _rotl, _rotr 
  10888.  
  10889. Example: 
  10890.  
  10891.                     #include <stdio.h>
  10892.                     #include <stdlib.h>
  10893.  
  10894.                     unsigned long mask = 0x12345678;
  10895.  
  10896.                     void main()
  10897.                       {
  10898.                         mask = _lrotr( mask, 4 );
  10899.                         printf( "%08lX\n", mask );
  10900.                       }
  10901.  
  10902.           produces the following: 
  10903.  
  10904.                     81234567
  10905.  
  10906. Classification: WATCOM 
  10907.  
  10908.  
  10909. ΓòÉΓòÉΓòÉ 194. lsearch ΓòÉΓòÉΓòÉ
  10910.  
  10911. Synopsis: 
  10912.  
  10913.                     #include <search.h>
  10914.                     void *lsearch( const void *key, /* object to search for */
  10915.                                    const void *base,/* base of search data  */
  10916.                                    unsigned *num,   /* number of elements   */
  10917.                                    unsigned width,  /* width of each element*/
  10918.                                    int (*compare)( const void *element1,
  10919.                                                    const void *element2 ) );
  10920.  
  10921. Description: The lsearch function performs a linear search for the value key in 
  10922.           the array of num elements pointed to by base. Each element of the 
  10923.           array is width bytes in size.  The argument compare is a pointer to a 
  10924.           user-supplied routine that will be called by lsearch to determine the 
  10925.           relationship of an array element with the key. One of the arguments 
  10926.           to the compare function will be an array element, and the other will 
  10927.           be key. 
  10928.  
  10929.           The compare function should return 0 if element1 is identical to 
  10930.           element2 and non-zero if the elements are not identical. 
  10931.  
  10932. Returns:  If the key value is not found in the array, then it is added to the 
  10933.           end of the array and the number of elements is incremented.  The 
  10934.           lsearch function returns a pointer to the array element in base that 
  10935.           matches key if it is found, or the newly added key if it was not 
  10936.           found. 
  10937.  
  10938. See Also: bsearch, lfind 
  10939.  
  10940. Example: 
  10941.  
  10942.                     #include <stdio.h>
  10943.                     #include <stdlib.h>
  10944.                     #include <string.h>
  10945.                     #include <search.h>
  10946.                     void main( int argc, char *argv[] )
  10947.                       {
  10948.                         int i;
  10949.                         unsigned num = 0;
  10950.                         char **array = calloc( argc, sizeof(char **) );
  10951.                         int compare( char **, char ** );
  10952.                         for( i = 1; i < argc; ++i ) {
  10953.                           lsearch( &argv[i], array, &num, sizeof(char **),
  10954.                                       compare );
  10955.                         }
  10956.                         for( i = 0; i < num; ++i ) {
  10957.                           printf( "%s\n", array[i] );
  10958.                         }
  10959.                       }
  10960.                     int compare( char **op1, char **op2 )
  10961.                       {
  10962.                         return( strcmp( *op1, *op2 ) );
  10963.                       }
  10964.                     /* With input: one two one three four */
  10965.  
  10966.           produces the following: 
  10967.  
  10968.                     one
  10969.                     two
  10970.                     three
  10971.                     four
  10972.  
  10973. Classification: WATCOM 
  10974.  
  10975.  
  10976. ΓòÉΓòÉΓòÉ 195. lseek ΓòÉΓòÉΓòÉ
  10977.  
  10978. Synopsis: 
  10979.  
  10980.                     #include <stdio.h>
  10981.                     #include <io.h>
  10982.                     long int lseek( int handle, long int offset, int whence );
  10983.  
  10984. Description: The lseek function sets the current file position at the operating 
  10985.           system level.  The file is referenced using the file handle handle 
  10986.           returned by a successful execution of one of the creat, dup, dup2, 
  10987.           open or sopen functions.  The value of offset is used as a relative 
  10988.           offset from a file position determined by the value of the argument 
  10989.           whence. 
  10990.  
  10991.           The new file position is determined in a manner dependent upon the 
  10992.           value of whence which may have one of three possible values (defined 
  10993.           in the <stdio.h> header file): 
  10994.  
  10995.    Whence          Definition 
  10996.  
  10997.    SEEK_SET        The new file position is computed relative to the start of 
  10998.                    the file.  The value of offset must not be negative. 
  10999.  
  11000.    SEEK_CUR        The new file position is computed relative to the current 
  11001.                    file position. The value of offset may be positive, negative 
  11002.                    or zero. 
  11003.  
  11004.    SEEK_END        The new file position is computed relative to the end of the 
  11005.                    file. 
  11006.  
  11007.           An error will occur if the requested file position is before the 
  11008.           start of the file. 
  11009.  
  11010.           The requested file position may be beyond the end of the file.  If 
  11011.           data is later written at this point, subsequent reads of data in the 
  11012.           gap will return bytes whose value is equal to zero until data is 
  11013.           actually written in the gap. 
  11014.  
  11015.           The lseek function does not, in itself, extend the size of a file 
  11016.           (see the description of the chsize function). 
  11017.  
  11018. Returns:  If successful, the current file position is returned in a 
  11019.           system-dependent manner.  A value of 0 indicates the start of the 
  11020.           file. When an error occurs, -1 is returned and errno is set to 
  11021.           indicate the error. 
  11022.  
  11023. Errors:   When an error has occurred, errno contains a value indicating the 
  11024.           type of error that has been detected. 
  11025.  
  11026.    Constant  Meaning 
  11027.  
  11028.    EBADF     The handle argument is not a valid file handle. 
  11029.  
  11030.    EINVAL    The whence argument is not a proper value, or the resulting file 
  11031.              offset would be invalid. 
  11032.  
  11033. See Also: close, creat, dup, dup2, eof, exec Functions, filelength, fileno, 
  11034.           fstat, isatty, open, read, setmode, sopen, stat, tell, write, umask 
  11035.  
  11036. Example: 
  11037.  
  11038.           The lseek function can be used to obtain the current file position 
  11039.           (the tell function is implemented in terms of lseek).  This value can 
  11040.           then be used with the lseek function to reset the file position to 
  11041.           that point in the file: 
  11042.  
  11043.                     long int file_posn;
  11044.                     int handle;
  11045.  
  11046.                     /* get current file position */
  11047.                     file_posn = lseek( handle, 0L, SEEK_CUR );
  11048.                       /* or */
  11049.                     file_posn = tell( handle );
  11050.  
  11051.                     /* return to previous file position */
  11052.                     file_posn = lseek( handle, file_posn, SEEK_SET );
  11053.  
  11054.           If all records in the file are the same size, the position of the 
  11055.           n'th record can be calculated and read, as illustrated in the 
  11056.           following sample function: 
  11057.  
  11058.                     #include <stdio.h>
  11059.                     #include <io.h>
  11060.  
  11061.                     int read_record( int  handle,
  11062.                                      long rec_numb,
  11063.                                      int  rec_size,
  11064.                                      char *buffer )
  11065.                       {
  11066.                         if( lseek( handle, rec_numb * rec_size, SEEK_SET )
  11067.                              == -1L ) {
  11068.                           return( -1 );
  11069.                         }
  11070.                         return( read( handle, buffer, rec_size ) );
  11071.                       }
  11072.  
  11073.           The function in this example assumes records are numbered starting 
  11074.           with zero and that rec_size contains the size of a record in the file 
  11075.           (including the carriage-return character in text files). 
  11076.  
  11077. Classification: POSIX 1003.1 
  11078.  
  11079.  
  11080. ΓòÉΓòÉΓòÉ 196. ltoa ΓòÉΓòÉΓòÉ
  11081.  
  11082. Synopsis: 
  11083.  
  11084.                     #include <stdlib.h>
  11085.                     char *ltoa( long int value,
  11086.                                 char *buffer,
  11087.                                 int radix );
  11088.  
  11089. Description: The ltoa function converts the binary integer value into the 
  11090.           equivalent string in base radix notation storing the result in the 
  11091.           character array pointed to by buffer. A null character is appended to 
  11092.           the result.  The size of buffer must be at least 33 bytes when 
  11093.           converting values in base 2.  If the value of radix is 10 and value 
  11094.           is negative, then a minus sign is prepended to the result. 
  11095.  
  11096. Returns:  The ltoa function returns a pointer to the result. 
  11097.  
  11098. See Also: atol, strtol, strtoul, ultoa 
  11099.  
  11100. Example: 
  11101.  
  11102.                     #include <stdio.h>
  11103.                     #include <stdlib.h>
  11104.  
  11105.                     void print_value( long value )
  11106.                       {
  11107.                         int base;
  11108.                         char buffer[33];
  11109.  
  11110.                         for( base=8; base<=16; base=base+2 )
  11111.                           printf( "%2d %s\n", base,
  11112.                                   ltoa( value, buffer, base ) );
  11113.                       }
  11114.  
  11115.           produces the following: 
  11116.  
  11117.                      8 30735
  11118.                     10 12765
  11119.                     12 7479
  11120.                     14 491b
  11121.                     16 31dd
  11122.  
  11123. Classification: WATCOM 
  11124.  
  11125.  
  11126. ΓòÉΓòÉΓòÉ 197. main ΓòÉΓòÉΓòÉ
  11127.  
  11128. Synopsis: 
  11129.  
  11130.                     int main( void );
  11131.                     int main( int argc, const char *argv[] );
  11132.  
  11133. Description: The function main is a user-supplied function where program 
  11134.           execution begins.  The command line to the program is broken into a 
  11135.           sequence of tokens separated by blanks and are passed to main as an 
  11136.           array of pointers to character strings in the parameter argv. The 
  11137.           number of arguments found is passed in the parameter argc. The first 
  11138.           element of argv will be a pointer to a character string containing 
  11139.           the program name.  The last element of the array pointed to by argv 
  11140.           will be a NULL pointer (i.e.  argv[argc] will be NULL ).  Arguments 
  11141.           that contain blanks can be passed to main by enclosing them within 
  11142.           double quote characters (which are removed from that element in the 
  11143.           argv vector. 
  11144.  
  11145.           The command line arguments can also be obtained in its original 
  11146.           format by using the getcmd function. 
  11147.  
  11148. Returns:  The function main returns a return code back to the calling program 
  11149.           (usually the operating system). 
  11150.  
  11151. See Also: abort, atexit, exec Functions, exit, _exit, getcmd, getenv, onexit, 
  11152.           putenv, spawn Functions, system 
  11153.  
  11154. Example: 
  11155.  
  11156.                     #include <stdio.h>
  11157.  
  11158.                     int main( int argc, char *argv[] )
  11159.                       {
  11160.                         int i;
  11161.                         for( i = 0; i < argc; ++i ) {
  11162.                           printf( "argv[%d] = %s\n", i, argv[i] );
  11163.                         }
  11164.                         return( 0 );
  11165.                       }
  11166.  
  11167.           produces the following: 
  11168.  
  11169.                     argv[0] = C:\WATCOM\DEMO\MYPGM.EXE
  11170.                     argv[1] = hhhhh
  11171.                     argv[2] = another arg
  11172.  
  11173.           when the program mypgm is executed with the command 
  11174.  
  11175.                     mypgm hhhhh  "another arg"
  11176.  
  11177.  
  11178. Classification: ANSI 
  11179.  
  11180.  
  11181. ΓòÉΓòÉΓòÉ 198. _makepath ΓòÉΓòÉΓòÉ
  11182.  
  11183. Synopsis: 
  11184.  
  11185.                     #include <stdlib.h>
  11186.                     void _makepath( char *path,
  11187.                                     const char *drive,
  11188.                                     const char *dir,
  11189.                                     const char *fname,
  11190.                                     const char *ext );
  11191.  
  11192. Description: The _makepath function constructs a full pathname from the 
  11193.           components consisting of a drive letter, directory path, file name 
  11194.           and file name extension.  The full pathname is placed in the buffer 
  11195.           pointed to by the argument path. 
  11196.  
  11197.           The maximum size required for each buffer is specified by the 
  11198.           manifest constants _MAX_PATH, _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and 
  11199.           _MAX_EXT which are defined in <stdlib.h>. 
  11200.  
  11201.    drive     The drive argument points to a buffer containing the drive letter 
  11202.              (A, B, C, etc.) followed by an optional colon.  The _makepath 
  11203.              function will automatically insert a colon in the full pathname if 
  11204.              it is missing.  If drive is a NULL pointer or points to an empty 
  11205.              string, no drive letter or colon will be placed in the full 
  11206.              pathname. 
  11207.  
  11208.    dir       The dir argument points to a buffer containing just the pathname. 
  11209.              Either forward slashes (/) or backslashes (\) may be used.  The 
  11210.              trailing slash is optional. The _makepath function will 
  11211.              automatically insert a trailing slash in the full pathname if it 
  11212.              is missing.  If dir is a NULL pointer or points to an empty 
  11213.              string, no slash will be placed in the full pathname. 
  11214.  
  11215.    fname     The fname argument points to a buffer containing the base name of 
  11216.              the file without any extension (suffix). 
  11217.  
  11218.    ext       The ext argument points to a buffer containing the filename 
  11219.              extension or suffix.  A leading period (.) is optional.  The 
  11220.              _makepath routine will automatically insert a period in the full 
  11221.              pathname if it is missing.  If ext is a NULL pointer or points to 
  11222.              an empty string, no period will be placed in the full pathname. 
  11223.  
  11224. Returns:  The _makepath function returns no value. 
  11225.  
  11226. See Also: _fullpath, _splitpath 
  11227.  
  11228. Example: 
  11229.  
  11230.                     #include <stdio.h>
  11231.                     #include <stdlib.h>
  11232.  
  11233.                     void main()
  11234.                       {
  11235.                         char full_path[ _MAX_PATH ];
  11236.                         char drive[ _MAX_DRIVE ];
  11237.                         char dir[ _MAX_DIR ];
  11238.                         char fname[ _MAX_FNAME ];
  11239.                         char ext[ _MAX_EXT ];
  11240.  
  11241.                         _makepath(full_path,"c","watcomc\\h\\","stdio","h");
  11242.                         printf( "Full path is: %s\n\n", full_path );
  11243.                         _splitpath( full_path, drive, dir, fname, ext );
  11244.                         printf( "Components after _splitpath\n" );
  11245.                         printf( "drive: %s\n", drive );
  11246.                         printf( "dir:   %s\n", dir );
  11247.                         printf( "fname: %s\n", fname );
  11248.                         printf( "ext:   %s\n", ext );
  11249.                       }
  11250.  
  11251.           produces the following: 
  11252.  
  11253.                     Full path is: c:watcomc\h\stdio.h
  11254.  
  11255.                     Components after _splitpath
  11256.                     drive: c:
  11257.                     dir:   watcomc\h\
  11258.                     fname: stdio
  11259.                     ext:   .h
  11260.  
  11261.           Note the use of two adjacent backslash characters (\) within 
  11262.           character-string constants to signify a single backslash. 
  11263.  
  11264.  
  11265. Classification: WATCOM 
  11266.  
  11267.  
  11268. ΓòÉΓòÉΓòÉ 199. malloc Functions ΓòÉΓòÉΓòÉ
  11269.  
  11270. Synopsis: 
  11271.  
  11272.                     #include <stdlib.h>  For ANSI compatibility (malloc only)
  11273.                     #include <malloc.h>  Required for other function prototypes
  11274.                     void *malloc( size_t size );
  11275.                     void __based(void) *_bmalloc( __segment seg, size_t size );
  11276.                     void __far  *_fmalloc( size_t size );
  11277.                     void __near *_nmalloc( size_t size );
  11278.  
  11279. Description: The malloc functions allocate space for an object of size bytes. 
  11280.           Nothing is allocated when the size argument has a value of zero. 
  11281.  
  11282.           Each function allocates memory from a particular heap, as listed 
  11283.           below: 
  11284.  
  11285.    Function      Heap 
  11286.    malloc        Depends on data model of the program 
  11287.    _bmalloc      Based heap specified by seg value 
  11288.    _fmalloc      Far heap (outside the default data segment) 
  11289.    _nmalloc      Near heap (inside the default data segment) 
  11290.  
  11291.           In a small data memory model, the malloc function is equivalent to 
  11292.           the _nmalloc function; in a large data memory model, the malloc 
  11293.           function is equivalent to the _fmalloc function. 
  11294.  
  11295. Returns:  The malloc functions return a pointer to the start of the allocated 
  11296.           memory.  The malloc, _fmalloc and _nmalloc functions return NULL if 
  11297.           there is insufficient memory available or if the requested size is 
  11298.           zero. The _bmalloc function returns _NULLOFF if there is insufficient 
  11299.           memory available or if the requested size is zero. 
  11300.  
  11301. See Also: calloc Functions, _expand Functions, free Functions, halloc, hfree, 
  11302.           _msize Functions, realloc Functions, sbrk 
  11303.  
  11304. Example: 
  11305.  
  11306.                     #include <stdlib.h>
  11307.  
  11308.                     void main()
  11309.                       {
  11310.                         char *buffer;
  11311.  
  11312.                         buffer = (char *)malloc( 80 );
  11313.                        .
  11314.                        .
  11315.                        .
  11316.                         free( buffer );
  11317.                       }
  11318.  
  11319. Classification: malloc is ANSI; _bmalloc, _fmalloc, _nmalloc are not ANSI 
  11320.  
  11321.  
  11322. ΓòÉΓòÉΓòÉ 200. matherr ΓòÉΓòÉΓòÉ
  11323.  
  11324. Synopsis: 
  11325.  
  11326.                     #include <math.h>
  11327.                     int matherr( struct exception *err_info );
  11328.  
  11329. Description: The matherr function is invoked each time an error is detected by 
  11330.           functions in the math library.  The default matherr function supplied 
  11331.           in the library returns zero which causes an error message to be 
  11332.           displayed upon stderr and errno to be set with an appropriate error 
  11333.           value.  An alternative version of this function can be provided, 
  11334.           instead of the library version, in order that the error handling for 
  11335.           mathematical errors can be handled by an application. 
  11336.  
  11337.           A program may contain a user-written version of matherr to take any 
  11338.           appropriate action when an error is detected.  When zero is returned, 
  11339.           an error message will be printed upon stderr and errno will be set as 
  11340.           was the case with the default function.  When a non-zero value is 
  11341.           returned, no message is printed and errno is not changed.  The value 
  11342.           err_info->retval is used as the return value for the function in 
  11343.           which the error was detected. 
  11344.  
  11345.           The matherr function is passed a pointer to a structure of type 
  11346.           struct exception which contains information about the error that has 
  11347.           been detected: 
  11348.  
  11349.                     struct exception
  11350.                     { int type;      /* TYPE OF ERROR                */
  11351.                       char *name;    /* NAME OF FUNCTION             */
  11352.                       double arg1;   /* FIRST ARGUMENT TO FUNCTION   */
  11353.                       double arg2;   /* SECOND ARGUMENT TO FUNCTION  */
  11354.                       double retval; /* DEFAULT RETURN VALUE         */
  11355.                     };
  11356.  
  11357.           The type field will contain one of the following values: 
  11358.  
  11359.    Value           Meaning 
  11360.    DOMAIN          A domain error has occurred, such as sqrt(-1e0). 
  11361.    SING            A singularity will result, such as pow(0e0,-2). 
  11362.    OVERFLOW        An overflow will result, such as pow(10e0,100). 
  11363.    UNDERFLOW       An underflow will result, such as pow(10e0,-100). 
  11364.    TLOSS           Total loss of significance will result, such as exp(1000). 
  11365.    PLOSS           Partial loss of significance will result, such as 
  11366.                    sin(10e70). 
  11367.  
  11368.           The name field points to a string containing the name of the function 
  11369.           which detected the error.  The fields arg1 and arg2 (if required) 
  11370.           give the values which caused the error.  The field retval contains 
  11371.           the value which will be returned by the function.  This value may be 
  11372.           changed by a user-supplied version of the matherr function. 
  11373.  
  11374. Returns:  The matherr function returns zero when an error message is to be 
  11375.           printed and a non-zero value otherwise. 
  11376.  
  11377. Example: 
  11378.  
  11379.                     #include <stdio.h>
  11380.                     #include <string.h>
  11381.                     #include <math.h>
  11382.  
  11383.                     /* Demonstrate error routine in which negative */
  11384.                     /* arguments to "sqrt" are treated as positive */
  11385.  
  11386.                     void main()
  11387.                       {
  11388.                         printf( "%e\n", sqrt( -5e0 ) );
  11389.                         exit( 0 );
  11390.                       }
  11391.  
  11392.                     int matherr( struct exception *err )
  11393.                       {
  11394.                         if( strcmp( err->name, "sqrt" ) == 0 ) {
  11395.                           if( err->type == DOMAIN ) {
  11396.                             err->retval = sqrt( -(err->arg1) );
  11397.                             return( 1 );
  11398.                           } else
  11399.                             return( 0 );
  11400.                         } else
  11401.                           return( 0 );
  11402.                       }
  11403.  
  11404. Classification: WATCOM 
  11405.  
  11406.  
  11407. ΓòÉΓòÉΓòÉ 201. max ΓòÉΓòÉΓòÉ
  11408.  
  11409. Synopsis: 
  11410.  
  11411.                     #include <stdlib.h>
  11412.                     #define max(a,b)  (((a) > (b)) ? (a) : (b))
  11413.  
  11414. Description: The max macro will evaluate to be the greater of two values.  It 
  11415.           is implemented as follows. 
  11416.  
  11417.                     #define max(a,b)  (((a) > (b)) ? (a) : (b))
  11418.  
  11419. Returns:  The max macro will evaluate to the larger of the two values passed. 
  11420.  
  11421. See Also: min 
  11422.  
  11423. Example: 
  11424.  
  11425.                     #include <stdio.h>
  11426.                     #include <stdlib.h>
  11427.                     void main()
  11428.                       {
  11429.                         int a;
  11430.                         /*
  11431.                          * The following line will set the variable "a" to 10
  11432.                          * since 10 is greater than 1.
  11433.                          */
  11434.                         a = max( 1, 10 );
  11435.                         printf( "The value is: %d\n", a );
  11436.                       }
  11437.  
  11438. Classification: WATCOM 
  11439.  
  11440.  
  11441. ΓòÉΓòÉΓòÉ 202. mblen ΓòÉΓòÉΓòÉ
  11442.  
  11443. Synopsis: 
  11444.  
  11445.                     #include <stdlib.h>
  11446.                     int mblen( const char *s, size_t n );
  11447.  
  11448. Description: The mblen function determines the number of bytes comprising the 
  11449.           multibyte character pointed to by s. At most n bytes of the array 
  11450.           pointed to by s will be examined. 
  11451.  
  11452. Returns:  If s is a NULL pointer, the mblen function returns zero if multibyte 
  11453.           character encodings do not have state-dependent encoding, and 
  11454.           non-zero otherwise.  If s is not a NULL pointer, the mblen function 
  11455.           returns: 
  11456.  
  11457.    Value     Meaning 
  11458.  
  11459.    0         if s points to the null character 
  11460.  
  11461.    len       the number of bytes that comprise the multibyte character (if the 
  11462.              next n or fewer bytes form a valid multibyte character) 
  11463.  
  11464.    -1        if the next n bytes do not form a valid multibyte character 
  11465.  
  11466. See Also: mbtowc, mbstowcs, wctomb, wcstombs 
  11467.  
  11468. Classification: ANSI 
  11469.  
  11470.  
  11471. ΓòÉΓòÉΓòÉ 203. mbstowcs ΓòÉΓòÉΓòÉ
  11472.  
  11473. Synopsis: 
  11474.  
  11475.                     #include <stdlib.h>
  11476.                     size_t mbstowcs( wchar_t *pwcs,const char *s,size_t n );
  11477.  
  11478. Description: The mbstowcs function converts a sequence of multibyte characters 
  11479.           pointed to by s into their corresponding wide character codes and 
  11480.           stores not more than n codes into the array pointed to by pwcs. The 
  11481.           mbstowcs function does not convert any multibyte characters beyond 
  11482.           the null character.  At most n elements of the array pointed to by 
  11483.           pwcs will be modified. 
  11484.  
  11485. Returns:  If an invalid multibyte character is encountered, the mbstowcs 
  11486.           function returns (size_t)-1. Otherwise, the mbstowcs function returns 
  11487.           the number of array elements modified, not including the terminating 
  11488.           zero code if present. 
  11489.  
  11490. See Also: mblen, mbtowc, wctomb, wcstombs 
  11491.  
  11492. Classification: ANSI 
  11493.  
  11494.  
  11495. ΓòÉΓòÉΓòÉ 204. mbtowc ΓòÉΓòÉΓòÉ
  11496.  
  11497. Synopsis: 
  11498.  
  11499.                     #include <stdlib.h>
  11500.                     int mbtowc( wchar_t *pwc, const char *s, size_t n );
  11501.  
  11502. Description: The mbtowc function converts a single multibyte character pointed 
  11503.           to by s into the wide character code that corresponds to that 
  11504.           multibyte character. The code for the null character is zero.  If the 
  11505.           multibyte character is valid and pwc is not a NULL pointer, the code 
  11506.           is stored in the object pointed to by pwc. At most n bytes of the 
  11507.           array pointed to by s will be examined. 
  11508.  
  11509. Returns:  If s is a NULL pointer, the mbtowc function returns zero if multibyte 
  11510.           character encodings do not have state-dependent encoding, and 
  11511.           non-zero otherwise.  If s is not a NULL pointer, the mbtowc function 
  11512.           returns: 
  11513.  
  11514.    Value     Meaning 
  11515.  
  11516.    0         if s points to the null character 
  11517.  
  11518.    len       the number of bytes that comprise the multibyte character (if the 
  11519.              next n or fewer bytes form a valid multibyte character) 
  11520.  
  11521.    -1        if the next n bytes do not form a valid multibyte character 
  11522.  
  11523. See Also: mblen, wctomb, mbstowcs, wcstombs 
  11524.  
  11525. Classification: ANSI 
  11526.  
  11527.  
  11528. ΓòÉΓòÉΓòÉ 205. _memavl ΓòÉΓòÉΓòÉ
  11529.  
  11530. Synopsis: 
  11531.  
  11532.                     #include <malloc.h>
  11533.                     size_t _memavl( void );
  11534.  
  11535. Description: The _memavl function returns the number of bytes of memory 
  11536.           available for dynamic memory allocation in the near heap (the default 
  11537.           data segment).  In the tiny, small and medium memory models, the 
  11538.           default data segment is only extended as needed to satisfy requests 
  11539.           for memory allocation.  Therefore, you will need to call _nheapgrow 
  11540.           in these memory models before calling _memavl in order to get a 
  11541.           meaningful result. 
  11542.  
  11543.           The number returned by _memavl may not represent a single contiguous 
  11544.           block of memory.  Use the _memmax function to find the largest 
  11545.           contiguous block of memory that can be allocated. 
  11546.  
  11547. Returns:  The _memavl function returns the number of bytes of memory available 
  11548.           for dynamic memory allocation in the near heap (the default data 
  11549.           segment). 
  11550.  
  11551. See Also: calloc Functions, _freect, _memmax, _heapgrow Functions, malloc 
  11552.           Functions, realloc Functions 
  11553.  
  11554. Example: 
  11555.  
  11556.                     #include <stdio.h>
  11557.                     #include <malloc.h>
  11558.  
  11559.                     void main()
  11560.                       {
  11561.                         char *p;
  11562.                         char *fmt = "Memory available = %u\n";
  11563.  
  11564.                         printf( fmt, _memavl() );
  11565.                         _nheapgrow();
  11566.                         printf( fmt, _memavl() );
  11567.                         p = malloc( 2000 );
  11568.                         printf( fmt, _memavl() );
  11569.                       }
  11570.  
  11571.           produces the following: 
  11572.  
  11573.                     Memory available = 0
  11574.                     Memory available = 62732
  11575.                     Memory available = 60730
  11576.  
  11577. Classification: WATCOM 
  11578.  
  11579.  
  11580. ΓòÉΓòÉΓòÉ 206. memccpy, _fmemccpy ΓòÉΓòÉΓòÉ
  11581.  
  11582. Synopsis: 
  11583.  
  11584.                     #include <string.h>
  11585.                     void *memccpy( void *dest, const void *src,
  11586.                                    int c, unsigned cnt );
  11587.                     void __far *_fmemccpy( void __far *dest,
  11588.                                            const void __far *src,
  11589.                                            int c, unsigned cnt );
  11590.  
  11591. Description: The memccpy and _fmemccpy functions copy bytes from src to dest up 
  11592.           to and including the first occurrence of the character c or until cnt 
  11593.           bytes have been copied, whichever comes first. 
  11594.  
  11595.           The _fmemccpy function is a data model independent form of the 
  11596.           memccpy function.  It accepts far pointer arguments and returns a far 
  11597.           pointer.  It is most useful in mixed memory model applications. 
  11598.  
  11599. Returns:  The memccpy and _fmemccpy functions return a pointer to the byte in 
  11600.           dest following the character c if one is found and copied, otherwise 
  11601.           it returns NULL. 
  11602.  
  11603. See Also: memcpy, memmove, memset 
  11604.  
  11605. Example: 
  11606.  
  11607.                     #include <stdio.h>
  11608.                     #include <string.h>
  11609.  
  11610.                     char *msg = "This is the string: not copied";
  11611.  
  11612.                     void main()
  11613.                       {
  11614.                         auto char buffer[80];
  11615.  
  11616.                         memset( buffer, '\0', 80 );
  11617.                         memccpy( buffer, msg, ':', 80 );
  11618.                         printf( "%s\n", buffer );
  11619.                       }
  11620.  
  11621.           produces the following: 
  11622.  
  11623.                     This is the string:
  11624.  
  11625. Classification: WATCOM 
  11626.  
  11627.  
  11628. ΓòÉΓòÉΓòÉ 207. memchr, _fmemchr ΓòÉΓòÉΓòÉ
  11629.  
  11630. Synopsis: 
  11631.  
  11632.                     #include <string.h>
  11633.                     void *memchr( const void *buf, int ch, size_t length );
  11634.                     void __far *_fmemchr( const void __far *buf,
  11635.                                           int ch,
  11636.                                           size_t length );
  11637.  
  11638. Description: The memchr and _fmemchr functions locate the first occurrence of 
  11639.           ch (converted to an unsigned char) in the first length characters of 
  11640.           the object pointed to by buf. 
  11641.  
  11642.           The _fmemchr function is a data model independent form of the memchr 
  11643.           function.  It accepts far pointer arguments and returns a far 
  11644.           pointer.  It is most useful in mixed memory model applications. 
  11645.  
  11646. Returns:  The memchr and _fmemchr functions return a pointer to the located 
  11647.           character, or NULL if the character does not occur in the object. 
  11648.  
  11649. See Also: memcmp, memcpy, memset 
  11650.  
  11651. Example: 
  11652.  
  11653.                     #include <stdio.h>
  11654.                     #include <string.h>
  11655.  
  11656.                     void main()
  11657.                       {
  11658.                         char buffer[80];
  11659.                         char *where;
  11660.  
  11661.                         strcpy( buffer, "video x-rays" );
  11662.                         where = (char *) memchr( buffer, 'x', 6 );
  11663.                         if( where == NULL )
  11664.                           printf( "'x' not found\n" );
  11665.                         else
  11666.                           printf( "%s\n", where );
  11667.                         where = (char *) memchr( buffer, 'r', 9 );
  11668.                         if( where == NULL )
  11669.                           printf( "'r' not found\n" );
  11670.                         else
  11671.                           printf( "%s\n", where );
  11672.                       }
  11673.  
  11674. Classification: memchr is ANSI, _fmemchr is not ANSI 
  11675.  
  11676.  
  11677. ΓòÉΓòÉΓòÉ 208. memcmp, _fmemcmp ΓòÉΓòÉΓòÉ
  11678.  
  11679. Synopsis: 
  11680.  
  11681.                     #include <string.h>
  11682.                     int memcmp( const void *s1,
  11683.                                 const void *s2,
  11684.                                 size_t length );
  11685.                     int _fmemcmp( const void __far *s1,
  11686.                                   const void __far *s2,
  11687.                                   size_t length );
  11688.  
  11689. Description: The memcmp and _fmemcmp functions compare the first length 
  11690.           characters of the object pointed to by s1 to the object pointed to by 
  11691.           s2. 
  11692.  
  11693.           The _fmemcmp function is a data model independent form of the memcmp 
  11694.           function that accepts far pointer arguments.  It is most useful in 
  11695.           mixed memory model applications. 
  11696.  
  11697. Returns:  The memcmp and _fmemcmp functions return an integer less than, equal 
  11698.           to, or greater than zero, indicating that the object pointed to by s1 
  11699.           is less than, equal to, or greater than the object pointed to by s2. 
  11700.  
  11701. See Also: memchr, memcpy, memicmp, memset 
  11702.  
  11703. Example: 
  11704.  
  11705.                     #include <stdio.h>
  11706.                     #include <string.h>
  11707.  
  11708.                     void main()
  11709.                       {
  11710.                         auto char buffer[80];
  11711.  
  11712.                         strcpy( buffer, "world" );
  11713.                         if( memcmp( buffer, "Hello ", 6 ) < 0 ) {
  11714.                           printf( "Less than\n" );
  11715.                         }
  11716.                       }
  11717.  
  11718. Classification: memcmp is ANSI, _fmemcmp is not ANSI 
  11719.  
  11720.  
  11721. ΓòÉΓòÉΓòÉ 209. memcpy, _fmemcpy ΓòÉΓòÉΓòÉ
  11722.  
  11723. Synopsis: 
  11724.  
  11725.                     #include <string.h>
  11726.                     void *memcpy( void *dst,
  11727.                                   const void *src,
  11728.                                   size_t length );
  11729.                     void __far *_fmemcpy( void __far *dst,
  11730.                                           const void __far *src,
  11731.                                           size_t length );
  11732.  
  11733. Description: The memcpy and _fmemcpy functions copy length characters from the 
  11734.           buffer pointed to by src into the buffer pointed to by dst. Copying 
  11735.           of overlapping objects is not guaranteed to work properly.  See the 
  11736.           memmove function if you wish to copy objects that overlap. 
  11737.  
  11738.           The _fmemcpy function is a data model independent form of the memcpy 
  11739.           function.  It accepts far pointer arguments and returns a far 
  11740.           pointer.  It is most useful in mixed memory model applications. 
  11741.  
  11742. Returns:  The original value of dst is returned. 
  11743.  
  11744. See Also: memchr, memcmp, memmove, memset 
  11745.  
  11746. Example: 
  11747.  
  11748.                     #include <stdio.h>
  11749.                     #include <string.h>
  11750.  
  11751.                     void main()
  11752.                       {
  11753.                         auto char buffer[80];
  11754.  
  11755.                         memcpy( buffer, "Hello", 5 );
  11756.                         buffer[5] = '\0';
  11757.                         printf( "%s\n", buffer );
  11758.                       }
  11759.  
  11760. Classification: memcpy is ANSI, _fmemcpy is not ANSI 
  11761.  
  11762.  
  11763. ΓòÉΓòÉΓòÉ 210. memicmp, _fmemicmp ΓòÉΓòÉΓòÉ
  11764.  
  11765. Synopsis: 
  11766.  
  11767.                     #include <string.h>
  11768.                     int memicmp( const void *s1,
  11769.                                  const void *s2,
  11770.                                  size_t length );
  11771.                     int _fmemicmp( const void __far *s1,
  11772.                                    const void __far *s2,
  11773.                                    size_t length );
  11774.  
  11775. Description: The memicmp and _fmemicmp functions compare, with case 
  11776.           insensitivity (upper- and lower-case characters are equivalent), the 
  11777.           first length characters of the object pointed to by s1 to the object 
  11778.           pointed to by s2. 
  11779.  
  11780.           The _fmemicmp function is a data model independent form of the 
  11781.           memicmp function that accepts far pointer arguments.  It is most 
  11782.           useful in mixed memory model applications. 
  11783.  
  11784. Returns:  The memicmp and _fmemicmp functions return an integer less than, 
  11785.           equal to, or greater than zero, indicating that the object pointed to 
  11786.           by s1 is less than, equal to, or greater than the object pointed to 
  11787.           by s2. 
  11788.  
  11789. See Also: memchr, memcmp, memcpy, memset 
  11790.  
  11791. Example: 
  11792.  
  11793.                     #include <stdio.h>
  11794.                     #include <string.h>
  11795.  
  11796.                     void main()
  11797.                       {
  11798.                         char buffer[80];
  11799.  
  11800.                         if( memicmp( buffer, "Hello", 5 ) < 0 ) {
  11801.                           printf( "Less than\n" );
  11802.                         }
  11803.                       }
  11804.  
  11805. Classification: WATCOM 
  11806.  
  11807.  
  11808. ΓòÉΓòÉΓòÉ 211. _memmax ΓòÉΓòÉΓòÉ
  11809.  
  11810. Synopsis: 
  11811.  
  11812.                     #include <malloc.h>
  11813.                     size_t _memmax( void );
  11814.  
  11815. Description: The _memmax function returns the size of the largest contiguous 
  11816.           block of memory available for dynamic memory allocation in the near 
  11817.           heap (the default data segment).  In the tiny, small and medium 
  11818.           memory models, the default data segment is only extended as needed to 
  11819.           satisfy requests for memory allocation.  Therefore, you will need to 
  11820.           call _nheapgrow in these memory models before calling _memmax in 
  11821.           order to get a meaningful result. 
  11822.  
  11823. Returns:  The _memmax function returns the size of the largest contiguous block 
  11824.           of memory available for dynamic memory allocation in the near heap. 
  11825.           If 0 is returned, then there is no more memory available in the near 
  11826.           heap. 
  11827.  
  11828. See Also: calloc, _freect, _memavl, _nheapgrow, _nmalloc 
  11829.  
  11830. Example: 
  11831.  
  11832.                     #include <stdio.h>
  11833.                     #include <malloc.h>
  11834.                     void main()
  11835.                       {
  11836.                         char *p;
  11837.                         size_t size;
  11838.                         size = _memmax();
  11839.                         printf( "Maximum memory available is %u\n", size );
  11840.                         _nheapgrow();
  11841.                         size = _memmax();
  11842.                         printf( "Maximum memory available is %u\n", size );
  11843.                         p = _nmalloc( size );
  11844.                         size = _memmax();
  11845.                         printf( "Maximum memory available is %u\n", size );
  11846.                       }
  11847.  
  11848.           produces the following: 
  11849.  
  11850.                     Maximum memory available is 0
  11851.                     Maximum memory available is 62700
  11852.                     Maximum memory available is 0
  11853.  
  11854. Classification: WATCOM 
  11855.  
  11856.  
  11857. ΓòÉΓòÉΓòÉ 212. memmove, _fmemmove ΓòÉΓòÉΓòÉ
  11858.  
  11859. Synopsis: 
  11860.  
  11861.                     #include <string.h>
  11862.                     void *memmove( void *dst,
  11863.                                    const void *src,
  11864.                                    size_t length );
  11865.                     void __far *_fmemmove( void __far *dst,
  11866.                                            const void __far *src,
  11867.                                            size_t length );
  11868.  
  11869. Description: The memmove and _fmemmove functions copy length characters from 
  11870.           the buffer pointed to by src to the buffer pointed to by dst. Copying 
  11871.           of overlapping objects will take place properly.  See the memcpy or 
  11872.           _fmemcpy functions to copy objects that do not overlap. 
  11873.  
  11874.           The _fmemmove function is a data model independent form of the 
  11875.           memmove function.  It accepts far pointer arguments and returns a far 
  11876.           pointer.  It is most useful in mixed memory model applications. 
  11877.  
  11878. Returns:  The memmove and _fmemmove functions return dst. 
  11879.  
  11880. See Also: memcpy, memset 
  11881.  
  11882. Example: 
  11883.  
  11884.                     #include <string.h>
  11885.  
  11886.                     void main()
  11887.                       {
  11888.                         char buffer[80];
  11889.  
  11890.                         memmove( buffer+1, buffer, 79 );
  11891.                         buffer[0] = '*';
  11892.                       }
  11893.  
  11894. Classification: memmove is ANSI, _fmemmove is not ANSI 
  11895.  
  11896.  
  11897. ΓòÉΓòÉΓòÉ 213. memset, _fmemset ΓòÉΓòÉΓòÉ
  11898.  
  11899. Synopsis: 
  11900.  
  11901.                     #include <string.h>
  11902.                     void *memset( void *s,
  11903.                                   int c,
  11904.                                   size_t length );
  11905.                     void __far *_fmemset( void __far *s,
  11906.                                           int c,
  11907.                                           size_t length );
  11908.  
  11909. Description: The memset and _fmemset functions fill the first length characters 
  11910.           of the object pointed to by s with the value c. 
  11911.  
  11912.           The _fmemset function is a data model independent form of the memset 
  11913.           function.  It accepts far pointer arguments and returns a far 
  11914.           pointer.  It is most useful in mixed memory model applications. 
  11915.  
  11916. Returns:  The memset and _fmemset functions return the pointer s. 
  11917.  
  11918. See Also: memchr, memcmp, memcpy, memmove 
  11919.  
  11920. Example: 
  11921.  
  11922.                     #include <string.h>
  11923.  
  11924.                     void main()
  11925.                       {
  11926.                         char buffer[80];
  11927.  
  11928.                         memset( buffer, '=', 80 );
  11929.                       }
  11930.  
  11931. Classification: memset is ANSI, _fmemset is not ANSI 
  11932.  
  11933.  
  11934. ΓòÉΓòÉΓòÉ 214. min ΓòÉΓòÉΓòÉ
  11935.  
  11936. Synopsis: 
  11937.  
  11938.                     #include <stdlib.h>
  11939.                     #define min(a,b)  (((a) < (b)) ? (a) : (b))
  11940.  
  11941. Description: The min macro will evaluate to be the lesser of two values.  It is 
  11942.           implemented as follows. 
  11943.  
  11944.                     #define min(a,b)  (((a) < (b)) ? (a) : (b))
  11945.  
  11946. Returns:  The min macro will evaluate to the smaller of the two values passed. 
  11947.  
  11948. See Also: max 
  11949.  
  11950. Example: 
  11951.  
  11952.                     #include <stdio.h>
  11953.                     #include <stdlib.h>
  11954.                     void main()
  11955.                       {
  11956.                         int a;
  11957.                         /*
  11958.                          * The following line will set the variable "a" to 1
  11959.                          * since 10 is greater than 1.
  11960.                          */
  11961.                         a = min( 1, 10 );
  11962.                         printf( "The value is: %d\n", a );
  11963.                       }
  11964.  
  11965. Classification: WATCOM 
  11966.  
  11967.  
  11968. ΓòÉΓòÉΓòÉ 215. mkdir ΓòÉΓòÉΓòÉ
  11969.  
  11970. Synopsis: 
  11971.  
  11972.                     #include <sys\types.h>
  11973.                     #include <direct.h>
  11974.                     int mkdir( const char *path );
  11975.  
  11976. Description: The mkdir function creates a new subdirectory with name path. The 
  11977.           path can be either relative to the current working directory or it 
  11978.           can be an absolute path name. 
  11979.  
  11980. Returns:  The mkdir function returns zero if successful, and a non-zero value 
  11981.           otherwise. 
  11982.  
  11983. Errors:   When an error has occurred, errno contains a value indicating the 
  11984.           type of error that has been detected. 
  11985.  
  11986.    Constant  Meaning 
  11987.  
  11988.    EACCES    Search permission is denied for a component of path or write 
  11989.              permission is denied on the parent directory of the directory to 
  11990.              be created. 
  11991.  
  11992.    ENOENT    The specified path does not exist or path is an empty string. 
  11993.  
  11994. See Also: chdir, chmod, getcwd, rmdir, stat, umask 
  11995.  
  11996. Example: 
  11997.  
  11998.           To make a new directory called \watcom on drive C: 
  11999.  
  12000.                     #include <sys\types.h>
  12001.                     #include <direct.h>
  12002.  
  12003.                     void main()
  12004.                       {
  12005.                         mkdir( "c:\\watcom" );
  12006.                       }
  12007.  
  12008.           Note the use of two adjacent backslash characters (\) within 
  12009.           character-string constants to signify a single backslash. 
  12010.  
  12011. Classification: POSIX 1003.1 
  12012.  
  12013.  
  12014. ΓòÉΓòÉΓòÉ 216. MK_FP ΓòÉΓòÉΓòÉ
  12015.  
  12016. Synopsis: 
  12017.  
  12018.                     #include <dos.h>
  12019.                     void __far *MK_FP( unsigned int segment,
  12020.                                        unsigned int offset );
  12021.  
  12022. Description: The MK_FP macro can be used to obtain the far pointer value given 
  12023.           by the segment segment value and the offset offset value.  These 
  12024.           values may be obtained by using the FP_SEG and FP_OFF macros. 
  12025.  
  12026. Returns:  The macro returns a far pointer. 
  12027.  
  12028. See Also: FP_OFF, FP_SEG, segread 
  12029.  
  12030. Example: 
  12031.  
  12032.                     #include <dos.h>
  12033.                     #include <stdio.h>
  12034.  
  12035.                     void main()
  12036.                       {
  12037.                         unsigned short __far *bios_prtr_port_1;
  12038.  
  12039.                         bios_prtr_port_1 = MK_FP( 0x40, 0x8 );
  12040.                         printf( "Port address is %x\n", *bios_prtr_port_1 );
  12041.                       }
  12042.  
  12043. Classification: Intel 
  12044.  
  12045.  
  12046. ΓòÉΓòÉΓòÉ 217. mktime ΓòÉΓòÉΓòÉ
  12047.  
  12048. Synopsis: 
  12049.  
  12050.                     #include <time.h>
  12051.                     time_t mktime( struct tm *timeptr );
  12052.  
  12053.                     struct tm {
  12054.                       int tm_sec;   /* seconds after the minute -- [0,61] */
  12055.                       int tm_min;   /* minutes after the hour -- [0,59] */
  12056.                       int tm_hour;  /* hours after midnight -- [0,23] */
  12057.                       int tm_mday;  /* day of the month -- [1,31] */
  12058.                       int tm_mon;   /* months since January -- [0,11] */
  12059.                       int tm_year;  /* years since 1900 */
  12060.                       int tm_wday;  /* days since Sunday -- [0,6] */
  12061.                       int tm_yday;  /* days since January 1 -- [0,365]*/
  12062.                       int tm_isdst; /* Daylight Savings Time flag */
  12063.                     };
  12064.  
  12065. Description: The mktime function converts the local time information in the 
  12066.           structure pointed to by timeptr into a calendar time (Coordinated 
  12067.           Universal Time) with the same encoding used by the time function. 
  12068.           The original values of the fields tm_sec, tm_min, tm_hour, tm_mday, 
  12069.           and tm_mon are not restricted to ranges described for struct tm. If 
  12070.           these fields are not in their proper ranges, they are adjusted so 
  12071.           that they are in the proper ranges.  Values for the fields tm_wday 
  12072.           and tm_yday are computed after all the other fields have been 
  12073.           adjusted. 
  12074.  
  12075.           If the original value of tm_isdst is negative, this field is computed 
  12076.           also.  Otherwise, a value of 0 is treated as "daylight savings time 
  12077.           is not in effect" and a positive value is treated as "daylight 
  12078.           savings time is in effect". 
  12079.  
  12080.           Whenever mktime is called, the tzset function is also called. 
  12081.  
  12082. Returns:  The mktime function returns the converted calendar time. 
  12083.  
  12084. See Also: asctime, clock, ctime, difftime, gmtime, localtime, strftime, time, 
  12085.           tzset 
  12086.  
  12087. Example: 
  12088.  
  12089.                     #include <stdio.h>
  12090.                     #include <time.h>
  12091.                     static const char *week_day[] = {
  12092.                         "Sunday", "Monday", "Tuesday", "Wednesday",
  12093.                         "Thursday", "Friday", "Saturday"
  12094.                     };
  12095.                     void main()
  12096.                       {
  12097.                         struct tm new_year;
  12098.                         new_year.tm_year  = 2001 - 1900;
  12099.                         new_year.tm_mon   = 0;
  12100.                         new_year.tm_mday  = 1;
  12101.                         new_year.tm_hour  = 0;
  12102.                         new_year.tm_min   = 0;
  12103.                         new_year.tm_sec   = 0;
  12104.                         new_year.tm_isdst = 0;
  12105.                         mktime( &new_year );
  12106.                         printf( "The next century begins on a %s\n",
  12107.                                  week_day[ new_year.tm_wday ] );
  12108.                       }
  12109.  
  12110.           produces the following: 
  12111.  
  12112.                     The next century begins on a Monday
  12113.  
  12114. Classification: ANSI 
  12115.  
  12116.  
  12117. ΓòÉΓòÉΓòÉ 218. modf ΓòÉΓòÉΓòÉ
  12118.  
  12119. Synopsis: 
  12120.  
  12121.                     #include <math.h>
  12122.                     double modf( double value, double *iptr );
  12123.  
  12124. Description: The modf function breaks the argument value into integral and 
  12125.           fractional parts, each of which has the same sign as the argument. 
  12126.           It stores the integral part as a double in the object pointed to by 
  12127.           iptr. 
  12128.  
  12129. Returns:  The modf function returns the signed fractional part of value. 
  12130.  
  12131. See Also: frexp, ldexp 
  12132.  
  12133. Example: 
  12134.  
  12135.                     #include <stdio.h>
  12136.                     #include <math.h>
  12137.  
  12138.                     void main()
  12139.                       {
  12140.                         double integral_value, fractional_part;
  12141.  
  12142.                         fractional_part = modf( 4.5, &integral_value );
  12143.                         printf( "%f %f\n", fractional_part, integral_value );
  12144.                         fractional_part = modf( -4.5, &integral_value );
  12145.                         printf( "%f %f\n", fractional_part, integral_value );
  12146.                       }
  12147.  
  12148.           produces the following: 
  12149.  
  12150.                     0.500000 4.000000
  12151.                     -0.500000 -4.000000
  12152.  
  12153. Classification: ANSI 
  12154.  
  12155.  
  12156. ΓòÉΓòÉΓòÉ 219. movedata ΓòÉΓòÉΓòÉ
  12157.  
  12158. Synopsis: 
  12159.  
  12160.                     #include <string.h>
  12161.                     void movedata( unsigned int src_segment,
  12162.                                    unsigned int src_offset,
  12163.                                    unsigned int tgt_segment,
  12164.                                    unsigned int tgt_offset,
  12165.                                    size_t length );
  12166.  
  12167. Description: The movedata function copies length bytes from the far pointer 
  12168.           calculated as (src_segment:src_offset) to a target location 
  12169.           determined as a far pointer (tgt_segment:tgt_offset). 
  12170.  
  12171.           Overlapping data may not be correctly copied.  When the source and 
  12172.           target areas may overlap, copy the areas one character at a time. 
  12173.  
  12174.           The function is useful to move data when the near address(es) of the 
  12175.           source and/or target areas are not known. 
  12176.  
  12177. Returns:  No value is returned. 
  12178.  
  12179. See Also: FP_SEG, FP_OFF, memcpy, segread 
  12180.  
  12181. Example: 
  12182.  
  12183.                     #include <stdio.h>
  12184.                     #include <string.h>
  12185.                     #include <dos.h>
  12186.  
  12187.                     void main()
  12188.                       {
  12189.                         char buffer[14] = {
  12190.                             '*', 0x17, 'H', 0x17, 'e', 0x17, 'l', 0x17,
  12191.                             'l', 0x17, 'o', 0x17, '*', 0x17 };
  12192.                         movedata( FP_SEG( buffer ),
  12193.                                   FP_OFF( buffer ),
  12194.                                   0xB800,
  12195.                                   0x0720,
  12196.                                   14 );
  12197.                       }
  12198.  
  12199. Classification: WATCOM 
  12200.  
  12201.  
  12202. ΓòÉΓòÉΓòÉ 220. _msize Functions ΓòÉΓòÉΓòÉ
  12203.  
  12204. Synopsis: 
  12205.  
  12206.                     #include <malloc.h>
  12207.                     size_t _msize( void *buffer );
  12208.                     size_t _bmsize( __segment seg, void __based(void) *buffer );
  12209.                     size_t _fmsize( void __far *buffer );
  12210.                     size_t _nmsize( void __near *buffer );
  12211.  
  12212. Description: The _msize functions return the size of the memory block pointed 
  12213.           to by buffer that was allocated by a call to the appropriate version 
  12214.           of the calloc, malloc, or realloc functions. 
  12215.  
  12216.           You must use the correct _msize function as listed below depending on 
  12217.           which heap the memory block belongs to. 
  12218.  
  12219.    Function      Heap 
  12220.    _msize        Depends on data model of the program 
  12221.    _bmsize       Based heap specified by seg value 
  12222.    _fmsize       Far heap (outside the default data segment) 
  12223.    _nmsize       Near heap (inside the default data segment) 
  12224.  
  12225.           In small data models (small and medium memory models), _msize maps to 
  12226.           _nmsize. In large data models (compact, large and huge memory 
  12227.           models), _msize maps to _fmsize. 
  12228.  
  12229. Returns:  The _msize functions return the size of the memory block pointed to 
  12230.           by buffer. 
  12231.  
  12232. See Also: calloc Functions, _expand Functions, free Functions, halloc, hfree, 
  12233.           malloc Functions, realloc Functions, sbrk 
  12234.  
  12235. Example: 
  12236.  
  12237.                     #include <stdio.h>
  12238.                     #include <malloc.h>
  12239.  
  12240.                     void main()
  12241.                       {
  12242.                         void *buffer;
  12243.  
  12244.                         buffer = malloc( 999 );
  12245.                         printf( "Size of block is %u bytes\n",
  12246.                                     _msize( buffer ) );
  12247.                       }
  12248.  
  12249.           produces the following: 
  12250.  
  12251.                     Size of block is 1000 bytes
  12252.  
  12253. Classification: WATCOM 
  12254.  
  12255.  
  12256. ΓòÉΓòÉΓòÉ 221. nosound ΓòÉΓòÉΓòÉ
  12257.  
  12258. Synopsis: 
  12259.  
  12260.                     #include <dos.h>
  12261.                     void nosound( void );
  12262.  
  12263. Description: The nosound function turns off the PC's speaker. 
  12264.  
  12265. Returns:  The nosound function has no return value. 
  12266.  
  12267. See Also: delay, sound 
  12268.  
  12269. Example: 
  12270.  
  12271.                     #include <dos.h>
  12272.  
  12273.                     void main()
  12274.                       {
  12275.                         sound( 200 );
  12276.                         delay( 500 );  /* delay for 1/2 second */
  12277.                         nosound();
  12278.                       }
  12279.  
  12280. Classification: Intel 
  12281.  
  12282.  
  12283. ΓòÉΓòÉΓòÉ 222. offsetof ΓòÉΓòÉΓòÉ
  12284.  
  12285. Synopsis: 
  12286.  
  12287.                     #include <stddef.h>
  12288.                     size_t offsetof( composite, name );
  12289.  
  12290. Description: The offsetof macro returns the offset of the element name within 
  12291.           the struct or union composite. This provides a portable method to 
  12292.           determine the offset.  The macro may not be used to initialize data; 
  12293.           it can only be used with executable statements. 
  12294.  
  12295. Returns:  The offsetof function returns the offset of name. 
  12296.  
  12297. Example: 
  12298.  
  12299.                     #include <stdio.h>
  12300.                     #include <stddef.h>
  12301.  
  12302.                     struct new_def
  12303.                     {  char *first;
  12304.                        char second[10];
  12305.                        int third;
  12306.                     };
  12307.  
  12308.                     void main()
  12309.                       {
  12310.                         printf( "first:%d second:%d third:%d\n",
  12311.                             offsetof( struct new_def, first ),
  12312.                             offsetof( struct new_def, second ),
  12313.                             offsetof( struct new_def, third ) );
  12314.                       }
  12315.  
  12316.           produces the following: 
  12317.  
  12318.           In a small data model, the following would result: 
  12319.  
  12320.                     first:0 second:2 third:12
  12321.  
  12322.           In a large data model, the following would result: 
  12323.  
  12324.                     first:0 second:4 third:14
  12325.  
  12326.  
  12327. Classification: ANSI 
  12328.  
  12329.  
  12330. ΓòÉΓòÉΓòÉ 223. onexit ΓòÉΓòÉΓòÉ
  12331.  
  12332. Synopsis: 
  12333.  
  12334.                     #include <stdlib.h>
  12335.                     onexit_t onexit( onexit_t func )
  12336.  
  12337. Description: The onexit function is passed the address of function func to be 
  12338.           called when the program terminates normally.  Successive calls to 
  12339.           onexit create a list of functions that will be executed on a 
  12340.           "last-in, first-out" basis.  No more than 32 functions can be 
  12341.           registered with the onexit function. 
  12342.  
  12343.           The functions have no parameters and do not return values. 
  12344.  
  12345.           NOTE:  The onexit function is not an ANSI function.  The ANSI 
  12346.           standard function atexit does the same thing that onexit does and 
  12347.           should be used instead of onexit where ANSI portability is concerned. 
  12348.  
  12349. Returns:  The onexit function returns func if the registration succeeds, NULL 
  12350.           if it fails. 
  12351.  
  12352. See Also: abort, atexit, exit, _exit 
  12353.  
  12354. Example: 
  12355.  
  12356.                     #include <stdio.h>
  12357.                     #include <stdlib.h>
  12358.                     void main()
  12359.                       {
  12360.                         void func1(void), func2(void), func3(void);
  12361.                         onexit( func1 );
  12362.                         onexit( func2 );
  12363.                         onexit( func3 );
  12364.                         printf( "Do this first.\n" );
  12365.                       }
  12366.                     void func1(void) { printf( "last.\n" ); }
  12367.                     void func2(void) { printf( "this " ); }
  12368.                     void func3(void) { printf( "Do " ); }
  12369.  
  12370.           produces the following: 
  12371.  
  12372.                     Do this first.
  12373.                     Do this last.
  12374.  
  12375. Classification: WATCOM 
  12376.  
  12377.  
  12378. ΓòÉΓòÉΓòÉ 224. open ΓòÉΓòÉΓòÉ
  12379.  
  12380. Synopsis: 
  12381.  
  12382.                     #include <sys\types.h>
  12383.                     #include <sys\stat.h>
  12384.                     #include <fcntl.h>
  12385.                     int open( const char *path, int access, ... );
  12386.  
  12387. Description: The open function opens a file at the operating system level.  The 
  12388.           name of the file to be opened is given by path. The file will be 
  12389.           accessed according to the access mode specified by access. The 
  12390.           optional argument is the file permissions to be used when the O_CREAT 
  12391.           flag is on in the access mode. 
  12392.  
  12393.           The access mode is established a combination of the bits defined in 
  12394.           the <fcntl.h> header file.  The following bits may be set: 
  12395.  
  12396.    Mode          Meaning 
  12397.  
  12398.    O_RDONLY      permit the file to be only read. 
  12399.  
  12400.    O_WRONLY      permit the file to be only written. 
  12401.  
  12402.    O_RDWR        permit the file to be both read and written. 
  12403.  
  12404.    O_APPEND      causes each record that is written to be written at the end of 
  12405.                  the file. 
  12406.  
  12407.    O_CREAT       has no effect when the file indicated by filename already 
  12408.                  exists; otherwise, the file is created; 
  12409.  
  12410.    O_TRUNC       causes the file to be truncated to contain no data when the 
  12411.                  file exists; has no effect when the file does not exist. 
  12412.  
  12413.    O_BINARY      causes the file to be opened in binary mode which means that 
  12414.                  data will be transmitted to and from the file unchanged. 
  12415.  
  12416.    O_TEXT        causes the file to be opened in text mode which means that 
  12417.                  carriage-return characters are written before any linefeed 
  12418.                  character that is written and causes carriage-return 
  12419.                  characters to be removed when encountered during reads. 
  12420.  
  12421.           When neither O_TEXT nor O_BINARY are specified, the default value in 
  12422.           the global variable _fmode is used to set the file translation mode. 
  12423.           When the program begins execution, this variable has a value of 
  12424.           O_TEXT. 
  12425.  
  12426.           O_CREAT must be specified when the file does not exist and it is to 
  12427.           be written. 
  12428.  
  12429.           When the file is to be created (O_CREAT is specified), an additional 
  12430.           argument must be passed which contains the file permissions to be 
  12431.           used for the new file.  The access permissions for the file or 
  12432.           directory are specified as a combination of bits (defined in the 
  12433.           <sys\stat.h> header file). 
  12434.  
  12435.           The following bits define permissions for the owner. 
  12436.  
  12437.    Permission    Meaning 
  12438.    S_IRWXU       Read, write, execute/search 
  12439.    S_IRUSR       Read permission 
  12440.    S_IWUSR       Write permission 
  12441.    S_IXUSR       Execute/search permission 
  12442.  
  12443.           The following bits define permissions for the group. 
  12444.  
  12445.    Permission    Meaning 
  12446.    S_IRWXG       Read, write, execute/search 
  12447.    S_IRGRP       Read permission 
  12448.    S_IWGRP       Write permission 
  12449.    S_IXGRP       Execute/search permission 
  12450.  
  12451.           The following bits define permissions for others. 
  12452.  
  12453.    Permission    Meaning 
  12454.    S_IRWXO       Read, write, execute/search 
  12455.    S_IROTH       Read permission 
  12456.    S_IWOTH       Write permission 
  12457.    S_IXOTH       Execute/search permission 
  12458.  
  12459.           The following bits define miscellaneous permissions used by other 
  12460.           implementations. 
  12461.  
  12462.    Permission    Meaning 
  12463.    S_IREAD       is equivalent to S_IRUSR (read permission) 
  12464.    S_IWRITE      is equivalent to S_IWUSR (write permission) 
  12465.    S_IEXEC       is equivalent to S_IXUSR (execute/search permission) 
  12466.  
  12467.           All files are readable with DOS; however, it is a good idea to set 
  12468.           S_IREAD when read permission is intended for the file. 
  12469.  
  12470.           The open function applies the current file permission mask to the 
  12471.           specified permissions (see umask). 
  12472.  
  12473. Returns:  If successful, open returns a handle for the file.  When an error 
  12474.           occurs while opening the file, -1 is returned. 
  12475.  
  12476. Errors:   When an error has occurred, errno contains a value indicating the 
  12477.           type of error that has been detected. 
  12478.  
  12479.    Constant  Meaning 
  12480.  
  12481.    EACCES    Access denied because path specifies a directory or a volume ID, 
  12482.              or attempting to open a read-only file for writing 
  12483.  
  12484.    EMFILE    No more handles available, (too many open files) 
  12485.  
  12486.    ENOENT    Path or file not found 
  12487.  
  12488. See Also: close, creat, dup, dup2, eof, exec Functions, filelength, fileno, 
  12489.           fstat, isatty, lseek, read, setmode, sopen, stat, tell, write, umask 
  12490.  
  12491. Example: 
  12492.  
  12493.                     #include <sys\stat.h>
  12494.                     #include <sys\types.h>
  12495.                     #include <fcntl.h>
  12496.  
  12497.                     void main()
  12498.                       {
  12499.                         int handle;
  12500.  
  12501.                         /* open a file for output                  */
  12502.                         /* replace existing file if it exists      */
  12503.  
  12504.                         handle = open( "file",
  12505.                                     O_WRONLY | O_CREAT | O_TRUNC,
  12506.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  12507.  
  12508.                         /* read a file which is assumed to exist   */
  12509.  
  12510.                         handle = open( "file", O_RDONLY );
  12511.  
  12512.                         /* append to the end of an existing file   */
  12513.                         /* write a new file if file does not exist */
  12514.  
  12515.                         handle = open( "file",
  12516.                                     O_WRONLY | O_CREAT | O_APPEND,
  12517.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  12518.                       }
  12519.  
  12520. Classification: POSIX 1003.1 
  12521.  
  12522.  
  12523. ΓòÉΓòÉΓòÉ 225. opendir ΓòÉΓòÉΓòÉ
  12524.  
  12525. Synopsis: 
  12526.  
  12527.                     #include <direct.h>
  12528.                     DIR *opendir( const char *dirname );
  12529.  
  12530. Description: The opendir function is used in conjunction with the functions 
  12531.           readdir and closedir to obtain the list of file names contained in 
  12532.           the directory specified by dirname. The path indicated by dirname can 
  12533.           be either relative to the current working directory or it can be an 
  12534.           absolute path name.  As an extension to POSIX, the last part of 
  12535.           dirname can contain the characters '?' and '*' for matching multiple 
  12536.           files within a directory. 
  12537.  
  12538.           The file <direct.h> contains definitions for the structure dirent. 
  12539.  
  12540.                     typedef struct dirent {
  12541.                         char    d_dta[ 21 ];       /* disk transfer area */
  12542.                         char    d_attr;            /* file's attribute */
  12543.                         unsigned short int d_time; /* file's time */
  12544.                         unsigned short int d_date; /* file's date */
  12545.                         long    d_size;            /* file's size */
  12546.                         char    d_name[ 13 ];      /* file's name */
  12547.                         ino_t   d_ino;             /* serial number */
  12548.                         char    d_first;           /* flag for 1st time */
  12549.                     } DIR;
  12550.  
  12551.           More than one directory can be read at the same time using the 
  12552.           opendir, readdir, and closedir functions. 
  12553.  
  12554. Returns:  The opendir function, if successful, returns a pointer to a structure 
  12555.           required for subsequent calls to readdir to retrieve the file names 
  12556.           matching the pattern specified by dirname. The opendir function 
  12557.           returns NULL if dirname is not a valid pathname, or if there are no 
  12558.           files matching dirname. 
  12559.  
  12560. Errors:   When an error has occurred, errno contains a value indicating the 
  12561.           type of error that has been detected. 
  12562.  
  12563.    Constant  Meaning 
  12564.  
  12565.    EACCES    Search permission is denied for a component of dirname or read 
  12566.              permission is denied for dirname. 
  12567.  
  12568.    ENOENT    The named directory does not exist. 
  12569.  
  12570. See Also: closedir, readdir 
  12571.  
  12572. Example: 
  12573.  
  12574.           To get a list of files contained in the directory \watcom\h on your 
  12575.           default disk: 
  12576.  
  12577.                     #include <stdio.h>
  12578.                     #include <direct.h>
  12579.                     void main()
  12580.                       {
  12581.                         DIR *dirp;
  12582.                         struct dirent *direntp;
  12583.  
  12584.                         dirp = opendir( "\\watcom\\h" );
  12585.                         if( dirp == NULL ) {
  12586.                           perror( "" );
  12587.                         } else {
  12588.                           for(;;) {
  12589.                             direntp = readdir( dirp );
  12590.                             if( direntp == NULL ) break;
  12591.                             printf( "%s\n", direntp->d_name );
  12592.                           }
  12593.                           closedir( dirp );
  12594.                         }
  12595.                       }
  12596.  
  12597.           Note the use of two adjacent backslash characters (\) within 
  12598.           character-string constants to signify a single backslash. 
  12599.  
  12600. Classification: POSIX 1003.1 
  12601.  
  12602.  
  12603. ΓòÉΓòÉΓòÉ 226. outp ΓòÉΓòÉΓòÉ
  12604.  
  12605. Synopsis: 
  12606.  
  12607.                     #include <conio.h>
  12608.                     unsigned int outp( int port, int value );
  12609.  
  12610. Description: The outp function writes one byte, determined by value, to the 
  12611.           80x86 hardware port whose number is given by port. 
  12612.  
  12613.           A hardware port is used to communicate with a device.  One or two 
  12614.           bytes can be read and/or written from each port, depending upon the 
  12615.           hardware.  Consult the technical documentation for your computer to 
  12616.           determine the port numbers for a device and the expected usage of 
  12617.           each port for a device. 
  12618.  
  12619. Returns:  The value transmitted is returned. 
  12620.  
  12621. See Also: inp, inpw, outpw 
  12622.  
  12623. Example: 
  12624.  
  12625.                     #include <conio.h>
  12626.  
  12627.                     void main()
  12628.                       {
  12629.                         /* turn off speaker */
  12630.                         outp( 0x61, inp( 0x61 ) & 0xFC );
  12631.                       }
  12632.  
  12633. Classification: Intel 
  12634.  
  12635.  
  12636. ΓòÉΓòÉΓòÉ 227. outpw ΓòÉΓòÉΓòÉ
  12637.  
  12638. Synopsis: 
  12639.  
  12640.                     #include <conio.h>
  12641.                     unsigned int outpw( int port,
  12642.                                         unsigned int value );
  12643.  
  12644. Description: The outpw function writes a word (two bytes), determined by value, 
  12645.           to the 80x86 hardware port whose number is given by port. 
  12646.  
  12647.           A hardware port is used to communicate with a device.  One or two 
  12648.           bytes can be read and/or written from each port, depending upon the 
  12649.           hardware.  Consult the technical documentation for your computer to 
  12650.           determine the port numbers for a device and the expected usage of 
  12651.           each port for a device. 
  12652.  
  12653. Returns:  The value transmitted is returned. 
  12654.  
  12655. See Also: inp, inpw, outp 
  12656.  
  12657. Example: 
  12658.  
  12659.                     #include <conio.h>
  12660.                     #define DEVICE 34
  12661.  
  12662.                     void main()
  12663.                       {
  12664.                         outpw( DEVICE, 0x1234 );
  12665.                       }
  12666.  
  12667. Classification: Intel 
  12668.  
  12669.  
  12670. ΓòÉΓòÉΓòÉ 228. perror ΓòÉΓòÉΓòÉ
  12671.  
  12672. Synopsis: 
  12673.  
  12674.                     #include <stdio.h>
  12675.                     void perror( const char *prefix );
  12676.  
  12677. Description: The perror function prints, on the file designated by stderr, the 
  12678.           error message corresponding to the error number contained in errno. 
  12679.           The perror function is implemented as follows: 
  12680.  
  12681.                     #include <stdio.h>
  12682.                     void perror( const char *prefix )
  12683.                     {
  12684.                         if( prefix != NULL ) {
  12685.                             if( *prefix != '\0' ) {
  12686.                                 fprintf( stderr, "%s: ", prefix );
  12687.                             }
  12688.                         }
  12689.                         fprintf( stderr, "%s\n", strerror( errno ) );
  12690.                     }
  12691.  
  12692. Returns:  The perror function returns no value.  Because the function uses the 
  12693.           fprintf function, the errno can be set when an error is detected 
  12694.           during the execution of that function. 
  12695.  
  12696. See Also: strerror 
  12697.  
  12698. Example: 
  12699.  
  12700.                     #include <stdio.h>
  12701.  
  12702.                     void main()
  12703.                       {
  12704.                         FILE *fp;
  12705.  
  12706.                         fp = fopen( "data.fil", "r" );
  12707.                         if( fp == NULL ) {
  12708.                             perror( "Unable to open file" );
  12709.                         }
  12710.                       }
  12711.  
  12712. Classification: ANSI 
  12713.  
  12714.  
  12715. ΓòÉΓòÉΓòÉ 229. pow ΓòÉΓòÉΓòÉ
  12716.  
  12717. Synopsis: 
  12718.  
  12719.                     #include <math.h>
  12720.                     double pow( double x, double y );
  12721.  
  12722. Description: The pow function computes x raised to the power y. A domain error 
  12723.           occurs if x is zero and y is less than or equal to 0, or if x is 
  12724.           negative and y is not an integer.  A range error may occur. 
  12725.  
  12726. Returns:  The pow function returns the value of x raised to the power y. When 
  12727.           the argument is outside the permissible range, the matherr function 
  12728.           is called.  Unless the default matherr function is replaced, it will 
  12729.           set the global variable errno to EDOM, and print a "DOMAIN error" 
  12730.           diagnostic message using the stderr stream. 
  12731.  
  12732. See Also: exp, log, sqrt 
  12733.  
  12734. Example: 
  12735.  
  12736.                     #include <stdio.h>
  12737.                     #include <math.h>
  12738.  
  12739.                     void main()
  12740.                       {
  12741.                         printf( "%f\n", pow( 1.5, 2.5 ) );
  12742.                       }
  12743.  
  12744.           produces the following: 
  12745.  
  12746.                     2.755676
  12747.  
  12748. Classification: ANSI 
  12749.  
  12750.  
  12751. ΓòÉΓòÉΓòÉ 230. printf ΓòÉΓòÉΓòÉ
  12752.  
  12753. Synopsis: 
  12754.  
  12755.                     #include <stdio.h>
  12756.                     int printf( const char *format, ... );
  12757.  
  12758. Description: The printf function writes output to the file designated by stdout 
  12759.           under control of the argument format. The format string is described 
  12760.           below. 
  12761.  
  12762. Returns:  The printf function returns the number of characters written, or a 
  12763.           negative value if an output error occurred.  When an error has 
  12764.           occurred, errno contains a value indicating the type of error that 
  12765.           has been detected. 
  12766.  
  12767. See Also: cprintf, fprintf, sprintf, vfprintf, vprintf, vsprintf 
  12768.  
  12769. Example: 
  12770.  
  12771.                     #include <stdio.h>
  12772.  
  12773.                     void main()
  12774.                       {
  12775.                         char *weekday, *month;
  12776.  
  12777.                         weekday = "Saturday";
  12778.                         month = "April";
  12779.                         printf( "%s, %s %d, %d\n",
  12780.                               weekday, month, 18, 1987 );
  12781.                         printf( "f1 = %8.4f f2 = %10.2E x = %#08x i = %d\n",
  12782.                                 23.45,      3141.5926,   0x1db,     -1 );
  12783.                       }
  12784.  
  12785.           produces the following: 
  12786.  
  12787.                     Saturday, April 18, 1987
  12788.                     f1 =  23.4500 f2 =  3.14E+003 x = 0x0001db i = -1
  12789.  
  12790. Format Control String: The format control string consists of ordinary 
  12791.           characters, that are written exactly as they occur in the format 
  12792.           string, and conversion specifiers,  that cause argument values to be 
  12793.           written as they are encountered during the processing of the format 
  12794.           string.  An ordinary character in the format string is any character, 
  12795.           other than a percent character (%), that is not part of a conversion 
  12796.           specifier.  A conversion specifier is a sequence of characters in the 
  12797.           format string that begins with a percent character (%) and is 
  12798.           followed, in sequence, by the following: 
  12799.  
  12800.    o zero or more format control flags  that can modify the final effect of the 
  12801.      format directive 
  12802.  
  12803.    o an optional decimal integer, or an asterisk character ('*'), that 
  12804.      specifies a minimum field width  to be reserved for the formatted item 
  12805.  
  12806.    o an optional precision  specification in the form of a period character 
  12807.      (.), followed by an optional decimal integer or an asterisk character (*) 
  12808.  
  12809.    o an optional type length  specification:  one of "h", "l", "L", "N" or "F" 
  12810.  
  12811.    o a character that specifies the type of conversion to be performed: one of 
  12812.      the characters "cdeEfFgGinopsuxX". 
  12813.  
  12814.           The valid format control flags are: 
  12815.  
  12816.    "-"       the formatted item is left-justified within the field; normally, 
  12817.              items are right-justified 
  12818.  
  12819.    "+"       a signed, positive object will always start with a plus character 
  12820.              (+); normally, only negative items begin with a sign 
  12821.  
  12822.    " "       a signed, positive object will always start with a space 
  12823.              character; if both "+" and "-" are specified, "+" overrides "-" 
  12824.  
  12825.    "#"       an alternate conversion form is used: 
  12826.  
  12827.       o for "o" (unsigned octal) conversions, the precision is incremented, if 
  12828.         necessary, so that the first digit is "0". 
  12829.  
  12830.       o for "x" or "X" (unsigned hexadecimal) conversions, a non-zero value is 
  12831.         prepended with "0x" or "0X" respectively 
  12832.  
  12833.       o for "e", "E", "f", "g" or "G" (any floating point) conversions, the 
  12834.         result always contains a decimal-point character, even if no digits 
  12835.         follow it; normally, a decimal-point character appears in the result 
  12836.         only if there is a digit to follow it 
  12837.  
  12838.       o in addition to the preceding, for "g" or "G" conversions, trailing 
  12839.         zeros are not removed from the result 
  12840.  
  12841.           If no field width is specified, or if the value that is given is less 
  12842.           than the number of characters in the converted value (subject to any 
  12843.           precision value), a field of sufficient width to contain the 
  12844.           converted value is used. If the converted value has fewer characters 
  12845.           than are specified by the field width, the value is padded on the 
  12846.           left (or right, subject to the left-justification flag) with spaces 
  12847.           or zero characters ("0").  If the field width begins with a zero, the 
  12848.           value is padded with zeros, otherwise the value is padded with 
  12849.           spaces.  If the field width is "*", a value of type int from the 
  12850.           argument list is used (before a precision argument or a conversion 
  12851.           argument) as the minimum field width.  A negative field width value 
  12852.           is interpreted as a left-justification flag, followed by a positive 
  12853.           field width. 
  12854.  
  12855.           As with the field width specifier, a precision specifier of "*" 
  12856.           causes a value of type int from the argument list to be used as the 
  12857.           precision specifier.  If no precision value is given, a precision of 
  12858.           0 is used.  The precision value affects the following conversions: 
  12859.  
  12860.    o for "d", "i", "o", "u", "x" and "X" (integer) conversions, the precision 
  12861.      specifies the minimum number of digits to appear 
  12862.  
  12863.    o for "e", "E" and "f" (fixed-precision, floating-point) conversions, the 
  12864.      precision specifies the number of digits to appear after the decimal-point 
  12865.      character 
  12866.  
  12867.    o for "g" and "G" (variable-precision, floating-point) conversions, the 
  12868.      precision specifies the maximum number of significant digits to appear 
  12869.  
  12870.    o for "s" (string) conversions, the precision specifies the maximum number 
  12871.      of characters to appear 
  12872.  
  12873.           A type length specifier affects the conversion as follows: 
  12874.  
  12875.    o "h" causes a "d", "i", "o", "u", "x" or "X" (integer) conversion to 
  12876.      process a short int or unsigned short int argument; note that although the 
  12877.      argument may have been promoted as part of the function call, the value is 
  12878.      converted to the smaller type before it is converted 
  12879.  
  12880.    o "h" causes an "f" format conversion to interpret a long argument as a 
  12881.      fixed-point number.  The value is formatted with the same rules as for 
  12882.      floating-point values.  This is a WATCOM extension. 
  12883.  
  12884.    o "h" causes an "n" (converted length assignment) operation to assign the 
  12885.      converted length to an object of type unsigned short int 
  12886.  
  12887.    o "l" causes a "d", "i", "o", "u", "x" or "X" (integer) conversion to 
  12888.      process a long int or unsigned long int argument; 
  12889.  
  12890.    o "l" causes an "n" (converted length assignment) operation to assign the 
  12891.      converted length to an object of type unsigned long int 
  12892.  
  12893.    o "F" causes the pointer associated with "n", "p", "s" conversions to be 
  12894.      treated as a far pointer; 
  12895.  
  12896.    o "L" causes an "e", "E", "f", "g", "G" (double) conversion to process a 
  12897.      long double argument; 
  12898.  
  12899.    o "N" causes the pointer associated with "n", "p", "s" conversions to be 
  12900.      treated as a near pointer; 
  12901.  
  12902.           The valid conversion type specifiers are: 
  12903.  
  12904.    c         An argument of type int is converted to a value of type char and 
  12905.              the corresponding ASCII character code is written to the output 
  12906.              stream. 
  12907.  
  12908.    d, i      An argument of type int is converted to a signed decimal notation 
  12909.              and written to the output stream. The default precision is 1, but 
  12910.              if more digits are required, leading zeros are added. 
  12911.  
  12912.    e, E      An argument of type double is converted to a decimal notation in 
  12913.              the form [-]d.ddde[+|-]ddd similar to FORTRAN exponential (E) 
  12914.              notation.  The leading sign appears (subject to the format control 
  12915.              flags) only if the argument is negative.  If the argument is 
  12916.              non-zero, the digit before the decimal-point character is 
  12917.              non-zero.  The precision is used as the number of digits following 
  12918.              the decimal-point character.  If the precision is not specified, a 
  12919.              default precision of six is used.  If the precision is 0, the 
  12920.              decimal-point character is suppressed.  The value is rounded to 
  12921.              the appropriate number of digits.  For "E" conversions, the 
  12922.              exponent begins with the character "E" rather than "e".  The 
  12923.              exponent sign and a three-digit number (that indicates the power 
  12924.              of ten by which the decimal fraction is multiplied) are always 
  12925.              produced. 
  12926.  
  12927.    f         An argument of type double is converted to a decimal notation in 
  12928.              the form [-]ddd.ddd similar to FORTRAN fixed-point (F) notation. 
  12929.              The leading sign appears (subject to the format control flags) 
  12930.              only if the argument is negative.  The precision is used as the 
  12931.              number of digits following the decimal-point character.  If the 
  12932.              precision is not specified, a default precision of six is used. 
  12933.              If the precision is 0, the decimal-point character is suppressed, 
  12934.              otherwise, at least one digit is produced before the decimal-point 
  12935.              character.  The value is rounded to the appropriate number of 
  12936.              digits. 
  12937.  
  12938.    g, G      An argument of type double is converted using either the "f" or 
  12939.              "e" (or "E", for a "G" conversion) style of conversion depending 
  12940.              on the value of the argument.  In either case, the precision 
  12941.              specifies the number of significant digits that are contained in 
  12942.              the result.  "e" style conversion is used only if the exponent 
  12943.              from such a conversion would be less than -4 or greater than the 
  12944.              precision.  Trailing zeros are removed from the result and a 
  12945.              decimal-point character only appears if it is followed by a digit. 
  12946.  
  12947.    n         The number of characters that have been written to the output 
  12948.              stream is assigned to the integer pointed to by the argument.  No 
  12949.              output is produced. 
  12950.  
  12951.    o         An argument of type int is converted to an unsigned octal notation 
  12952.              and written to the output stream. The default precision is 1, but 
  12953.              if more digits are required, leading zeros are added. 
  12954.  
  12955.    p, P      An argument of type void * is converted to a value of type int and 
  12956.              the value is formatted as for a hexadecimal ("x") conversion. 
  12957.  
  12958.    s         Characters from the string specified by an argument of type char 
  12959.              *, up to, but not including the terminating null character ("\0"), 
  12960.              are written to the output stream.  If a precision is specified, no 
  12961.              more than that many characters are written. 
  12962.  
  12963.    u         An argument of type int is converted to an unsigned decimal 
  12964.              notation and written to the output stream.  The default precision 
  12965.              is 1, but if more digits are required, leading zeros are added. 
  12966.  
  12967.    x, X      An argument of type int is converted to an unsigned hexadecimal 
  12968.              notation and written to the output stream.  The default precision 
  12969.              is 1, but if more digits are required, leading zeros are added. 
  12970.              Hexadecimal notation uses the digits "0" through "9" and the 
  12971.              characters "a" through "f" or "A" through "F" for "x" or "X" 
  12972.              conversions respectively, as the hexadecimal digits.  Subject to 
  12973.              the alternate-form control flag, "0x" or "0X" is prepended to the 
  12974.              output. 
  12975.  
  12976.           Any other conversion type specifier character, including another 
  12977.           percent character (%), is written to the output stream with no 
  12978.           special interpretation. 
  12979.  
  12980.           The arguments must correspond with the conversion type specifiers, 
  12981.           left to right in the string; otherwise, indeterminate results will 
  12982.           occur. 
  12983.  
  12984.           If the value corresponding to a floating-point specifier is infinity, 
  12985.           or not a number (NAN), then the output will be "inf" or "-inf" for 
  12986.           infinity, and "nan" or "-nan" for NAN's. 
  12987.  
  12988.           For example, a specifier of the form "%8.*f" will define a field to 
  12989.           be at least 8 characters wide, and will get the next argument for the 
  12990.           precision to be used in the conversion. 
  12991.  
  12992. Classification: ANSI, (except for "F" and "N" modifiers) 
  12993.  
  12994.  
  12995. ΓòÉΓòÉΓòÉ 231. putc ΓòÉΓòÉΓòÉ
  12996.  
  12997. Synopsis: 
  12998.  
  12999.                     #include <stdio.h>
  13000.                     int putc( int c, FILE *fp );
  13001.  
  13002. Description: The putc function is equivalent to fputc, except it may be 
  13003.           implemented as a macro.  The putc function writes the character 
  13004.           specified by the argument c to the output stream designated by fp. 
  13005.  
  13006. Returns:  The putc function returns the character written.  If a write error 
  13007.           occurs, the error indicator is set and putc returns EOF. When an 
  13008.           error has occurred, errno contains a value indicating the type of 
  13009.           error that has been detected. 
  13010.  
  13011. See Also: fopen, fputc, fputchar, fputs, putchar, puts, ferror 
  13012.  
  13013. Example: 
  13014.  
  13015.                     #include <stdio.h>
  13016.  
  13017.                     void main()
  13018.                       {
  13019.                         FILE *fp;
  13020.                         int c;
  13021.  
  13022.                         fp = fopen( "file", "r" );
  13023.                         if( fp != NULL ) {
  13024.                           while( (c = fgetc( fp )) != EOF )
  13025.                               putc( c, stdout );
  13026.                           fclose( fp );
  13027.                         }
  13028.                       }
  13029.  
  13030. Classification: ANSI 
  13031.  
  13032.  
  13033. ΓòÉΓòÉΓòÉ 232. putch ΓòÉΓòÉΓòÉ
  13034.  
  13035. Synopsis: 
  13036.  
  13037.                     #include <conio.h>
  13038.                     int putch( int c );
  13039.  
  13040. Description: The putch function writes the character specified by the argument 
  13041.           c to the console. 
  13042.  
  13043. Returns:  The putch function returns the character written. 
  13044.  
  13045. See Also: getch, getche, kbhit, ungetch 
  13046.  
  13047. Example: 
  13048.  
  13049.                     #include <conio.h>
  13050.                     #include <stdio.h>
  13051.  
  13052.                     void main()
  13053.                       {
  13054.                         FILE *fp;
  13055.                         int c;
  13056.  
  13057.                         fp = fopen( "file", "r" );
  13058.                         if ( fp != NULL ) {
  13059.                           while( (c = fgetc( fp )) != EOF )
  13060.                             putch( c );
  13061.                         }
  13062.                         fclose( fp );
  13063.                       }
  13064.  
  13065. Classification: WATCOM 
  13066.  
  13067.  
  13068. ΓòÉΓòÉΓòÉ 233. putchar ΓòÉΓòÉΓòÉ
  13069.  
  13070. Synopsis: 
  13071.  
  13072.                     #include <stdio.h>
  13073.                     int putchar( int c );
  13074.  
  13075. Description: The putchar function writes the character specified by the 
  13076.           argument c to the output stream stdout. 
  13077.  
  13078.           The function is equivalent to 
  13079.  
  13080.                     fputc( c, stdout );
  13081.  
  13082. Returns:  The putchar function returns the character written.  If a write error 
  13083.           occurs, the error indicator is set and putchar returns EOF. When an 
  13084.           error has occurred, errno contains a value indicating the type of 
  13085.           error that has been detected. 
  13086.  
  13087. See Also: fputc, fputchar, fputs, putc 
  13088.  
  13089. Example: 
  13090.  
  13091.                     #include <stdio.h>
  13092.  
  13093.                     void main()
  13094.                       {
  13095.                         FILE *fp;
  13096.                         int c;
  13097.  
  13098.                         fp = fopen( "data.fil", "r" );
  13099.                         c = fgetc( fp );
  13100.                         while( c != EOF ) {
  13101.                             putchar( c );
  13102.                             c = fgetc( fp );
  13103.                         }
  13104.                         fclose( fp );
  13105.                       }
  13106.  
  13107. Classification: ANSI 
  13108.  
  13109.  
  13110. ΓòÉΓòÉΓòÉ 234. putenv ΓòÉΓòÉΓòÉ
  13111.  
  13112. Synopsis: 
  13113.  
  13114.                     #include <process.h>
  13115.                     int putenv( const char *env_name );
  13116.  
  13117. Description: The environment list consists of a number of environment names, 
  13118.           each of which has a value associated with it.  Entries can be added 
  13119.           to the environment list with the DOS set command or with the putenv 
  13120.           function.  All entries in the environment list can be displayed by 
  13121.           using the DOS set command with no arguments.  A program can obtain 
  13122.           the value for an environment variable by using the getenv function. 
  13123.  
  13124.           When the value of env_name has the format 
  13125.  
  13126.                         env_name=value
  13127.  
  13128.           an environment name and its value is added to the environment list. 
  13129.           When the value of env_name has the format 
  13130.  
  13131.                         env_name=
  13132.  
  13133.           the environment name and value is removed from the environment list. 
  13134.  
  13135.           The matching is case-insensitive; all lower-case letters are treated 
  13136.           as if they were in upper case. 
  13137.  
  13138.           The space into which environment names and their values are placed is 
  13139.           limited.  Consequently, the putenv function can fail when there is 
  13140.           insufficient space remaining to store an additional value. 
  13141.  
  13142.           NOTE:  If the argument env_name is not a literal string, you should 
  13143.           duplicate the string, since putenv does not copy the value; for 
  13144.           example, 
  13145.  
  13146.                         putenv( strdup( buffer ) );
  13147.  
  13148.           To assign a string to a variable and place it in the environment 
  13149.           list: 
  13150.  
  13151.                         C>SET INCLUDE=C:\WATCOM\H
  13152.  
  13153.           To see what variables are in the environment list, and their current 
  13154.           assignments: 
  13155.  
  13156.                         C>SET
  13157.                         COMSPEC=C:\COMMAND.COM
  13158.                         PATH=C:\;C:\WATCOM
  13159.                         INCLUDE=C:\WATCOM\H
  13160.  
  13161.                         C>
  13162.  
  13163. Returns:  The putenv function returns zero when it is successfully executed and 
  13164.           returns -1 when it fails. 
  13165.  
  13166. Errors:   When an error has occurred, errno contains a value indicating the 
  13167.           type of error that has been detected. 
  13168.  
  13169.    ENOMEM    Not enough memory to allocate a new environment string. 
  13170.  
  13171. See Also: clearenv, getenv, setenv 
  13172.  
  13173. Example: 
  13174.  
  13175.           The following gets the string currently assigned to INCLUDE and 
  13176.           displays it, assigns a new value to it, gets and displays it, and 
  13177.           then removes the environment name and value. 
  13178.  
  13179.                     #include <stdio.h>
  13180.                     #include <stdlib.h>
  13181.                     void main()
  13182.                       {
  13183.                         char *path;
  13184.                         path = getenv( "INCLUDE" );
  13185.                         if( path != NULL )
  13186.                             printf( "INCLUDE=%s\n", path );
  13187.                         if( putenv( "INCLUDE=mylib;yourlib" ) != 0 )
  13188.                             printf( "putenv failed" );
  13189.                         path = getenv( "INCLUDE" );
  13190.                         if( path != NULL )
  13191.                             printf( "INCLUDE=%s\n", path );
  13192.                         if( putenv( "INCLUDE=" ) != 0 )
  13193.                             printf( "putenv failed" );
  13194.                       }
  13195.  
  13196.           produces the following: 
  13197.  
  13198.                     INCLUDE=C:\WATCOM\H
  13199.                     INCLUDE=mylib;yourlib
  13200.  
  13201. Classification: WATCOM 
  13202.  
  13203.  
  13204. ΓòÉΓòÉΓòÉ 235. puts ΓòÉΓòÉΓòÉ
  13205.  
  13206. Synopsis: 
  13207.  
  13208.                     #include <stdio.h>
  13209.                     int puts( const char *buf );
  13210.  
  13211. Description: The puts function writes the character string pointed to by buf to 
  13212.           the output stream designated by stdout, and appends a new-line 
  13213.           character to the output.  The terminating null character is not 
  13214.           written. 
  13215.  
  13216. Returns:  The puts function returns a non-zero value if an error occurs; 
  13217.           otherwise, it returns zero.  When an error has occurred, errno 
  13218.           contains a value indicating the type of error that has been detected. 
  13219.  
  13220. See Also: fputs, putc 
  13221.  
  13222. Example: 
  13223.  
  13224.                     #include <stdio.h>
  13225.  
  13226.                     void main()
  13227.                       {
  13228.                         FILE *fp;
  13229.                         char buffer[80];
  13230.  
  13231.                         fp = freopen( "file", "r", stdin );
  13232.                         while( gets( buffer ) != NULL ) {
  13233.                             puts( buffer );
  13234.                         }
  13235.                         fclose( fp );
  13236.                       }
  13237.  
  13238. Classification: ANSI 
  13239.  
  13240.  
  13241. ΓòÉΓòÉΓòÉ 236. qsort ΓòÉΓòÉΓòÉ
  13242.  
  13243. Synopsis: 
  13244.  
  13245.                     #include <stdlib.h>
  13246.                     void qsort( void *base,
  13247.                                 size_t num,
  13248.                                 size_t width,
  13249.                                 int (*compar)
  13250.                                      ( const void *, const void *) );
  13251.  
  13252. Description: The qsort function sorts an array of num elements, which is 
  13253.           pointed to by base, using Hoare's Quicksort algorithm.  Each element 
  13254.           in the array is width bytes in size.  The comparison function pointed 
  13255.           to by compar is called with two arguments that point to elements in 
  13256.           the array.  The comparison function shall return an integer less 
  13257.           than, equal to, or greater than zero if the first argument is less 
  13258.           than, equal to, or greater than the second argument. 
  13259.  
  13260. Returns:  The qsort function returns no value. 
  13261.  
  13262. See Also: bsearch 
  13263.  
  13264. Example: 
  13265.  
  13266.                     #include <stdio.h>
  13267.                     #include <stdlib.h>
  13268.                     #include <string.h>
  13269.  
  13270.                     char *CharVect[] = { "last", "middle", "first" };
  13271.  
  13272.  
  13273.                     int compare( char **p1, char **p2 )
  13274.                       {
  13275.                         return( strcmp( *p1, *p2 ) );
  13276.                       }
  13277.  
  13278.                     void main()
  13279.                       {
  13280.                         qsort( CharVect, sizeof(CharVect)/sizeof(char *),
  13281.                               sizeof(char *), compare );
  13282.                         printf( "%s %s %s\n",
  13283.                                 CharVect[0], CharVect[1], CharVect[2] );
  13284.                       }
  13285.  
  13286.           produces the following: 
  13287.  
  13288.                     first last middle
  13289.  
  13290. Classification: ANSI 
  13291.  
  13292.  
  13293. ΓòÉΓòÉΓòÉ 237. raise ΓòÉΓòÉΓòÉ
  13294.  
  13295. Synopsis: 
  13296.  
  13297.                     #include <signal.h>
  13298.                     int raise( int condition );
  13299.  
  13300. Description: The raise function signals the exceptional condition indicated by 
  13301.           the condition argument.  The possible conditions are defined in the 
  13302.           <signal.h> header file and are documented with the signal function. 
  13303.           The signal function can be used to specify the action which is to 
  13304.           take place when such a condition occurs. 
  13305.  
  13306. Returns:  The raise function returns zero when the condition is successfully 
  13307.           raised and a non-zero value otherwise.  There may be no return of 
  13308.           control following the function call if the action for that condition 
  13309.           is to terminate the program or to transfer control using the longjmp 
  13310.           function. 
  13311.  
  13312. See Also: signal 
  13313.  
  13314. Example: 
  13315.  
  13316.                     /*
  13317.                      * This program loops until a SIGINT signal
  13318.                      * is received or a count is exceeded.
  13319.                      */
  13320.                     #include <stdio.h>
  13321.                     #include <signal.h>
  13322.  
  13323.                     sig_atomic_t signal_count;
  13324.                     sig_atomic_t signal_number;
  13325.                     static void alarm_handler( int signum );
  13326.  
  13327.                     void main()
  13328.                       {
  13329.                         unsigned long i;
  13330.  
  13331.                         signal_count = 0;
  13332.                         signal_number = 0;
  13333.                         signal( SIGINT, alarm_handler );
  13334.                         printf( "Program looping. Press Ctrl/C.\n" );
  13335.                         for( i = 0; i < 3000000; i++ ) {
  13336.                           if( i > 2000000 ) raise( SIGINT );
  13337.                           if( signal_count > 0 ) {
  13338.                             printf( "Signal %d received\n", signal_number );
  13339.                             break;
  13340.                           }
  13341.                         }
  13342.                       }
  13343.                     static void alarm_handler( int signum )
  13344.                       {
  13345.                         ++signal_count;
  13346.                         signal_number = signum;
  13347.                       }
  13348.  
  13349. Classification: ANSI 
  13350.  
  13351.  
  13352. ΓòÉΓòÉΓòÉ 238. rand ΓòÉΓòÉΓòÉ
  13353.  
  13354. Synopsis: 
  13355.  
  13356.                     #include <stdlib.h>
  13357.                     int rand( void );
  13358.  
  13359. Description: The rand function computes a sequence of pseudo-random integers in 
  13360.           the range 0 to RAND_MAX (32767).  The sequence can be started at 
  13361.           different values by calling the srand function. 
  13362.  
  13363. Returns:  The rand function returns a pseudo-random integer. 
  13364.  
  13365. See Also: srand 
  13366.  
  13367. Example: 
  13368.  
  13369.                     #include <stdio.h>
  13370.                     #include <stdlib.h>
  13371.  
  13372.                     void main()
  13373.                       {
  13374.                         int i;
  13375.  
  13376.                         for( i=1; i < 10; ++i ) {
  13377.                           printf( "%d\n", rand() );
  13378.                         }
  13379.                       }
  13380.  
  13381. Classification: ANSI 
  13382.  
  13383.  
  13384. ΓòÉΓòÉΓòÉ 239. read ΓòÉΓòÉΓòÉ
  13385.  
  13386. Synopsis: 
  13387.  
  13388.                     #include <io.h>
  13389.                     int read( int handle, char *buffer, int len );
  13390.  
  13391. Description: The read function reads data at the operating system level.  The 
  13392.           number of bytes transmitted is given by len and the data is 
  13393.           transmitted starting at the address specified by buffer. 
  13394.  
  13395.           The handle value is returned by the open function.  The access mode 
  13396.           must have included either O_RDONLY or O_RDWR when the open function 
  13397.           was invoked.  The data is read starting at the current file position 
  13398.           for the file in question.  This file position can be determined with 
  13399.           the tell function and can be set with the lseek function. 
  13400.  
  13401.           When O_BINARY is included in the access mode, the data is transmitted 
  13402.           unchanged.  When O_TEXT is included in the access mode, the data is 
  13403.           transmitted with the extra carriage return character removed before 
  13404.           each linefeed character encountered in the original data. 
  13405.  
  13406. Returns:  The read function returns the number of bytes of data transmitted 
  13407.           from the file to the buffer (this does not include any 
  13408.           carriage-return characters that were removed during the 
  13409.           transmission). Normally, this is the number given by the len 
  13410.           argument.  When the end of the file is encountered before the read 
  13411.           completes, the return value will be less than the number of bytes 
  13412.           requested. 
  13413.  
  13414.           A value of -1 is returned when an input/output error is detected. 
  13415.           When an error has occurred, errno contains a value indicating the 
  13416.           type of error that has been detected. 
  13417.  
  13418. See Also: close, creat, fread, open, write 
  13419.  
  13420. Example: 
  13421.  
  13422.                     #include <stdio.h>
  13423.                     #include <fcntl.h>
  13424.                     #include <io.h>
  13425.                     void main()
  13426.                       {
  13427.                         int  handle;
  13428.                         int  size_read;
  13429.                         char buffer[80];
  13430.                         /* open a file for input              */
  13431.                         handle = open( "file", O_RDONLY | O_TEXT );
  13432.                         if( handle != -1 ) {
  13433.                           /* read the text                      */
  13434.                           size_read = read( handle, buffer,
  13435.                                             sizeof( buffer ) );
  13436.                           /* test for error                     */
  13437.                           if( size_read == -1 ) {
  13438.                               printf( "Error reading file\n" );
  13439.                           }
  13440.                           /* close the file                     */
  13441.                           close( handle );
  13442.                         }
  13443.                       }
  13444.  
  13445. Classification: POSIX 1003.1 
  13446.  
  13447.  
  13448. ΓòÉΓòÉΓòÉ 240. readdir ΓòÉΓòÉΓòÉ
  13449.  
  13450. Synopsis: 
  13451.  
  13452.                     #include <direct.h>
  13453.                     struct dirent *readdir( DIR *dirp );
  13454.  
  13455. Description: The readdir function obtains information about the next matching 
  13456.           file name from the argument dirp. The argument dirp is the value 
  13457.           returned from the opendir function.  The readdir function can be 
  13458.           called repeatedly to obtain the list of file names contained in the 
  13459.           directory specified by the pathname given to opendir. The function 
  13460.           closedir must be called to close the directory and free the memory 
  13461.           allocated by opendir. 
  13462.  
  13463.           The file <direct.h> contains definitions for the structure dirent. 
  13464.  
  13465.                     typedef struct dirent {
  13466.                         char    d_dta[ 21 ];       /* disk transfer area */
  13467.                         char    d_attr;            /* file's attribute */
  13468.                         unsigned short int d_time; /* file's time */
  13469.                         unsigned short int d_date; /* file's date */
  13470.                         long    d_size;            /* file's size */
  13471.                         char    d_name[ 13 ];      /* file's name */
  13472.                         ino_t   d_ino;             /* serial number */
  13473.                         char    d_first;           /* flag for 1st time */
  13474.                     } DIR;
  13475.  
  13476.  
  13477. Returns:  When successful, readdir returns a pointer to an object of type 
  13478.           struct dirent.  When an error occurs, readdir returns the value NULL 
  13479.           and errno is set to indicate the error.  When the end of the 
  13480.           directory is encountered, readdir returns the value NULL and errno is 
  13481.           unchanged. 
  13482.  
  13483. Errors:   When an error has occurred, errno contains a value indicating the 
  13484.           type of error that has been detected. 
  13485.  
  13486.    EBADF     The argument dirp does not refer to an open directory stream. 
  13487.  
  13488. See Also: closedir, opendir 
  13489.  
  13490. Example: 
  13491.  
  13492.           To get a list of files contained in the directory \watcom\h on your 
  13493.           default disk: 
  13494.  
  13495.                     #include <stdio.h>
  13496.                     #include <direct.h>
  13497.  
  13498.                     void main()
  13499.                       {
  13500.                         DIR *dirp;
  13501.                         struct dirent *direntp;
  13502.  
  13503.                         dirp = opendir( "\\watcom\\h" );
  13504.                         if( dirp != NULL ) {
  13505.                           for(;;) {
  13506.                             direntp = readdir( dirp );
  13507.                             if( direntp == NULL ) break;
  13508.                             printf( "%s\n", direntp->d_name );
  13509.                           }
  13510.                           closedir( dirp );
  13511.                         }
  13512.                       }
  13513.  
  13514.           Note the use of two adjacent backslash characters (\) within 
  13515.           character-string constants to signify a single backslash. 
  13516.  
  13517. Classification: POSIX 1003.1 
  13518.  
  13519.  
  13520. ΓòÉΓòÉΓòÉ 241. realloc Functions ΓòÉΓòÉΓòÉ
  13521.  
  13522. Synopsis: 
  13523.  
  13524.                     #include <stdlib.h>  For ANSI compatibility (realloc only)
  13525.                     #include <malloc.h>  Required for other function prototypes
  13526.                     void * realloc( void *old_blk, size_t size );
  13527.                     void __based(void) *_brealloc( __segment seg,
  13528.                                                    void __based(void) *old_blk,
  13529.                                                    size_t size );
  13530.                     void __far  *_frealloc( void __far  *old_blk,
  13531.                                                   size_t size );
  13532.                     void __near *_nrealloc( void __near *old_blk,
  13533.                                                   size_t size );
  13534.  
  13535. Description: When the value of the old_blk argument is NULL, a new block of 
  13536.           memory of size bytes is allocated. 
  13537.  
  13538.           If the value of size is zero, the corresponding free function is 
  13539.           called to release the memory pointed to by old_blk. 
  13540.  
  13541.           Otherwise, the realloc function re-allocates space for an object of 
  13542.           size bytes by either: 
  13543.  
  13544.    o shrinking the allocated size of the allocated memory block old_blk when 
  13545.      size is sufficiently smaller than the size of old_blk. 
  13546.  
  13547.    o extending the allocated size of the allocated memory block old_blk if 
  13548.      there is a large enough block of unallocated memory immediately following 
  13549.      old_blk. 
  13550.  
  13551.    o allocating a new block and copying the contents of old_blk to the new 
  13552.      block. 
  13553.  
  13554.           Because it is possible that a new block will be allocated, no other 
  13555.           pointers should point into the memory of old_blk. These pointers will 
  13556.           point to freed memory, with possible disastrous results, when a new 
  13557.           block is allocated. 
  13558.  
  13559.           The memory pointed to by old_blk is not freed if it cannot be 
  13560.           re-allocated. 
  13561.  
  13562.           Each function reallocates memory from a particular heap, as listed 
  13563.           below: 
  13564.  
  13565.    Function      Heap 
  13566.    realloc       Depends on data model of the program 
  13567.    _brealloc     Based heap specified by seg value 
  13568.    _frealloc     Far heap (outside the default data segment) 
  13569.    _nrealloc     Near heap (inside the default data segment) 
  13570.  
  13571.           In a small data memory model, the realloc function is equivalent to 
  13572.           the _nrealloc function; in a large data memory model, the realloc 
  13573.           function is equivalent to the _frealloc function. 
  13574.  
  13575. Returns:  The realloc functions return a pointer to the start of the 
  13576.           re-allocated memory.  The return value is NULL if there is 
  13577.           insufficient memory available or if the value of the size argument is 
  13578.           zero.  The _brealloc function returns _NULLOFF if there is 
  13579.           insufficient memory available or if the requested size is zero. 
  13580.  
  13581. See Also: calloc Functions, _expand Functions, free Functions, halloc, hfree, 
  13582.           malloc Functions, _msize Functions, sbrk 
  13583.  
  13584. Example: 
  13585.  
  13586.                     #include <stdlib.h>
  13587.                     #include <malloc.h>
  13588.  
  13589.                     void main()
  13590.                       {
  13591.                         char *buffer;
  13592.  
  13593.                         buffer = malloc( 80 );
  13594.                         buffer = realloc( buffer, 100 );
  13595.                       }
  13596.  
  13597. Classification: realloc is ANSI; _brealloc, _frealloc, and _nrealloc are not 
  13598.           ANSI 
  13599.  
  13600.  
  13601. ΓòÉΓòÉΓòÉ 242. remove ΓòÉΓòÉΓòÉ
  13602.  
  13603. Synopsis: 
  13604.  
  13605.                     #include <stdio.h>
  13606.                     int remove( const char *filename );
  13607.  
  13608. Description: The remove function deletes the file whose name is the string 
  13609.           pointed to by filename. 
  13610.  
  13611. Returns:  The remove function returns zero if the operation succeeds, non-zero 
  13612.           if it fails.  When an error has occurred, errno contains a value 
  13613.           indicating the type of error that has been detected. 
  13614.  
  13615. Example: 
  13616.  
  13617.                     #include <stdio.h>
  13618.  
  13619.                     void main()
  13620.                       {
  13621.                         remove( "vm.tmp" );
  13622.                       }
  13623.  
  13624. Classification: ANSI 
  13625.  
  13626.  
  13627. ΓòÉΓòÉΓòÉ 243. rename ΓòÉΓòÉΓòÉ
  13628.  
  13629. Synopsis: 
  13630.  
  13631.                     #include <stdio.h>
  13632.                     int rename( const char *old, const char *new );
  13633.  
  13634. Description: The rename function causes the file whose name is indicated by the 
  13635.           string old to be renamed to the name given by the string new. 
  13636.  
  13637. Returns:  The rename function returns zero if the operation succeeds, a 
  13638.           non-zero value if it fails.  When an error has occurred, errno 
  13639.           contains a value indicating the type of error that has been detected. 
  13640.  
  13641. Example: 
  13642.  
  13643.                     #include <stdio.h>
  13644.  
  13645.                     void main()
  13646.                       {
  13647.                         rename( "old.dat", "new.dat" );
  13648.                       }
  13649.  
  13650. Classification: ANSI 
  13651.  
  13652.  
  13653. ΓòÉΓòÉΓòÉ 244. rewind ΓòÉΓòÉΓòÉ
  13654.  
  13655. Synopsis: 
  13656.  
  13657.                     #include <stdio.h>
  13658.                     void rewind( FILE *fp );
  13659.  
  13660. Description: The rewind function sets the file position indicator for the 
  13661.           stream indicated to by fp to the beginning of the file.  It is 
  13662.           equivalent to 
  13663.  
  13664.                         fseek( fp, 0L, SEEK_SET );
  13665.  
  13666.           except that the error indicator for the stream is cleared. 
  13667.  
  13668. Returns:  The rewind function returns no value. 
  13669.  
  13670. See Also: fopen, clearerr 
  13671.  
  13672. Example: 
  13673.  
  13674.                     #include <stdio.h>
  13675.  
  13676.                     void main()
  13677.                       {
  13678.                         FILE *fp;
  13679.  
  13680.                         if( (fp = fopen( "program.asm", "r")) != NULL ) {
  13681.                             assemble_pass( 1 );
  13682.                             rewind( fp );
  13683.                             assemble_pass( 2 );
  13684.                             fclose( fp );
  13685.                         }
  13686.                       }
  13687.  
  13688. Classification: ANSI 
  13689.  
  13690.  
  13691. ΓòÉΓòÉΓòÉ 245. rmdir ΓòÉΓòÉΓòÉ
  13692.  
  13693. Synopsis: 
  13694.  
  13695.                     #include <sys\types.h>
  13696.                     #include <direct.h>
  13697.                     int rmdir( const char *path );
  13698.  
  13699. Description: The rmdir function removes (deletes) the specified directory.  The 
  13700.           directory must not contain any files or directories.  The path can be 
  13701.           either relative to the current working directory or it can be an 
  13702.           absolute path name. 
  13703.  
  13704. Returns:  The rmdir function returns zero if successful and -1 otherwise. 
  13705.  
  13706. See Also: chdir, chmod, getcwd, mkdir, stat 
  13707.  
  13708. Example: 
  13709.  
  13710.           To delete the directory called \tmp on drive C: 
  13711.  
  13712.                     rmdir( "C:\\tmp" );
  13713.  
  13714.           Note the use of two adjacent backslash characters (\) within 
  13715.           character-string constants to signify a single backslash. 
  13716.  
  13717. Classification: POSIX 1003.1 
  13718.  
  13719.  
  13720. ΓòÉΓòÉΓòÉ 246. _rotl ΓòÉΓòÉΓòÉ
  13721.  
  13722. Synopsis: 
  13723.  
  13724.                     #include <stdlib.h>
  13725.                     unsigned int _rotl( unsigned int value,
  13726.                                         unsigned int shift );
  13727.  
  13728. Description: The _rotl function rotates the unsigned integer, determined by 
  13729.           value, to the left by the number of bits specified in shift. If you 
  13730.           port an application using _rotl between a 16-bit and a 32-bit 
  13731.           environment, you will get different results because of the difference 
  13732.           in the size of integers. 
  13733.  
  13734. Returns:  The rotated value is returned. 
  13735.  
  13736. See Also: _lrotl, _lrotr, _rotr 
  13737.  
  13738. Example: 
  13739.  
  13740.                     #include <stdio.h>
  13741.                     #include <stdlib.h>
  13742.  
  13743.                     unsigned int mask = 0x0F00;
  13744.  
  13745.                     void main()
  13746.                       {
  13747.                         mask = _rotl( mask, 4 );
  13748.                         printf( "%04X\n", mask );
  13749.                       }
  13750.  
  13751.           produces the following: 
  13752.  
  13753.                     F000
  13754.  
  13755. Classification: WATCOM 
  13756.  
  13757.  
  13758. ΓòÉΓòÉΓòÉ 247. _rotr ΓòÉΓòÉΓòÉ
  13759.  
  13760. Synopsis: 
  13761.  
  13762.                     #include <stdlib.h>
  13763.                     unsigned int _rotr( unsigned int value,
  13764.                                         unsigned int shift );
  13765.  
  13766. Description: The _rotr function rotates the unsigned integer, determined by 
  13767.           value, to the right by the number of bits specified in shift. If you 
  13768.           port an application using _rotr between a 16-bit and a 32-bit 
  13769.           environment, you will get different results because of the difference 
  13770.           in the size of integers. 
  13771.  
  13772. Returns:  The rotated value is returned. 
  13773.  
  13774. See Also: _lrotl, _lrotr, _rotl 
  13775.  
  13776. Example: 
  13777.  
  13778.                     #include <stdio.h>
  13779.                     #include <stdlib.h>
  13780.  
  13781.                     unsigned int mask = 0x1230;
  13782.  
  13783.                     void main()
  13784.                       {
  13785.                         mask = _rotr( mask, 4 );
  13786.                         printf( "%04X\n", mask );
  13787.                       }
  13788.  
  13789.           produces the following: 
  13790.  
  13791.                     0123
  13792.  
  13793. Classification: WATCOM 
  13794.  
  13795.  
  13796. ΓòÉΓòÉΓòÉ 248. sbrk ΓòÉΓòÉΓòÉ
  13797.  
  13798. Synopsis: 
  13799.  
  13800.                     #include <stdlib.h>
  13801.                     void *sbrk( int increment );
  13802.  
  13803. Description: The sbrk sets the "break" value for the program by adding the 
  13804.           value of increment to the current break value.  This increment may be 
  13805.           positive or negative. 
  13806.  
  13807.           The "break" value is the address of the first byte of unallocated 
  13808.           memory. When a program starts execution, the break value is placed 
  13809.           following the code and constant data for the program.  As memory is 
  13810.           allocated, this pointer will advance when there is no freed block 
  13811.           large enough to satisfy an allocation request. 
  13812.  
  13813.           A new process started with one of the spawn... or exec... functions 
  13814.           is loaded following the break value. Consequently, decreasing the 
  13815.           break value leaves more space available to the new process. 
  13816.           Similarly, for a resident program (a program which remains in memory 
  13817.           while another program executes), increasing the break value will 
  13818.           leave more space available to be allocated by the resident program 
  13819.           after other programs are loaded. 
  13820.  
  13821. Returns:  The function returns the old break value when the break value has 
  13822.           been reset; otherwise, -1 is returned.  When an error has occurred, 
  13823.           errno contains a value indicating the type of error that has been 
  13824.           detected. 
  13825.  
  13826. See Also: calloc Functions, _expand Functions, free Functions, halloc, hfree, 
  13827.           malloc Functions, _msize Functions, realloc Functions 
  13828.  
  13829. Classification: WATCOM 
  13830.  
  13831.  
  13832. ΓòÉΓòÉΓòÉ 249. scanf ΓòÉΓòÉΓòÉ
  13833.  
  13834. Synopsis: 
  13835.  
  13836.                     #include <stdio.h>
  13837.                     int scanf( const char *format, ... );
  13838.  
  13839. Description: The scanf function scans input from the file designated by stdin 
  13840.           under control of the argument format. The format string is described 
  13841.           below.  Following the format string is the list of addresses of items 
  13842.           to receive values. 
  13843.  
  13844. Returns:  The scanf function returns EOF when the scanning is terminated by 
  13845.           reaching the end of the input stream.  Otherwise, the number of input 
  13846.           arguments for which values were successfully scanned and stored is 
  13847.           returned. 
  13848.  
  13849. See Also: fscanf, sscanf 
  13850.  
  13851. Example: 
  13852.  
  13853.           To scan a date in the form "Saturday April 18 1987": 
  13854.  
  13855.                     #include <stdio.h>
  13856.  
  13857.                     void main()
  13858.                       {
  13859.                         int day, year;
  13860.                         char weekday[10], month[12];
  13861.  
  13862.                         scanf( "%s %s %d %d", weekday, month, &day, &year );
  13863.                       }
  13864.  
  13865.  
  13866. Format Control String: The format control string consists of zero or more 
  13867.           format directives  that specify acceptable input file data. 
  13868.           Subsequent arguments are pointers to various types of objects that 
  13869.           are assigned values as the format string is processed. 
  13870.  
  13871.           A format directive can be a sequence of one or more white-space 
  13872.           characters, an ordinary character,  or a conversion specifier.  An 
  13873.           ordinary character in the format string is any character, other than 
  13874.           a white-space character or the percent character (%), that is not 
  13875.           part of a conversion specifier.  A conversion specifier is a sequence 
  13876.           of characters in the format string that begins with a percent 
  13877.           character (%) and is followed, in sequence, by the following: 
  13878.  
  13879.    o an optional assignment suppression indicator:  the asterisk character (*) 
  13880.  
  13881.    o an optional decimal integer that specifies the maximum field width  to be 
  13882.      scanned for the conversion 
  13883.  
  13884.    o an optional pointer-type  specification:  one of "N" or "F" 
  13885.  
  13886.    o an optional type length  specification:  one of "h", "l" or "L" 
  13887.  
  13888.    o a character that specifies the type of conversion to be performed: one of 
  13889.      the characters cdefgionpsux[ 
  13890.  
  13891.           As each format directive in the format string is processed, the 
  13892.           directive may successfully complete, fail because of a lack of input 
  13893.           data, or fail because of a matching error as defined by the 
  13894.           particular directive.  If end-of-file is encountered on the input 
  13895.           data before any characters that match the current directive have been 
  13896.           processed (other than leading white-space where permitted), the 
  13897.           directive fails for lack of data.  If end-of-file occurs after a 
  13898.           matching character has been processed, the directive is completed 
  13899.           (unless a matching error occurs), and the function returns without 
  13900.           processing the next directive.  If a directive fails because of an 
  13901.           input character mismatch, the character is left unread in the input 
  13902.           stream.  Trailing white-space characters, including new-line 
  13903.           characters, are not read unless matched by a directive.  When a 
  13904.           format directive fails, or the end of the format string is 
  13905.           encountered, the scanning is completed and the function returns. 
  13906.  
  13907.           When one or more white-space characters (space " ", horizontal tab 
  13908.           "\t", vertical tab "\v", form feed "\f", carriage return "\r", new 
  13909.           line or linefeed "\n") occur in the format string, input data up to 
  13910.           the first non-white-space character is read, or until no more data 
  13911.           remains.  If no white-space characters are found in the input data, 
  13912.           the scanning is complete and the function returns. 
  13913.  
  13914.           An ordinary character in the format string is expected to match the 
  13915.           same character in the input stream. 
  13916.  
  13917.           A conversion specifier in the format string is processed as follows: 
  13918.  
  13919.    o for conversion types other than "[", "c" and "n", leading white-space 
  13920.      characters are skipped 
  13921.  
  13922.    o for conversion types other than "n", all input characters, up to any 
  13923.      specified maximum field length, that can be matched by the conversion type 
  13924.      are read and converted to the appropriate type of value; the character 
  13925.      immediately following the last character to be matched is left unread; if 
  13926.      no characters are matched, the format directive fails 
  13927.  
  13928.    o unless the assignment suppression indicator ("*") was specified, the 
  13929.      result of the conversion is assigned to the object pointed to by the next 
  13930.      unused argument (if assignment suppression was specified, no argument is 
  13931.      skipped); the arguments must correspond in number, type and order to the 
  13932.      conversion specifiers in the format string 
  13933.  
  13934.           A pointer-type specification is used to indicate the type of pointer 
  13935.           used to locate the next argument to be scanned: 
  13936.  
  13937.    F         pointer is a far pointer 
  13938.    N         pointer is a near pointer 
  13939.  
  13940.           The pointer type defaults to that used for data in the memory model 
  13941.           for which the program has been compiled. 
  13942.  
  13943.           A type length specifier affects the conversion as follows: 
  13944.  
  13945.    o "h" causes a "d", "i", "o", "u" or "x" (integer) conversion to assign the 
  13946.      converted value to an object of type short int or unsigned short int 
  13947.  
  13948.    o "h" causes an "f" conversion to assign a fixed-point number to an object 
  13949.      of type long consisting of a 16-bit integer part and a 16-bit fractional 
  13950.      part. 
  13951.  
  13952.    o "h" causes an "n" (read length assignment) operation to assign the number 
  13953.      of characters that have been read to an object of type unsigned short int 
  13954.  
  13955.    o "l" causes a "d", "i", "o", "u" or "x" (integer) conversion to assign the 
  13956.      converted value to an object of type long int or unsigned long int 
  13957.  
  13958.    o "l" causes an "n" (read length assignment) operation to assign the number 
  13959.      of characters that have been read to an object of type unsigned long int 
  13960.  
  13961.    o "l" causes an "e", "f" or "g" (floating-point) conversion to assign the 
  13962.      converted value to an object of type double 
  13963.  
  13964.    o "L" causes an "e", "f" or "g" (floating-point) conversion to assign the 
  13965.      converted value to an object of type long double 
  13966.  
  13967.           The valid conversion type specifiers are: 
  13968.  
  13969.    c         Any sequence of characters in the input stream of the length 
  13970.              specified by the field width, or a single character if no field 
  13971.              width is specified, is matched.  The argument is assumed to point 
  13972.              to the first element of a character array of sufficient size to 
  13973.              contain the sequence, without a terminating null character ('\0'). 
  13974.              For a single character assignment, a pointer to a single object of 
  13975.              type char is sufficient. 
  13976.  
  13977.    d         A decimal integer, consisting of an optional sign, followed by one 
  13978.              or more decimal digits, is matched.  The argument is assumed to 
  13979.              point to an object of type int. 
  13980.  
  13981.    e, f, g   A floating point number, consisting of an optional sign ("+" or 
  13982.              "-"), followed by one or more decimal digits, optionally 
  13983.              containing a decimal-point character, followed by an optional 
  13984.              exponent of the form "e" or "E", an optional sign and one or more 
  13985.              decimal digits, is matched.  The exponent, if present, specifies 
  13986.              the power of ten by which the decimal fraction is multiplied.  The 
  13987.              argument is assumed to point to an object of type float. 
  13988.  
  13989.    i         An optional sign, followed by an octal, decimal or hexadecimal 
  13990.              constant is matched.  An octal constant consists of "0" and zero 
  13991.              or more octal digits.  A decimal constant consists of a non-zero 
  13992.              decimal digit and zero or more decimal digits.  A hexadecimal 
  13993.              constant consists of the characters "0x" or "0X" followed by one 
  13994.              or more (upper- or lower-case) hexadecimal digits.  The argument 
  13995.              is assumed to point to an object of type int. 
  13996.  
  13997.    n         No input data is processed.  Instead, the number of characters 
  13998.              that have already been read is assigned to the object of type 
  13999.              unsigned int that is pointed to by the argument.  The number of 
  14000.              items that have been scanned and assigned (the return value) is 
  14001.              not affected by the "n" conversion type specifier. 
  14002.  
  14003.    o         An octal integer, consisting of an optional sign, followed by one 
  14004.              or more (zero or non-zero) octal digits, is matched.  The argument 
  14005.              is assumed to point to an object of type int. 
  14006.  
  14007.    p         A hexadecimal integer, as described for "x" conversions below, is 
  14008.              matched.  The converted value is further converted to a value of 
  14009.              type void* and then assigned to the object pointed to by the 
  14010.              argument. 
  14011.  
  14012.    s         A sequence of non-white-space characters is matched.  The argument 
  14013.              is assumed to point to the first element of a character array of 
  14014.              sufficient size to contain the sequence and a terminating null 
  14015.              character, which is added by the conversion operation. 
  14016.  
  14017.    u         An unsigned decimal integer, consisting of one or more decimal 
  14018.              digits, is matched.  The argument is assumed to point to an object 
  14019.              of type unsigned int. 
  14020.  
  14021.    x         A hexadecimal integer, consisting of an optional sign, followed by 
  14022.              an optional prefix "0x" or "0X", followed by one or more (upper- 
  14023.              or lower-case) hexadecimal digits, is matched.  The argument is 
  14024.              assumed to point to an object of type int. 
  14025.  
  14026.    [c1c2...] A sequence of characters, consisting of any of the characters c1, 
  14027.              c2, ... called the scanset,  in any order, is matched. c1 cannot 
  14028.              be the caret character ('^').  If c1 is "]", that character is 
  14029.              considered to be part of the scanset and a second "]" is required 
  14030.              to end the format directive.  The argument is assumed to point to 
  14031.              the first element of a character array of sufficient size to 
  14032.              contain the sequence and a terminating null character, which is 
  14033.              added by the conversion operation. 
  14034.  
  14035.    [^c1c2...] A sequence of characters, consisting of any of the characters 
  14036.              other than  the characters between the "^" and "]", is matched. 
  14037.              As with the preceding conversion, if c1 is "]", it is considered 
  14038.              to be part of the scanset and a second "]" ends the format 
  14039.              directive.  The argument is assumed to point to the first element 
  14040.              of a character array of sufficient size to contain the sequence 
  14041.              and a terminating null character, which is added by the conversion 
  14042.              operation. 
  14043.  
  14044.           A conversion type specifier of "%" is treated as a single ordinary 
  14045.           character that matches a single "%" character in the input data.  A 
  14046.           conversion type specifier other than those listed above causes 
  14047.           scanning to terminate the function to return. 
  14048.  
  14049.           The line 
  14050.  
  14051.                     scanf( "%s%*f%3hx%d", name, &hexnum, &decnum )
  14052.  
  14053.           with input 
  14054.  
  14055.                     some_string 34.555e-3 abc1234
  14056.  
  14057.           will copy "some_string" into the array name, skip 34.555e-3 , assign 
  14058.           0xabc to hexnum and 1234 to decnum. The return value will be 3. 
  14059.  
  14060.           The program 
  14061.  
  14062.                     #include <stdio.h>
  14063.  
  14064.                     void main()
  14065.                       {
  14066.                         char string1[80], string2[80];
  14067.  
  14068.                         scanf( "%[abcdefghijklmnopqrstuvwxyz"
  14069.                                "ABCDEFGHIJKLMNOPQRSTUVWZ ]%*2s%[^\n]",
  14070.                                string1, string2 );
  14071.                         printf( "%s\n%s\n", string1, string2 );
  14072.                       }
  14073.  
  14074.           with input 
  14075.  
  14076.                     They may look alike, but they don't perform alike.
  14077.  
  14078.           will assign 
  14079.  
  14080.                     "They may look alike"
  14081.  
  14082.           to string1, skip the comma (the "%*2s" will match only the comma; the 
  14083.           following blank terminates that field), and assign 
  14084.  
  14085.                     " but they don't perform alike."
  14086.  
  14087.           to string2. 
  14088.  
  14089. Classification: ANSI, (except for "F" and "N" modifiers) 
  14090.  
  14091.  
  14092. ΓòÉΓòÉΓòÉ 250. _searchenv ΓòÉΓòÉΓòÉ
  14093.  
  14094. Synopsis: 
  14095.  
  14096.                     #include <stdlib.h>
  14097.                     void _searchenv( const char *name,
  14098.                                      const char *env_var,
  14099.                                      char *buffer );
  14100.  
  14101. Description: The _searchenv function searches for the file specified by name in 
  14102.           the list of directories assigned to the environment variable 
  14103.           specified by env_var. Common values for env_var are PATH, LIB and 
  14104.           INCLUDE. 
  14105.  
  14106.           The current directory is searched first to find the specified file. 
  14107.           If the file is not found in the current directory, each of the 
  14108.           directories specified by the environment variable is searched. 
  14109.  
  14110.           The full pathname is placed in the buffer pointed to by the argument 
  14111.           buffer. If the specified file cannot be found, then buffer will 
  14112.           contain an empty string. 
  14113.  
  14114. Returns:  The _searchenv function returns no value. 
  14115.  
  14116. See Also: getenv, _splitpath, putenv 
  14117.  
  14118. Example: 
  14119.  
  14120.                     #include <stdio.h>
  14121.                     #include <stdlib.h>
  14122.  
  14123.                     void main()
  14124.                       {
  14125.                         FILE *help_file;
  14126.                         char full_path[ _MAX_PATH ];
  14127.  
  14128.                         _searchenv( "watcomc.hlp", "PATH", full_path );
  14129.                         if( full_path[0] == '\0' ) {
  14130.                           printf( "Unable to find help file\n" );
  14131.                         } else {
  14132.                           help_file = fopen( full_path, "r" );
  14133.                           display_help( help_file );
  14134.                           fclose( help_file );
  14135.                         }
  14136.                       }
  14137.  
  14138. Classification: WATCOM 
  14139.  
  14140.  
  14141. ΓòÉΓòÉΓòÉ 251. segread ΓòÉΓòÉΓòÉ
  14142.  
  14143. Synopsis: 
  14144.  
  14145.                     #include <dos.h>
  14146.                     void segread( struct SREGS *seg_regs );
  14147.  
  14148. Description: The segread function places the values of the segment registers 
  14149.           into the structure located by seg_regs. 
  14150.  
  14151. Returns:  No value is returned. 
  14152.  
  14153. See Also: FP_OFF, FP_SEG, MK_FP 
  14154.  
  14155. Example: 
  14156.  
  14157.                     #include <stdio.h>
  14158.                     #include <dos.h>
  14159.  
  14160.                     void main()
  14161.                       {
  14162.                         struct SREGS sregs;
  14163.  
  14164.                         segread( &sregs );
  14165.                         printf( "Current value of CS is %04X\n", sregs.cs );
  14166.                       }
  14167.  
  14168. Classification: WATCOM 
  14169.  
  14170.  
  14171. ΓòÉΓòÉΓòÉ 252. setbuf ΓòÉΓòÉΓòÉ
  14172.  
  14173. Synopsis: 
  14174.  
  14175.                     #include <stdio.h>
  14176.                     void setbuf( FILE *fp, char *buffer );
  14177.  
  14178. Description: The setbuf function can be used to associate a buffer with the 
  14179.           file designated by fp. If this function is used, it must be called 
  14180.           after the file has been opened and before it has been read or 
  14181.           written.  If the argument buffer is NULL, then all input/output for 
  14182.           the file fp will be completely unbuffered.  If the argument buffer is 
  14183.           not NULL, then it must point to an array that is at least BUFSIZ 
  14184.           characters in length, and all input/output will be fully buffered. 
  14185.  
  14186. Returns:  The setbuf function returns no value. 
  14187.  
  14188. See Also: fopen, setvbuf 
  14189.  
  14190. Example: 
  14191.  
  14192.                     #include <stdio.h>
  14193.  
  14194.                     void main()
  14195.                       {
  14196.                         char *buffer;
  14197.                         FILE *fp;
  14198.  
  14199.                         fp = fopen( "data.fil", "r" );
  14200.                         buffer = malloc( BUFSIZ );
  14201.                         setbuf( fp, buffer );
  14202.                         .
  14203.                         .
  14204.                         .
  14205.                         fclose( fp );
  14206.                       }
  14207.  
  14208. Classification: ANSI 
  14209.  
  14210.  
  14211. ΓòÉΓòÉΓòÉ 253. setenv ΓòÉΓòÉΓòÉ
  14212.  
  14213. Synopsis: 
  14214.  
  14215.                     #include <env.h>
  14216.                     int setenv( const char *name,
  14217.                                 const char *newvalue,
  14218.                                 int overwrite );
  14219.  
  14220. Description: The environment list consists of a number of environment names, 
  14221.           each of which has a value associated with it.  Entries can be added 
  14222.           to the environment list with the DOS set command or with the setenv 
  14223.           function.  All entries in the environment list can be displayed by 
  14224.           using the DOS set command with no arguments.  A program can obtain 
  14225.           the value for an environment variable by using the getenv function. 
  14226.  
  14227.           The setenv function searches the environment list for an entry of the 
  14228.           form name=value. If no such string is present, setenv adds an entry 
  14229.           of the form name=newvalue to the environment list.  Otherwise, if the 
  14230.           overwrite argument is non-zero, setenv either will change the 
  14231.           existing value to newvalue or will delete the string name=value and 
  14232.           add the string name=newvalue. 
  14233.  
  14234.           If the newvalue pointer is NULL, all strings of the form name=value 
  14235.           in the environment list will be deleted. 
  14236.  
  14237.           The value of the pointer environ may change across a call to the 
  14238.           setenv function. 
  14239.  
  14240.           The setenv function will make copies of the strings associated with 
  14241.           name and newvalue. 
  14242.  
  14243.           The matching is case-insensitive; all lower-case letters are treated 
  14244.           as if they were in upper case. 
  14245.  
  14246.           Entries can also be added to the environment list with the DOS set 
  14247.           command or with the putenv or setenv functions.  All entries in the 
  14248.           environment list can be obtained by using the getenv function. 
  14249.  
  14250.           To assign a string to a variable and place it in the environment 
  14251.           list: 
  14252.  
  14253.                         C>SET INCLUDE=C:\WATCOM\H
  14254.  
  14255.           To see what variables are in the environment list, and their current 
  14256.           assignments: 
  14257.  
  14258.                         C>SET
  14259.                         COMSPEC=C:\COMMAND.COM
  14260.                         PATH=C:\;C:\WATCOM
  14261.                         INCLUDE=C:\WATCOM\H
  14262.                         C>
  14263.  
  14264. Returns:  The setenv function returns zero upon successful completion. 
  14265.           Otherwise, it will return a non-zero value and set errno to indicate 
  14266.           the error. 
  14267.  
  14268. Errors:   When an error has occurred, errno contains a value indicating the 
  14269.           type of error that has been detected. 
  14270.  
  14271.    ENOMEM    Not enough memory to allocate a new environment string. 
  14272.  
  14273. See Also: clearenv, exec Functions, getenv, putenv, spawn Functions, system 
  14274.  
  14275. Example: 
  14276.  
  14277.           The following will change the string assigned to INCLUDE and then 
  14278.           display the new string. 
  14279.  
  14280.                     #include <stdio.h>
  14281.                     #include <stdlib.h>
  14282.                     #include <env.h>
  14283.                     int main()
  14284.                       {
  14285.                         char *path;
  14286.                         if( setenv( "INCLUDE", "D:\WATCOM\H", 1 ) == 0 )
  14287.                           if( (path = getenv( "INCLUDE" )) != NULL )
  14288.                             printf( "INCLUDE=%s\n", path );
  14289.                       }
  14290.  
  14291. Classification: POSIX 1003.1 
  14292.  
  14293.  
  14294. ΓòÉΓòÉΓòÉ 254. setjmp ΓòÉΓòÉΓòÉ
  14295.  
  14296. Synopsis: 
  14297.  
  14298.                     #include <setjmp.h>
  14299.                     int setjmp( jmp_buf env );
  14300.  
  14301. Description: The setjmp function saves its calling environment in its jmp_buf 
  14302.           argument, for subsequent use by the longjmp function. 
  14303.  
  14304.           In some cases, error handling can be implemented by using setjmp to 
  14305.           record the point to which a return will occur following an error. 
  14306.           When an error is detected in a called function, that function uses 
  14307.           longjmp to jump back to the recorded position.  The original function 
  14308.           which called setjmp must still be active (it cannot have returned to 
  14309.           the function which called it). 
  14310.  
  14311.           Special care must be exercised to ensure that any side effects that 
  14312.           are left undone (allocated memory, opened files, etc.) are 
  14313.           satisfactorily handled. 
  14314.  
  14315. Returns:  The setjmp function returns zero when it is initially called.  The 
  14316.           return value will be non-zero if the return is the result of a call 
  14317.           to the longjmp function.  An if statement is often used to handle 
  14318.           these two returns.  When the return value is zero, the initial call 
  14319.           to setjmp has been made; when the return value is non-zero, a return 
  14320.           from a longjmp has just occurred. 
  14321.  
  14322. See Also: longjmp 
  14323.  
  14324. Example: 
  14325.  
  14326.                     /* show LONGJMP, SETJMP */
  14327.                     #include <stdio.h>
  14328.                     #include <setjmp.h>
  14329.                     jmp_buf env;
  14330.                     void main()
  14331.                       {
  14332.                         int ret_val;
  14333.                         ret_val = 293;
  14334.                         if( 0 == ( ret_val = setjmp( env ) ) ) {
  14335.                           printf( "after setjmp %d\n", ret_val );
  14336.                           rtn();
  14337.                           printf( "back from rtn %d\n", ret_val );
  14338.                         } else {
  14339.                           printf( "back from longjmp %d\n", ret_val );
  14340.                         }
  14341.                       }
  14342.                     rtn()
  14343.                       {
  14344.                         printf( "about to longjmp\n" );
  14345.                         longjmp( env, 14 );
  14346.                       }
  14347.  
  14348.           produces the following: 
  14349.  
  14350.                     after setjmp 0
  14351.                     about to longjmp
  14352.                     back from longjmp 14
  14353.  
  14354. Classification: ANSI 
  14355.  
  14356.  
  14357. ΓòÉΓòÉΓòÉ 255. setlocale ΓòÉΓòÉΓòÉ
  14358.  
  14359. Synopsis: 
  14360.  
  14361.                     #include <locale.h>
  14362.                     char *setlocale( int category, const char *locale );
  14363.  
  14364. Description: The setlocale function selects a portion of a program's locale 
  14365.           according to the category given by category and the locale specified 
  14366.           by locale. A locale  affects the collating sequence (the order in 
  14367.           which characters compare with one another), the way in which certain 
  14368.           character-handling functions operate, the decimal-point character 
  14369.           that is used in formatted input/output and string conversion, and the 
  14370.           format and names used in the time string produced by the strftime 
  14371.           function. 
  14372.  
  14373.           Potentially, there may be many such environments.  WATCOM C supports 
  14374.           only the "C" locale and so invoking this function will have no effect 
  14375.           upon the behavior of a program at present. 
  14376.  
  14377.           The possible values for the argument category are as follows: 
  14378.  
  14379.    Category            Meaning 
  14380.    LC_ALL              select entire environment 
  14381.    LC_COLLATE          select collating sequence 
  14382.    LC_CTYPE            select the character-handling 
  14383.    LC_MONETARY         select monetary formatting information 
  14384.    LC_NUMERIC          select the numeric-format environment 
  14385.    LC_TIME             select the time-related environment 
  14386.  
  14387.           At the start of a program, the equivalent of the following statement 
  14388.           is executed. 
  14389.  
  14390.                         setlocale( LC_ALL, "C" );
  14391.  
  14392. Returns:  If the selection is successful, a string is returned to indicate the 
  14393.           locale that was in effect before the function was invoked; otherwise, 
  14394.           a NULL pointer is returned. 
  14395.  
  14396. See Also: strcoll, strftime, strxfrm 
  14397.  
  14398. Classification: ANSI, POSIX 1003.1 
  14399.  
  14400.  
  14401. ΓòÉΓòÉΓòÉ 256. setmode ΓòÉΓòÉΓòÉ
  14402.  
  14403. Synopsis: 
  14404.  
  14405.                     #include <io.h>
  14406.                     #include <fcntl.h>
  14407.                     int setmode( int handle, int mode );
  14408.  
  14409. Description: The setmode function sets, at the operating system level, the 
  14410.           translation mode to be the value of mode for the file whose file 
  14411.           handle is given by handle. The mode, defined in the <fcntl.h> header 
  14412.           file, can be one of: 
  14413.  
  14414.    Mode      Meaning 
  14415.  
  14416.    O_TEXT    On input, a carriage-return character that immediately precedes a 
  14417.              linefeed character is removed from the data that is read.  On 
  14418.              output, a carriage-return character is inserted before each 
  14419.              linefeed character. 
  14420.  
  14421.    O_BINARY  Data is read or written unchanged. 
  14422.  
  14423. Returns:  If successful, the function returns the previous mode that was set 
  14424.           for the file; otherwise, -1 is returned.  When an error has occurred, 
  14425.           errno contains a value indicating the type of error that has been 
  14426.           detected. 
  14427.  
  14428. See Also: close, creat, dup, dup2, eof, exec Functions, filelength, fileno, 
  14429.           fstat, isatty, lseek, open, read, sopen, stat, tell, write, umask 
  14430.  
  14431. Classification: WATCOM 
  14432.  
  14433.  
  14434. ΓòÉΓòÉΓòÉ 257. setvbuf ΓòÉΓòÉΓòÉ
  14435.  
  14436. Synopsis: 
  14437.  
  14438.                     #include <stdio.h>
  14439.                     int setvbuf( FILE *fp,
  14440.                                  char *buf,
  14441.                                  int mode,
  14442.                                  size_t size );
  14443.  
  14444. Description: The setvbuf function can be used to associate a buffer with the 
  14445.           file designated by fp. If this function is used, it must be called 
  14446.           after the file has been opened and before it has been read or 
  14447.           written.  The argument mode determines how the file fp will be 
  14448.           buffered, as follows: 
  14449.  
  14450.    Mode      Meaning 
  14451.  
  14452.    _IOFBF    causes input/output to be fully buffered. 
  14453.  
  14454.    _IOLBF    causes output to be line buffered (the buffer will be flushed when 
  14455.              a new-line character is written, when the buffer is full, or when 
  14456.              input is requested. 
  14457.  
  14458.    _IONBF    causes input/output to be completely unbuffered. 
  14459.  
  14460.           If the argument buf is not NULL, the array to which it points will be 
  14461.           used instead of an automatically allocated buffer.  The argument size 
  14462.           specifies the size of the array. 
  14463.  
  14464. Returns:  The setvbuf function returns zero on success, or a non-zero value if 
  14465.           an invalid value is given for mode or size. 
  14466.  
  14467. See Also: fopen, setbuf 
  14468.  
  14469. Example: 
  14470.  
  14471.                     #include <stdio.h>
  14472.  
  14473.                     void main()
  14474.                     {
  14475.                       char *buf;
  14476.                       FILE *fp;
  14477.  
  14478.                       fp = fopen( "data.fil", "r" );
  14479.                       buf = malloc( 1024 );
  14480.                       setvbuf( fp, buf, _IOFBF, 1024 );
  14481.                     }
  14482.  
  14483. Classification: ANSI 
  14484.  
  14485.  
  14486. ΓòÉΓòÉΓòÉ 258. signal ΓòÉΓòÉΓòÉ
  14487.  
  14488. Synopsis: 
  14489.  
  14490.                     #include <signal.h>
  14491.                     void ( *signal(int sig, void (*func)(int)) )( int );
  14492.  
  14493. Description: The signal function is used to specify an action to take place 
  14494.           when certain conditions are detected while a program executes.  These 
  14495.           conditions are defined to be: 
  14496.  
  14497.    Condition     Meaning 
  14498.    SIGABRT       abnormal termination, such as caused by the abort function 
  14499.    SIGBREAK      an interactive attention (CTRL/BREAK on keyboard) is signalled 
  14500.    SIGFPE        an erroneous floating-point operation occurs (such as division 
  14501.                  by zero, overflow and underflow) 
  14502.    SIGILL        illegal instruction encountered 
  14503.    SIGINT        an interactive attention (CTRL/C on keyboard) is signalled 
  14504.    SIGSEGV       an illegal memory reference is detected 
  14505.    SIGTERM       a termination request is sent to the program 
  14506.    SIGUSR1       OS/2 process flag A via DosFlagProcess 
  14507.    SIGUSR2       OS/2 process flag B via DosFlagProcess 
  14508.    SIGUSR3       OS/2 process flag C via DosFlagProcess 
  14509.  
  14510.           An action can be specified for each of the above conditions, 
  14511.           depending upon the value of the func argument: 
  14512.  
  14513.    function  When func is a function name, that function will be called 
  14514.              equivalently to the following code sequence. 
  14515.  
  14516.                               /* "sig_no" is condition being signalled */
  14517.                               signal( sig_no, SIG_DFL );
  14518.                               (*func)( sig_no );
  14519.  
  14520.              The func function may terminate the program by calling the exit or 
  14521.              abort functions or call the longjmp function. Because the next 
  14522.              signal will be handled with default handling, the program must 
  14523.              again call signal if it is desired to handle the next condition of 
  14524.              the type that has been signalled. 
  14525.  
  14526.              After returning from the signal-catching function, the receiving 
  14527.              process will resume execution at the point at which it was 
  14528.              interrupted. 
  14529.  
  14530.              The signal catching function is described as follows: 
  14531.  
  14532.                               void func( int sig_no )
  14533.                               {
  14534.                                  .
  14535.                                  .
  14536.                                  .
  14537.                               }
  14538.  
  14539.              Since signal-catching functions are invoked asynchronously with 
  14540.              process execution, the type sig_atomic_t may be used to define 
  14541.              variables on which an atomic operation (e.g., incrementation, 
  14542.              decrementation) may be performed. 
  14543.  
  14544.    SIG_DFL   This value causes the default action for the condition to occur. 
  14545.  
  14546.    SIG_IGN   This value causes the indicated condition to be ignored. 
  14547.  
  14548.    SIG_ACK   Used in OS/2 to acknowledge the receipt of a signal.  Once a 
  14549.              process receives a given signal, the operating system will not 
  14550.              send any more signals of this type until it receives a SIG_ACK 
  14551.              acknowledgement back from the process. 
  14552.  
  14553.           When a condition is detected, it may be handled by a program, it may 
  14554.           be ignored, or it may be handled by the usual default action (often 
  14555.           causing an error message to be printed upon the stderr stream 
  14556.           followed by program termination). 
  14557.  
  14558.           When the program begins execution, the equivalent of 
  14559.  
  14560.                         signal( SIGABRT, SIG_IGN );
  14561.                         signal( SIGFPE, SIG_DFL );
  14562.                         signal( SIGILL, SIG_DFL );
  14563.                         signal( SIGINT, SIG_IGN );
  14564.                         signal( SIGSEGV, SIG_DFL );
  14565.                         signal( SIGTERM, SIG_DFL );
  14566.  
  14567.           is executed. 
  14568.  
  14569.           A condition can be generated by a program using the raise function. 
  14570.  
  14571. Returns:  A return value of SIG_ERR indicates that that the request could not 
  14572.           be handled, and errno is set to the value EINVAL. 
  14573.  
  14574.           Otherwise, the previous value of func for the indicated condition is 
  14575.           returned. 
  14576.  
  14577. See Also: raise 
  14578.  
  14579. Example: 
  14580.  
  14581.                     #include <signal.h>
  14582.  
  14583.                     sig_atomic_t signal_count;
  14584.  
  14585.                     void MyHandler( int sig_number )
  14586.                       {
  14587.                          ++signal_count;
  14588.                       }
  14589.  
  14590.                     void main()
  14591.                       {
  14592.                         signal( SIGFPE, MyHandler );   /* set own handler */
  14593.                         signal( SIGABRT, SIG_DFL );    /* Default action */
  14594.                         signal( SIGFPE, SIG_IGN );     /* Ignore condition */
  14595.                       }
  14596.  
  14597. Classification: ANSI 
  14598.  
  14599.  
  14600. ΓòÉΓòÉΓòÉ 259. sin ΓòÉΓòÉΓòÉ
  14601.  
  14602. Synopsis: 
  14603.  
  14604.                     #include <math.h>
  14605.                     double sin( double x );
  14606.  
  14607. Description: The sin function computes the sine of x (measured in radians).  A 
  14608.           large magnitude argument may yield a result with little or no 
  14609.           significance. 
  14610.  
  14611. Returns:  The sin function returns the sine value. 
  14612.  
  14613. See Also: acos, asin, atan, atan2, cos, tan 
  14614.  
  14615. Example: 
  14616.  
  14617.                     #include <stdio.h>
  14618.                     #include <math.h>
  14619.  
  14620.                     void main()
  14621.                       {
  14622.                         printf( "%f\n", sin(.5) );
  14623.                       }
  14624.  
  14625.           produces the following: 
  14626.  
  14627.                     0.479426
  14628.  
  14629. Classification: ANSI 
  14630.  
  14631.  
  14632. ΓòÉΓòÉΓòÉ 260. sinh ΓòÉΓòÉΓòÉ
  14633.  
  14634. Synopsis: 
  14635.  
  14636.                     #include <math.h>
  14637.                     double sinh( double x );
  14638.  
  14639. Description: The sinh function computes the hyperbolic sine of x. A range error 
  14640.           occurs if the magnitude of x is too large. 
  14641.  
  14642. Returns:  The sinh function returns the hyperbolic sine value.  When the 
  14643.           argument is outside the permissible range, the matherr function is 
  14644.           called.  Unless the default matherr function is replaced, it will set 
  14645.           the global variable errno to ERANGE, and print a "RANGE error" 
  14646.           diagnostic message using the stderr stream. 
  14647.  
  14648. See Also: cosh, tanh, matherr 
  14649.  
  14650. Example: 
  14651.  
  14652.                     #include <stdio.h>
  14653.                     #include <math.h>
  14654.  
  14655.                     void main()
  14656.                       {
  14657.                         printf( "%f\n", sinh(.5) );
  14658.                       }
  14659.  
  14660.           produces the following: 
  14661.  
  14662.                     0.521095
  14663.  
  14664. Classification: ANSI 
  14665.  
  14666.  
  14667. ΓòÉΓòÉΓòÉ 261. sleep ΓòÉΓòÉΓòÉ
  14668.  
  14669. Synopsis: 
  14670.  
  14671.                     #include <dos.h>
  14672.                     void sleep( unsigned seconds );
  14673.  
  14674. Description: The sleep function suspends execution by the specified number of 
  14675.           seconds. 
  14676.  
  14677. Returns:  The sleep function has no return value. 
  14678.  
  14679. See Also: delay 
  14680.  
  14681. Example: 
  14682.  
  14683.                     #include <dos.h>
  14684.  
  14685.                     void main()
  14686.                       {
  14687.                         sleep( 5 );  /* sleep for 5 seconds */
  14688.                       }
  14689.  
  14690. Classification: WATCOM 
  14691.  
  14692.  
  14693. ΓòÉΓòÉΓòÉ 262. sopen ΓòÉΓòÉΓòÉ
  14694.  
  14695. Synopsis: 
  14696.  
  14697.                     #include <io.h>
  14698.                     #include <fcntl.h>
  14699.                     #include <sys\stat.h>
  14700.                     #include <sys\types.h>
  14701.                     #include <share.h>
  14702.                     int sopen( const char *filename,
  14703.                                int access, int share, ... );
  14704.  
  14705. Description: The sopen function opens a file at the operating system level for 
  14706.           shared access.  The name of the file to be opened is given by 
  14707.           filename. The file will be accessed according to the access mode 
  14708.           specified by access. When the file is be created, the optional 
  14709.           argument must be given which establishes the future access 
  14710.           permissions for the file.  Additionally, the sharing mode of the file 
  14711.           is given by the share argument.  The optional argument is the file 
  14712.           permissions to be used when O_CREAT flag is on in the access mode. 
  14713.  
  14714.           The access mode is established a combination of the bits defined in 
  14715.           the <fcntl.h> header file.  The following bits may be set: 
  14716.  
  14717.    Mode          Meaning 
  14718.  
  14719.    O_RDONLY      permit the file to be only read. 
  14720.  
  14721.    O_WRONLY      permit the file to be only written. 
  14722.  
  14723.    O_RDWR        permit the file to be both read and written. 
  14724.  
  14725.    O_APPEND      causes each record that is written to be written at the end of 
  14726.                  the file. 
  14727.  
  14728.    O_CREAT       has no effect when the file indicated by filename already 
  14729.                  exists; otherwise, the file is created; 
  14730.  
  14731.    O_TRUNC       causes the file to be truncated to contain no data when the 
  14732.                  file exists; has no effect when the file does not exist. 
  14733.  
  14734.    O_BINARY      causes the file to be opened in binary mode which means that 
  14735.                  data will be transmitted to and from the file unchanged. 
  14736.  
  14737.    O_TEXT        causes the file to be opened in text mode which means that 
  14738.                  carriage-return characters are written before any linefeed 
  14739.                  character that is written and causes carriage-return 
  14740.                  characters to be removed when encountered during reads. 
  14741.  
  14742.           When neither O_TEXT nor O_BINARY are specified, the default value in 
  14743.           the global variable _fmode is used to set the file translation mode. 
  14744.           When the program begins execution, this variable has a value of 
  14745.           O_TEXT. 
  14746.  
  14747.           O_CREAT must be specified when the file does not exist and it is to 
  14748.           be written. 
  14749.  
  14750.           When the file is to be created (O_CREAT is specified), an additional 
  14751.           argument must be passed which contains the file permissions to be 
  14752.           used for the new file.  The access permissions for the file or 
  14753.           directory are specified as a combination of bits (defined in the 
  14754.           <sys\stat.h> header file). 
  14755.  
  14756.           The following bits define permissions for the owner. 
  14757.  
  14758.    Permission    Meaning 
  14759.    S_IRWXU       Read, write, execute/search 
  14760.    S_IRUSR       Read permission 
  14761.    S_IWUSR       Write permission 
  14762.    S_IXUSR       Execute/search permission 
  14763.  
  14764.           The following bits define permissions for the group. 
  14765.  
  14766.    Permission    Meaning 
  14767.    S_IRWXG       Read, write, execute/search 
  14768.    S_IRGRP       Read permission 
  14769.    S_IWGRP       Write permission 
  14770.    S_IXGRP       Execute/search permission 
  14771.  
  14772.           The following bits define permissions for others. 
  14773.  
  14774.    Permission    Meaning 
  14775.    S_IRWXO       Read, write, execute/search 
  14776.    S_IROTH       Read permission 
  14777.    S_IWOTH       Write permission 
  14778.    S_IXOTH       Execute/search permission 
  14779.  
  14780.           The following bits define miscellaneous permissions used by other 
  14781.           implementations. 
  14782.  
  14783.    Permission    Meaning 
  14784.    S_IREAD       is equivalent to S_IRUSR (read permission) 
  14785.    S_IWRITE      is equivalent to S_IWUSR (write permission) 
  14786.    S_IEXEC       is equivalent to S_IXUSR (execute/search permission) 
  14787.  
  14788.           All files are readable with DOS; however, it is a good idea to set 
  14789.           S_IREAD when read permission is intended for the file. 
  14790.  
  14791.           The sopen function applies the current file permission mask to the 
  14792.           specified permissions (see umask). 
  14793.  
  14794.           The shared access for the file, share, is established by a 
  14795.           combination of bits defined in the <share.h> header file.  The 
  14796.           following values may be set: 
  14797.  
  14798.    Value             Meaning 
  14799.    SH_COMPAT         Set compatibility mode. 
  14800.    SH_DENYRW         Prevent read or write access to the file. 
  14801.    SH_DENYWR         Prevent write access of the file. 
  14802.    SH_DENYRD         Prevent read access to the file. 
  14803.    SH_DENYNO         Permit both read and write access to the file. 
  14804.  
  14805.           You should consult the technical documentation for the DOS system 
  14806.           that you are using for more detailed information about these sharing 
  14807.           modes. 
  14808.  
  14809. Returns:  The sopen function returns the file handle for the file. When an 
  14810.           error is detected, -1 is returned.  When an error has occurred, errno 
  14811.           contains a value indicating the type of error that has been detected. 
  14812.  
  14813. See Also: close, creat, dup, dup2, eof, exec Functions, filelength, fileno, 
  14814.           fstat, isatty, lseek, open, read, setmode, stat, tell, write, umask 
  14815.  
  14816. Classification: WATCOM 
  14817.  
  14818.  
  14819. ΓòÉΓòÉΓòÉ 263. sound ΓòÉΓòÉΓòÉ
  14820.  
  14821. Synopsis: 
  14822.  
  14823.                     #include <dos.h>
  14824.                     void sound( unsigned frequency );
  14825.  
  14826. Description: The sound function turns on the PC's speaker at the specified 
  14827.           frequency. The frequency is in Hertz (cycles per second).  The 
  14828.           speaker can be turned off by calling the function nosound after an 
  14829.           appropriate amount of time. 
  14830.  
  14831. Returns:  The sound function has no return value. 
  14832.  
  14833. See Also: delay, nosound 
  14834.  
  14835. Example: 
  14836.  
  14837.                     #include <dos.h>
  14838.  
  14839.                     /*
  14840.                         The numbers in this table are the timer divisors
  14841.                         necessary to produce the pitch indicated in the
  14842.                         lowest octave that is supported by the "sound"
  14843.                         function.
  14844.  
  14845.                         To raise the pitch by N octaves, simply divide the
  14846.                         number in the table by 2**N since a pitch which is
  14847.                         an octave above another has double the frequency of
  14848.                         the original pitch.
  14849.  
  14850.                         The frequency obtained by these numbers is given by
  14851.                         1193180 / X where X is the number obtained in the
  14852.                         table.
  14853.                     */
  14854.                     unsigned short Notes[] = {
  14855.                             19327 ,        /* C b            */
  14856.                             18242 ,        /* C              */
  14857.                             17218 ,        /* C #   ( D b )  */
  14858.                             16252 ,        /* D              */
  14859.                             15340 ,        /* D #   ( E b )  */
  14860.                             14479 ,        /* E     ( F b )  */
  14861.                             13666 ,        /* F     ( E # )  */
  14862.                             12899 ,        /* F #   ( G b )  */
  14863.                             12175 ,        /* G              */
  14864.                             11492 ,        /* G #   ( A b )  */
  14865.                             10847 ,        /* A              */
  14866.                             10238 ,        /* A #   ( B b )  */
  14867.                             9664 ,         /* B     ( C b )  */
  14868.                             9121 ,         /* B #            */
  14869.                             0
  14870.                     };
  14871.                     #define FACTOR  1193180
  14872.                     #define OCTAVE  4
  14873.  
  14874.                     void main()             /* play the scale */
  14875.                       {
  14876.                         int i;
  14877.                         for( i = 0; Notes[i]; ++i ) {
  14878.                           sound( FACTOR / (Notes[i] / (1 << OCTAVE)) );
  14879.                           delay( 200 );
  14880.                           nosound();
  14881.                         }
  14882.                       }
  14883.  
  14884. Classification: Intel 
  14885.  
  14886.  
  14887. ΓòÉΓòÉΓòÉ 264. spawn Functions ΓòÉΓòÉΓòÉ
  14888.  
  14889. Synopsis: 
  14890.  
  14891.                     #include <process.h>
  14892.                     int spawnl(   mode, pgm, arg0, arg1..., argn, NULL );
  14893.                     int spawnle(  mode, pgm, arg0, arg1..., argn, NULL, envp);
  14894.                     int spawnlp(  mode, pgm, arg0, arg1..., argn, NULL );
  14895.                     int spawnlpe( mode, pgm, arg0, arg1..., argn, NULL, envp);
  14896.                     int spawnv(   mode, pgm, argv );
  14897.                     int spawnve(  mode, pgm, argv, envp );
  14898.                     int spawnvp(  mode, pgm, argv );
  14899.  
  14900.                     int spawnvpe( mode, pgm, argv, envp );
  14901.                        int         mode;             /* mode for parent    */
  14902.                        const char *pgm;              /* name of file       */
  14903.                        const char *arg0, ..., *argn; /* arguments          */
  14904.                        const char *argv[];           /* array of arguments */
  14905.                        const char *envp[];           /* environment strings*/
  14906.  
  14907. Description: The spawn functions create and execute a new child process, named 
  14908.           by pgm. The value of mode determines how the program is loaded and 
  14909.           how the invoking program will behave after the invoked program is 
  14910.           initiated: 
  14911.  
  14912.    Mode      Meaning 
  14913.  
  14914.    P_WAIT    The invoked program is loaded into available memory, is executed, 
  14915.              and then the original program resumes execution. 
  14916.  
  14917.    P_NOWAIT  Causes the current program to execute concurrently with the new 
  14918.              child process. 
  14919.  
  14920.    P_NOWAITO Causes the current program to execute concurrently with the new 
  14921.              child process.  The functions wait and cwait are ignored. 
  14922.  
  14923.    P_OVERLAY The invoked program replaces the original program in memory and is 
  14924.              executed. No return is made to the original program.  This is 
  14925.              equivalent to calling the appropriate exec function.  P_OVERLAY is 
  14926.              only supported on those systems that also support the exec 
  14927.              function (see the description of the exec function for more 
  14928.              information). 
  14929.  
  14930.           The program is located by using the following logic in sequence: 
  14931.  
  14932.     1. An attempt is made to locate the program in the current working 
  14933.        directory if no directory specification precedes the program name; 
  14934.        otherwise, an attempt is made in the specified directory. 
  14935.  
  14936.     2. If no file extension is given, an attempt is made to find the program 
  14937.        name, in the directory indicated in the first point, with .COM 
  14938.        concatenated to the end of the program name. 
  14939.  
  14940.     3. If no file extension is given, an attempt is made to find the program 
  14941.        name, in the directory indicated in the first point, with .EXE 
  14942.        concatenated to the end of the program name. 
  14943.  
  14944.     4. When no directory specification is given as part of the program name, 
  14945.        the spawnlp, spawnlpe, spawnvp, and spawnvpe functions will repeat the 
  14946.        preceding three steps for each of the directories specified by the PATH 
  14947.        environment variable.  The command 
  14948.  
  14949.               path c:\myapps;d:\lib\applns
  14950.  
  14951.        indicates that the two directories 
  14952.  
  14953.               c:\myapps
  14954.               d:\lib\applns
  14955.  
  14956.        are to be searched.  The DOS path command (without any directory 
  14957.        specification) will cause the current path definition to be displayed. 
  14958.  
  14959.           An error is detected when the program cannot be found. 
  14960.  
  14961.           Arguments are passed to the child process by supplying one or more 
  14962.           pointers to character strings as arguments in the spawn call.  These 
  14963.           character strings are concatenated with spaces inserted to separate 
  14964.           the arguments to form one argument string for the child process.  The 
  14965.           length of this concatenated string must not exceed 128 bytes for DOS 
  14966.           systems. 
  14967.  
  14968.           The arguments may be passed as a list of arguments (spawnl, spawnle, 
  14969.           spawnlp and spawnlpe) or as a vector of pointers (spawnv, spawnve, 
  14970.           spawnvp, and spawnvpe).  At least one argument, arg0 or argv[0] , 
  14971.           must be passed to the child process.  By convention, this first 
  14972.           argument is a pointer to the name of the program. 
  14973.  
  14974.           If the arguments are passed as a list, there must be a NULL pointer 
  14975.           to mark the end of the argument list.  Similarly, if a pointer to an 
  14976.           argument vector is passed, the argument vector must be terminated by 
  14977.           a NULL pointer. 
  14978.  
  14979.           The environment for the invoked program is inherited from the parent 
  14980.           process when you use the spawnl, spawnlp, spawnv and spawnvp 
  14981.           functions.  The spawnle, spawnlpe, spawnve and spawnvpe functions 
  14982.           allow a different environment to be passed to the child process 
  14983.           through the envp argument.  The argument envp is a pointer to an 
  14984.           array of character pointers, each of which points to a string 
  14985.           defining an environment variable.  The array is terminated with a 
  14986.           NULL pointer.  Each pointer locates a character string of the form 
  14987.  
  14988.                         variable=value
  14989.  
  14990.           that is used to define an environment variable.  If the value of envp 
  14991.           is NULL , then the child process inherits the environment of the 
  14992.           parent process. 
  14993.  
  14994.           The environment is the collection of environment variables whose 
  14995.           values that have been defined with the DOS SET command or by the 
  14996.           successful execution of the putenv function.  A program may read 
  14997.           these values with the getenv function. 
  14998.  
  14999. Returns:  When the value of mode is P_WAIT, then the return value from spawn is 
  15000.           the exit status of the child process. 
  15001.  
  15002.           When the value of mode is P_NOWAIT or P_NOWAITO, then the return 
  15003.           value from spawn is the process id of the child process.  To obtain 
  15004.           the exit code for a process spawned with P_NOWAIT, you must call the 
  15005.           wait or cwait function specifying the process id. The exit code 
  15006.           cannot be obtained for a process spawned with P_NOWAITO. 
  15007.  
  15008.           When an error is detected while invoking the indicated program, spawn 
  15009.           returns -1 and errno is set to indicate the error. 
  15010.  
  15011. Errors:   When an error has occurred, errno contains a value indicating the 
  15012.           type of error that has been detected. 
  15013.  
  15014.    Constant  Meaning 
  15015.  
  15016.    E2BIG     The argument list exceeds 128 bytes, or the space required for the 
  15017.              environment information exceeds 32K. 
  15018.  
  15019.    EINVAL    The mode argument is invalid. 
  15020.  
  15021.    ENOENT    Path or file not found 
  15022.  
  15023.    ENOMEM    Not enough memory is available to execute the child process. 
  15024.  
  15025. See Also: abort, atexit, cwait, exec Functions, exit, _exit, getcmd, getenv, 
  15026.           main, putenv, system, wait 
  15027.  
  15028. Example: 
  15029.  
  15030.                     #include <stddef.h>
  15031.                     #include <process.h>
  15032.  
  15033.                     spawnl( P_WAIT, "myprog",
  15034.                             "myprog", "ARG1", "ARG2", NULL );
  15035.  
  15036.           The preceding invokes "myprog" as if 
  15037.  
  15038.                     myprog ARG1 ARG2
  15039.  
  15040.           had been entered as a command to DOS.  The program will be found if 
  15041.           one of 
  15042.  
  15043.                     myprog.
  15044.                     myprog.com
  15045.                     myprog.exe
  15046.  
  15047.           is found in the current working directory. 
  15048.  
  15049.                     #include <stddef.h>
  15050.                     #include <process.h>
  15051.  
  15052.                     char *env_list[] = { "SOURCE=MYDATA",
  15053.                                          "TARGET=OUTPUT",
  15054.                                          "lines=65",
  15055.                                          NULL
  15056.                                         };
  15057.  
  15058.                     spawnle( P_WAIT, "myprog",
  15059.                             "myprog", "ARG1", "ARG2", NULL,
  15060.                              env_list );
  15061.  
  15062.           The preceding invokes "myprog" as if 
  15063.  
  15064.                     myprog ARG1 ARG2
  15065.  
  15066.           had been entered as a command to DOS.  The program will be found if 
  15067.           one of 
  15068.  
  15069.                     myprog.
  15070.                     myprog.com
  15071.                     myprog.exe
  15072.  
  15073.           is found in the current working directory.  The DOS environment for 
  15074.           the invoked program will consist of the three environment variables 
  15075.           SOURCE, TARGET and lines. 
  15076.  
  15077.                     #include <stddef.h>
  15078.                     #include <process.h>
  15079.  
  15080.                     char *arg_list[] = { "myprog", "ARG1", "ARG2", NULL };
  15081.  
  15082.                     spawnv( P_WAIT, "myprog", arg_list );
  15083.  
  15084.           The preceding invokes "myprog" as if 
  15085.  
  15086.                     myprog ARG1 ARG2
  15087.  
  15088.           had been entered as a command to DOS.  The program will be found if 
  15089.           one of 
  15090.  
  15091.                     myprog.
  15092.                     myprog.com
  15093.                     myprog.exe
  15094.  
  15095.           is found in the current working directory. 
  15096.  
  15097. Classification: WATCOM 
  15098.  
  15099.  
  15100. ΓòÉΓòÉΓòÉ 265. _splitpath ΓòÉΓòÉΓòÉ
  15101.  
  15102. Synopsis: 
  15103.  
  15104.                     #include <stdlib.h>
  15105.                     void _splitpath( const char *path,
  15106.                                            char *drive,
  15107.                                            char *dir,
  15108.                                            char *fname,
  15109.                                            char *ext );
  15110.  
  15111. Description: The _splitpath function splits up a full pathname into four 
  15112.           components consisting of a drive letter, directory path, file name 
  15113.           and file name extension.  The argument path points to a buffer 
  15114.           containing the full pathname to be split up. 
  15115.  
  15116.           The maximum size required for each buffer is specified by the 
  15117.           manifest constants _MAX_PATH, _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and 
  15118.           _MAX_EXT which are defined in <stdlib.h>. 
  15119.  
  15120.    drive     The drive argument points to a buffer that will be filled in with 
  15121.              the drive letter (A, B, C, etc.) followed by a colon if a drive is 
  15122.              specified in the full pathname. 
  15123.  
  15124.    dir       The dir argument points to a buffer that will be filled in with 
  15125.              the pathname including the trailing slash.  Either forward slashes 
  15126.              (/) or backslashes (\) may be used. 
  15127.  
  15128.    fname     The fname argument points to a buffer that will be filled in with 
  15129.              the base name of the file without any extension (suffix). 
  15130.  
  15131.    ext       The ext argument points to a buffer that will be filled in with 
  15132.              the filename extension or suffix including the leading period. 
  15133.  
  15134.           The arguments drive, dir, fname and ext will not be filled in if they 
  15135.           are NULL pointers. 
  15136.  
  15137.           For each component of the full pathname that is not present, its 
  15138.           corresponding buffer will be set to an empty string. 
  15139.  
  15140. Returns:  The _splitpath function returns no value. 
  15141.  
  15142. See Also: _fullpath, _makepath 
  15143.  
  15144. Example: 
  15145.  
  15146.                     #include <stdio.h>
  15147.                     #include <stdlib.h>
  15148.  
  15149.                     void main()
  15150.                       {
  15151.                         char full_path[ _MAX_PATH ];
  15152.                         char drive[ _MAX_DRIVE ];
  15153.                         char dir[ _MAX_DIR ];
  15154.                         char fname[ _MAX_FNAME ];
  15155.                         char ext[ _MAX_EXT ];
  15156.  
  15157.                         _makepath(full_path,"c","watcomc\\h\\","stdio","h");
  15158.                         printf( "Full path is: %s\n\n", full_path );
  15159.                         _splitpath( full_path, drive, dir, fname, ext );
  15160.                         printf( "Components after _splitpath\n" );
  15161.                         printf( "drive: %s\n", drive );
  15162.                         printf( "dir:   %s\n", dir );
  15163.                         printf( "fname: %s\n", fname );
  15164.                         printf( "ext:   %s\n", ext );
  15165.                       }
  15166.  
  15167.           produces the following: 
  15168.  
  15169.                     Full path is: c:watcomc\h\stdio.h
  15170.  
  15171.                     Components after _splitpath
  15172.                     drive: c:
  15173.                     dir:   watcomc\h\
  15174.                     fname: stdio
  15175.                     ext:   .h
  15176.  
  15177.           Note the use of two adjacent backslash characters (\) within 
  15178.           character-string constants to signify a single backslash. 
  15179.  
  15180.  
  15181. Classification: WATCOM 
  15182.  
  15183.  
  15184. ΓòÉΓòÉΓòÉ 266. sprintf ΓòÉΓòÉΓòÉ
  15185.  
  15186. Synopsis: 
  15187.  
  15188.                     #include <stdio.h>
  15189.                     int sprintf( char *buf, const char *format, ... );
  15190.  
  15191. Description: The sprintf function is equivalent to the fprintf function, except 
  15192.           that the argument buf specifies a character array into which the 
  15193.           generated output is placed, rather than to a file.  A null character 
  15194.           is placed at the end of the generated character string.  The format 
  15195.           string is described under the description of the printf function. 
  15196.  
  15197. Returns:  The sprintf function returns the number of characters written into 
  15198.           the array, not counting the terminating null character.  An error can 
  15199.           occur while converting a value for output.  When an error has 
  15200.           occurred, errno contains a value indicating the type of error that 
  15201.           has been detected. 
  15202.  
  15203. See Also: cprintf, fprintf, printf, vfprintf, vprintf, vsprintf 
  15204.  
  15205. Example: 
  15206.  
  15207.           To create a temporary file name using a counter: 
  15208.  
  15209.                     #include <stdio.h>
  15210.  
  15211.                     char namebuf[13];
  15212.                     int  TempCount = 0;
  15213.  
  15214.                     char *make_temp_name()
  15215.                       {
  15216.                         sprintf( namebuf, "ZZ%.6o.TMP", TempCount++ );
  15217.                         return( namebuf );
  15218.                       }
  15219.  
  15220.  
  15221. Classification: ANSI 
  15222.  
  15223.  
  15224. ΓòÉΓòÉΓòÉ 267. sqrt ΓòÉΓòÉΓòÉ
  15225.  
  15226. Synopsis: 
  15227.  
  15228.                     #include <math.h>
  15229.                     double sqrt( double x );
  15230.  
  15231. Description: The sqrt function computes the non-negative square root of x. A 
  15232.           domain error occurs if the argument is negative. 
  15233.  
  15234. Returns:  The sqrt function returns the value of the square root. When the 
  15235.           argument is outside the permissible range, the matherr function is 
  15236.           called.  Unless the default matherr function is replaced, it will set 
  15237.           the global variable errno to EDOM, and print a "DOMAIN error" 
  15238.           diagnostic message using the stderr stream. 
  15239.  
  15240. See Also: exp, log, pow, matherr 
  15241.  
  15242. Example: 
  15243.  
  15244.                     #include <stdio.h>
  15245.                     #include <math.h>
  15246.  
  15247.                     void main()
  15248.                       {
  15249.                         printf( "%f\n", sqrt(.5) );
  15250.                       }
  15251.  
  15252.           produces the following: 
  15253.  
  15254.                     0.707107
  15255.  
  15256. Classification: ANSI 
  15257.  
  15258.  
  15259. ΓòÉΓòÉΓòÉ 268. srand ΓòÉΓòÉΓòÉ
  15260.  
  15261. Synopsis: 
  15262.  
  15263.                     #include <stdlib.h>
  15264.                     void srand( unsigned int seed );
  15265.  
  15266. Description: The srand function uses the argument seed to start a new sequence 
  15267.           of pseudo-random integers to be returned by subsequent calls to rand. 
  15268.           A particular sequence of pseudo-random integers can be repeated by 
  15269.           calling srand with the same seed value.  The default sequence of 
  15270.           pseudo-random integers is selected with a seed value of 1. 
  15271.  
  15272. Returns:  The srand function returns no value. 
  15273.  
  15274. See Also: rand 
  15275.  
  15276. Example: 
  15277.  
  15278.                     #include <stdio.h>
  15279.                     #include <stdlib.h>
  15280.  
  15281.                     void main()
  15282.                       {
  15283.                         int i;
  15284.  
  15285.                         srand( 982 );
  15286.                         for( i = 1; i < 10; ++i ) {
  15287.                             printf( "%d\n", rand() );
  15288.                         }
  15289.                         srand( 982 );  /* start sequence over again */
  15290.                         for( i = 1; i < 10; ++i ) {
  15291.                             printf( "%d\n", rand() );
  15292.                         }
  15293.                       }
  15294.  
  15295. Classification: ANSI 
  15296.  
  15297.  
  15298. ΓòÉΓòÉΓòÉ 269. sscanf ΓòÉΓòÉΓòÉ
  15299.  
  15300. Synopsis: 
  15301.  
  15302.                     #include <stdio.h>
  15303.                     int sscanf( const char *in_string,
  15304.                                 const char *format, ... );
  15305.  
  15306. Description: The sscanf function scans input from the character string 
  15307.           in_string under control of the argument format. Following the format 
  15308.           string is the list of addresses of items to receive values. 
  15309.  
  15310.           The format string is described under the description of the scanf 
  15311.           function. 
  15312.  
  15313. Returns:  The sscanf function returns EOF when the scanning is terminated by 
  15314.           reaching the end of the input string.  Otherwise, the number of input 
  15315.           arguments for which values were successfully scanned and stored is 
  15316.           returned. 
  15317.  
  15318. See Also: fscanf, scanf, vsscanf 
  15319.  
  15320. Example: 
  15321.  
  15322.           To scan the date in the form "Saturday April 18 1987": 
  15323.  
  15324.                     #include <stdio.h>
  15325.  
  15326.                     void main()
  15327.                       {
  15328.                         int day, year;
  15329.                         char weekday[20], month[20];
  15330.  
  15331.                         sscanf( "Friday August 0014 1987",
  15332.                                 "%s %s %d  %d",
  15333.                                  &weekday, &month, &day, &year );
  15334.                         printf( "%s %s %d %d\n",
  15335.                                  weekday, month, day, year );
  15336.                       }
  15337.  
  15338.           produces the following: 
  15339.  
  15340.                     Friday August 14 1987
  15341.  
  15342. Classification: ANSI 
  15343.  
  15344.  
  15345. ΓòÉΓòÉΓòÉ 270. stackavail ΓòÉΓòÉΓòÉ
  15346.  
  15347. Synopsis: 
  15348.  
  15349.                     #include <malloc.h>
  15350.                     size_t stackavail(void);
  15351.  
  15352. Description: The stackavail function returns the number of bytes currently 
  15353.           available in the stack.  This value is usually used to determine an 
  15354.           appropriate amount to allocate using alloca. 
  15355.  
  15356. Returns:  The stackavail function returns the number of bytes currently 
  15357.           available in the stack. 
  15358.  
  15359. See Also: alloca, calloc Functions, malloc Functions 
  15360.  
  15361. Example: 
  15362.  
  15363.                     #include <stdio.h>
  15364.                     #include <string.h>
  15365.                     #include <malloc.h>
  15366.  
  15367.                     long char_count( FILE *fp )
  15368.                       {
  15369.                          char *buffer;
  15370.                          size_t bufsiz;
  15371.                          long count;
  15372.  
  15373.                          /* allocate half of stack for temp buffer */
  15374.                          bufsiz = stackavail() >> 1;
  15375.                          buffer = alloca( bufsiz );
  15376.                          setvbuf( fp, buffer, _IOFBF, bufsiz );
  15377.                          count = 0L;
  15378.                          while( fgetc( fp ) != EOF ) ++count;
  15379.                          fclose( fp );
  15380.                          return( count );
  15381.                       }
  15382.  
  15383. Classification: WATCOM 
  15384.  
  15385.  
  15386. ΓòÉΓòÉΓòÉ 271. stat ΓòÉΓòÉΓòÉ
  15387.  
  15388. Synopsis: 
  15389.  
  15390.                     #include <sys\stat.h>
  15391.                     int stat( const char *path, struct stat *buf );
  15392.  
  15393. Description: The stat function obtains information about the file or directory 
  15394.           referenced in path. This information is placed in the structure 
  15395.           located at the address indicated by buf. 
  15396.  
  15397.           The file <sys\stat.h> contains definitions for the structure stat. 
  15398.  
  15399.                     struct stat {
  15400.                        dev_t   st_dev;    /* disk drive file resides on */
  15401.                        ino_t   st_ino;    /* this inode's number        */
  15402.                        unsigned short st_mode; /* file mode             */
  15403.                        short   st_nlink;  /* # of hard links            */
  15404.                        short   st_uid;    /* user-id, always 'root'     */
  15405.                        short   st_gid;    /* group-id, always 'root'    */
  15406.                        dev_t   st_rdev;   /* drive #, same as st_dev    */
  15407.                        off_t   st_size;   /* total file size            */
  15408.                        time_t  st_atime;  /* time of last access        */
  15409.                        time_t  st_mtime;  /* time of last modification  */
  15410.                        time_t  st_ctime;  /* time of last status change */
  15411.                     };
  15412.  
  15413.  
  15414. Returns:  The stat function returns zero when the information is successfully 
  15415.           obtained.  Otherwise, -1 is returned. 
  15416.  
  15417. Errors:   When an error has occurred, errno contains a value indicating the 
  15418.           type of error that has been detected. 
  15419.  
  15420.    EACCES    Search permission is denied for a component of path. 
  15421.  
  15422. See Also: fstat 
  15423.  
  15424. Example: 
  15425.  
  15426.                     #include <stdio.h>
  15427.                     #include <sys\stat.h>
  15428.  
  15429.                     void main()
  15430.                       {
  15431.                         struct stat buf;
  15432.  
  15433.                         if( stat( "file", &buf ) != -1 ) {
  15434.                           printf( "File size = %d\n", buf.st_size );
  15435.                         }
  15436.                       }
  15437.  
  15438. Classification: POSIX 1003.1 
  15439.  
  15440.  
  15441. ΓòÉΓòÉΓòÉ 272. _status87 ΓòÉΓòÉΓòÉ
  15442.  
  15443. Synopsis: 
  15444.  
  15445.                     #include <float.h>
  15446.                     unsigned int _status87( void );
  15447.  
  15448. Description: The _status87 function returns the floating-point status word 
  15449.           which is used to record the status of 8087/80287/80387/80486 
  15450.           floating-point operations. 
  15451.  
  15452. Returns:  The _status87 function returns the floating-point status word which 
  15453.           is used to record the status of 8087/80287/80387/80486 floating-point 
  15454.           operations.  The description of this status is found in the <float.h> 
  15455.           header file. 
  15456.  
  15457. See Also: _clear87, _control87, _fpreset 
  15458.  
  15459. Example: 
  15460.  
  15461.                     #include <stdio.h>
  15462.                     #include <float.h>
  15463.                     char *status[2] = { "No", "  " };
  15464.                     void main()
  15465.                       {
  15466.                         unsigned int fp_status;
  15467.                         fp_status = _status87();
  15468.                         printf( "80x87 status\n" );
  15469.                         printf( "%s invalid operation\n",
  15470.                                 status[ (fp_status & SW_INVALID) == 0 ] );
  15471.                         printf( "%s denormalized operand\n",
  15472.                                 status[ (fp_status & SW_DENORMAL) == 0 ] );
  15473.                         printf( "%s divide by zero\n",
  15474.                                 status[ (fp_status & SW_ZERODIVIDE) == 0 ] );
  15475.                         printf( "%s overflow\n",
  15476.                                 status[ (fp_status & SW_OVERFLOW) == 0 ] );
  15477.                         printf( "%s underflow\n",
  15478.                                 status[ (fp_status & SW_UNDERFLOW) == 0 ] );
  15479.                         printf( "%s inexact result\n",
  15480.                                 status[ (fp_status & SW_INEXACT) == 0 ] );
  15481.                       }
  15482.  
  15483. Classification: Intel 
  15484.  
  15485.  
  15486. ΓòÉΓòÉΓòÉ 273. strcat, _fstrcat ΓòÉΓòÉΓòÉ
  15487.  
  15488. Synopsis: 
  15489.  
  15490.                     #include <string.h>
  15491.                     char *strcat( char *dst, const char *src );
  15492.                     char __far *_fstrcat( char __far *dst,
  15493.                                           const char __far *src );
  15494.  
  15495. Description: The strcat and _fstrcat functions append a copy of the string 
  15496.           pointed to by src (including the terminating null character) to the 
  15497.           end of the string pointed to by dst. The first character of src 
  15498.           overwrites the null character at the end of dst. 
  15499.  
  15500.           The _fstrcat function is a data model independent form of the strcat 
  15501.           function.  It accepts far pointer arguments and returns a far 
  15502.           pointer.  It is most useful in mixed memory model applications. 
  15503.  
  15504. Returns:  The value of dst is returned. 
  15505.  
  15506. See Also: strncat 
  15507.  
  15508. Example: 
  15509.  
  15510.                     #include <stdio.h>
  15511.                     #include <string.h>
  15512.  
  15513.                     void main()
  15514.                       {
  15515.                         char buffer[80];
  15516.  
  15517.                         strcpy( buffer, "Hello " );
  15518.                         strcat( buffer, "world" );
  15519.                         printf( "%s\n", buffer );
  15520.                       }
  15521.  
  15522.           produces the following: 
  15523.  
  15524.                     Hello world
  15525.  
  15526. Classification: strcat is ANSI, _fstrcat is not ANSI 
  15527.  
  15528.  
  15529. ΓòÉΓòÉΓòÉ 274. strchr, _fstrchr ΓòÉΓòÉΓòÉ
  15530.  
  15531. Synopsis: 
  15532.  
  15533.                     #include <string.h>
  15534.                     char *strchr( const char *s, int c );
  15535.                     char __far *_fstrchr( const char __far *s, int c );
  15536.  
  15537. Description: The strchr and _fstrchr functions locate the first occurrence of c 
  15538.           (converted to a char) in the string pointed to by s. The terminating 
  15539.           null character is considered to be part of the string. 
  15540.  
  15541.           The _fstrchr function is a data model independent form of the strchr 
  15542.           function.  It accepts far pointer arguments and returns a far 
  15543.           pointer.  It is most useful in mixed memory model applications. 
  15544.  
  15545. Returns:  The strchr and _fstrchr functions return a pointer to the located 
  15546.           character, or NULL if the character does not occur in the string. 
  15547.  
  15548. See Also: memchr, strcspn, strrchr, strspn, strstr, strtok 
  15549.  
  15550. Example: 
  15551.  
  15552.                     #include <stdio.h>
  15553.                     #include <string.h>
  15554.  
  15555.                     void main()
  15556.                       {
  15557.                         char buffer[80];
  15558.                         char *where;
  15559.  
  15560.                         strcpy( buffer, "video x-rays" );
  15561.                         where = strchr( buffer, 'x' );
  15562.                         if( where == NULL ) {
  15563.                             printf( "'x' not found\n" );
  15564.                         }
  15565.                       }
  15566.  
  15567. Classification: strchr is ANSI, _fstrchr is not ANSI 
  15568.  
  15569.  
  15570. ΓòÉΓòÉΓòÉ 275. strcmp, _fstrcmp ΓòÉΓòÉΓòÉ
  15571.  
  15572. Synopsis: 
  15573.  
  15574.                     #include <string.h>
  15575.                     int strcmp( const char *s1, const char *s2 );
  15576.                     int _fstrcmp( const char __far *s1,
  15577.                                   const char __far *s2 );
  15578.  
  15579. Description: The strcmp and _fstrcmp functions compare the string pointed to by 
  15580.           s1 to the string pointed to by s2. 
  15581.  
  15582.           The _fstrcmp function is a data model independent form of the strcmp 
  15583.           function that accepts far pointer arguments.  It is most useful in 
  15584.           mixed memory model applications. 
  15585.  
  15586. Returns:  The strcmp and _fstrcmp functions return an integer less than, equal 
  15587.           to, or greater than zero, indicating that the string pointed to by s1 
  15588.           is less than, equal to, or greater than the string pointed to by s2. 
  15589.  
  15590. See Also: stricmp, strncmp, strnicmp 
  15591.  
  15592. Example: 
  15593.  
  15594.                     #include <stdio.h>
  15595.                     #include <string.h>
  15596.  
  15597.                     void main()
  15598.                       {
  15599.                         printf( "%d\n", strcmp( "abcdef", "abcdef" ) );
  15600.                         printf( "%d\n", strcmp( "abcdef", "abc" ) );
  15601.                         printf( "%d\n", strcmp( "abc", "abcdef" ) );
  15602.                         printf( "%d\n", strcmp( "abcdef", "mnopqr" ) );
  15603.                         printf( "%d\n", strcmp( "mnopqr", "abcdef" ) );
  15604.                       }
  15605.  
  15606.           produces the following: 
  15607.  
  15608.                     0
  15609.                     1
  15610.                     -1
  15611.                     -1
  15612.                     1
  15613.  
  15614. Classification: strcmp is ANSI, _fstrcmp is not ANSI 
  15615.  
  15616.  
  15617. ΓòÉΓòÉΓòÉ 276. strcmpi ΓòÉΓòÉΓòÉ
  15618.  
  15619. Synopsis: 
  15620.  
  15621.                     #include <string.h>
  15622.                     int strcmpi( const char *s1, const char *s2 );
  15623.  
  15624. Description: The strcmpi function compares, with case insensitivity, the string 
  15625.           pointed to by s1 to the string pointed to by s2. All upper-case 
  15626.           characters from s1 and s2 are mapped to lower-case for the purposes 
  15627.           of doing the comparison.  The strcmpi function is identical to the 
  15628.           stricmp function. 
  15629.  
  15630. Returns:  The strcmpi function returns an integer less than, equal to, or 
  15631.           greater than zero, indicating that the string pointed to by s1 is 
  15632.           less than, equal to, or greater than the string pointed to by s2. 
  15633.  
  15634. See Also: strcmp, stricmp, strncmp, strnicmp 
  15635.  
  15636. Example: 
  15637.  
  15638.                     #include <stdio.h>
  15639.                     #include <string.h>
  15640.  
  15641.                     void main()
  15642.                       {
  15643.                         printf( "%d\n", strcmpi( "AbCDEF", "abcdef" ) );
  15644.                         printf( "%d\n", strcmpi( "abcdef", "ABC"    ) );
  15645.                         printf( "%d\n", strcmpi( "abc",    "ABCdef" ) );
  15646.                         printf( "%d\n", strcmpi( "Abcdef", "mnopqr" ) );
  15647.                         printf( "%d\n", strcmpi( "Mnopqr", "abcdef" ) );
  15648.                       }
  15649.  
  15650.           produces the following: 
  15651.  
  15652.                     0
  15653.                     100
  15654.                     -100
  15655.                     -12
  15656.                     12
  15657.  
  15658. Classification: WATCOM 
  15659.  
  15660.  
  15661. ΓòÉΓòÉΓòÉ 277. strcoll ΓòÉΓòÉΓòÉ
  15662.  
  15663. Synopsis: 
  15664.  
  15665.                     #include <string.h>
  15666.                     int strcoll( const char *s1,
  15667.                                  const char *s2 );
  15668.  
  15669. Description: The strcoll function compares the string pointed to by s1 to the 
  15670.           string pointed to by s2. The comparison uses the collating sequence 
  15671.           selected by the setlocale function.  The function will be equivalent 
  15672.           to the strcmp function when the collating sequence is selected from 
  15673.           the "C" locale. 
  15674.  
  15675. Returns:  The strcoll function returns an integer less than, equal to, or 
  15676.           greater than zero, indicating that the string pointed to by s1 is 
  15677.           less than, equal to, or greater than the string pointed to by s2, 
  15678.           according to the collating sequence selected. 
  15679.  
  15680. See Also: setlocale, strncmp 
  15681.  
  15682. Example: 
  15683.  
  15684.                     #include <stdio.h>
  15685.                     #include <string.h>
  15686.  
  15687.                     char buffer[80] = "world";
  15688.  
  15689.                     void main()
  15690.                       {
  15691.                         if( strcoll( buffer, "Hello" ) < 0 ) {
  15692.                             printf( "Less than\n" );
  15693.                         }
  15694.                       }
  15695.  
  15696. Classification: ANSI 
  15697.  
  15698.  
  15699. ΓòÉΓòÉΓòÉ 278. strcpy, _fstrcpy ΓòÉΓòÉΓòÉ
  15700.  
  15701. Synopsis: 
  15702.  
  15703.                     #include <string.h>
  15704.                     char *strcpy( char *dst, const char *src );
  15705.                     char __far *_fstrcpy( char __far *dst,
  15706.                                           const char __far *src );
  15707.  
  15708. Description: The strcpy and _fstrcpy functions copy the string pointed to by 
  15709.           src (including the terminating null character) into the array pointed 
  15710.           to by dst. Copying of overlapping objects is not guaranteed to work 
  15711.           properly.  See the description for the memmove function to copy 
  15712.           objects that overlap. 
  15713.  
  15714.           The _fstrcpy function is a data model independent form of the strcpy 
  15715.           function.  It accepts far pointer arguments and returns a far 
  15716.           pointer.  It is most useful in mixed memory model applications. 
  15717.  
  15718. Returns:  The value of dst is returned. 
  15719.  
  15720. See Also: strdup, strncpy 
  15721.  
  15722. Example: 
  15723.  
  15724.                     #include <stdio.h>
  15725.                     #include <string.h>
  15726.  
  15727.                     void main()
  15728.                       {
  15729.                         auto char buffer[80];
  15730.  
  15731.                         strcpy( buffer, "Hello " );
  15732.                         strcat( buffer, "world" );
  15733.                         printf( "%s\n", buffer );
  15734.                       }
  15735.  
  15736.           produces the following: 
  15737.  
  15738.                     Hello world
  15739.  
  15740. Classification: strcpy is ANSI, _fstrcpy is not ANSI 
  15741.  
  15742.  
  15743. ΓòÉΓòÉΓòÉ 279. strcspn, _fstrcspn ΓòÉΓòÉΓòÉ
  15744.  
  15745. Synopsis: 
  15746.  
  15747.                     #include <string.h>
  15748.                     size_t strcspn( const char *str,
  15749.                                     const char *charset );
  15750.                     size_t _fstrcspn( const char __far *str,
  15751.                                       const char __far *charset );
  15752.  
  15753. Description: The strcspn and _fstrcspn functions compute the length of the 
  15754.           initial segment of the string pointed to by str which consists 
  15755.           entirely of characters not  from the string pointed to by charset. 
  15756.           The terminating null character is not considered part of str. 
  15757.  
  15758.           The _fstrcspn function is a data model independent form of the 
  15759.           strcspn function that accepts far pointer arguments.  It is most 
  15760.           useful in mixed memory model applications. 
  15761.  
  15762. Returns:  The length of the initial segment is returned. 
  15763.  
  15764. See Also: strspn 
  15765.  
  15766. Example: 
  15767.  
  15768.                     #include <stdio.h>
  15769.                     #include <string.h>
  15770.  
  15771.                     void main()
  15772.                       {
  15773.                         printf( "%d\n", strcspn( "abcbcadef", "cba" ) );
  15774.                         printf( "%d\n", strcspn( "xxxbcadef", "cba" ) );
  15775.                         printf( "%d\n", strcspn( "123456789", "cba" ) );
  15776.                       }
  15777.  
  15778.           produces the following: 
  15779.  
  15780.                     0
  15781.                     3
  15782.                     9
  15783.  
  15784. Classification: strcspn is ANSI, _fstrcspn is not ANSI 
  15785.  
  15786.  
  15787. ΓòÉΓòÉΓòÉ 280. strdup ΓòÉΓòÉΓòÉ
  15788.  
  15789. Synopsis: 
  15790.  
  15791.                     #include <string.h>
  15792.                     char *strdup( const char *src );
  15793.  
  15794. Description: The strdup function creates a duplicate copy of the string pointed 
  15795.           to by src and returns a pointer to the new copy.  The memory for the 
  15796.           new string is obtained by using the malloc function and can be freed 
  15797.           using the free function. 
  15798.  
  15799. Returns:  The strdup function returns the pointer to the new copy of the string 
  15800.           if successful, otherwise it returns NULL. 
  15801.  
  15802. See Also: free, malloc, strcpy, strncpy 
  15803.  
  15804. Example: 
  15805.  
  15806.                     #include <stdio.h>
  15807.                     #include <string.h>
  15808.  
  15809.                     void main()
  15810.                       {
  15811.                         char *new;
  15812.  
  15813.                         new = strdup( "Make a copy" );
  15814.                         printf( "%s\n", new );
  15815.                       }
  15816.  
  15817. Classification: WATCOM 
  15818.  
  15819.  
  15820. ΓòÉΓòÉΓòÉ 281. strerror ΓòÉΓòÉΓòÉ
  15821.  
  15822. Synopsis: 
  15823.  
  15824.                     #include <string.h>
  15825.                     char *strerror( int errnum );
  15826.  
  15827. Description: The strerror function maps the error number contained in errnum to 
  15828.           an error message. 
  15829.  
  15830. Returns:  The strerror function returns a pointer to the error message.  The 
  15831.           array containing the error string should not be modified by the 
  15832.           program.  This array may be overwritten by a subsequent call to the 
  15833.           strerror function. 
  15834.  
  15835. See Also: perror 
  15836.  
  15837. Example: 
  15838.  
  15839.                     #include <stdio.h>
  15840.                     #include <string.h>
  15841.                     #include <errno.h>
  15842.  
  15843.                     void main()
  15844.                       {
  15845.                         FILE *fp;
  15846.  
  15847.                         fp = fopen( "file.nam", "r" );
  15848.                         if( fp == NULL ) {
  15849.                             printf( "Unable to open file: %s\n",
  15850.                                      strerror( errno ) );
  15851.                         }
  15852.                       }
  15853.  
  15854. Classification: ANSI 
  15855.  
  15856.  
  15857. ΓòÉΓòÉΓòÉ 282. strftime ΓòÉΓòÉΓòÉ
  15858.  
  15859. Synopsis: 
  15860.  
  15861.                     #include <time.h>
  15862.                     size_t strftime(char *s,
  15863.                                     size_t maxsize,
  15864.                                     const char *format,
  15865.                                     const struct tm *timeptr );
  15866.  
  15867.                     struct tm {
  15868.                       int tm_sec;   /* seconds after the minute -- [0,61] */
  15869.                       int tm_min;   /* minutes after the hour -- [0,59] */
  15870.                       int tm_hour;  /* hours after midnight -- [0,23] */
  15871.                       int tm_mday;  /* day of the month -- [1,31] */
  15872.                       int tm_mon;   /* months since January -- [0,11] */
  15873.                       int tm_year;  /* years since 1900 */
  15874.                       int tm_wday;  /* days since Sunday -- [0,6] */
  15875.                       int tm_yday;  /* days since January 1 -- [0,365]*/
  15876.                       int tm_isdst; /* Daylight Savings Time flag */
  15877.                     };
  15878.  
  15879. Description: The strftime function formats the time in the argument timeptr 
  15880.           into the array pointed to by the argument s according to the format 
  15881.           argument.  The format string consists of zero or more directives and 
  15882.           ordinary characters.  A directive consists of a '%' character 
  15883.           followed by a character that determines the substitution that is to 
  15884.           take place.  All ordinary characters are copied unchanged into the 
  15885.           array.  No more than maxsize characters are placed in the array.  The 
  15886.           format directives %D, %h, %n, %r, %t, and %T are from POSIX. 
  15887.  
  15888.    Directive Meaning 
  15889.    %a        locale's abbreviated weekday name 
  15890.    %A        locale's full weekday name 
  15891.    %b        locale's abbreviated month name 
  15892.    %B        locale's full month name 
  15893.    %c        locale's appropriate date and time representation 
  15894.    %d        day of the month as a decimal number (01-31) 
  15895.    %D        date in the format mm/dd/yy (POSIX) 
  15896.    %h        locale's abbreviated month name (POSIX) 
  15897.    %H        hour (24-hour clock) as a decimal number (00-23) 
  15898.    %I        hour (12-hour clock) as a decimal number (01-12) 
  15899.    %j        day of the year as a decimal number (001-366) 
  15900.    %m        month as a decimal number (01-12) 
  15901.    %M        minute as a decimal number (00-59) 
  15902.    %n        newline character (POSIX) 
  15903.    %p        locale's equivalent of either AM or PM 
  15904.    %r        12-hour clock time (01-12) using the AM/PM notation in the format 
  15905.              HH:MM:SS (AM|PM) (POSIX) 
  15906.    %S        second as a decimal number (00-59) 
  15907.    %t        tab character (POSIX) 
  15908.    %T        24-hour clock time in the format HH:MM:SS (POSIX) 
  15909.    %U        week number of the year as a decimal number (00-52) where Sunday 
  15910.              is the first day of the week 
  15911.    %w        weekday as a decimal number (0-6) where 0 is Sunday 
  15912.    %W        week number of the year as a decimal number (00-52) where Monday 
  15913.              is the first day of the week 
  15914.    %x        locale's appropriate date representation 
  15915.    %X        locale's appropriate time representation 
  15916.    %y        year without century as a decimal number (00-99) 
  15917.    %Y        year with century as a decimal number 
  15918.    %Z        timezone name, or by no characters if no timezone exists 
  15919.    %%        character % 
  15920.  
  15921.           When the %Z directive is specified, the tzset function is called. 
  15922.  
  15923. Returns:  If the number of characters to be placed into the array is less than 
  15924.           maxsize, the strftime function returns the number of characters 
  15925.           placed into the array pointed to by s not including the terminating 
  15926.           null character.  Otherwise, zero is returned. When an error has 
  15927.           occurred, errno contains a value indicating the type of error that 
  15928.           has been detected. 
  15929.  
  15930. See Also: setlocale asctime, clock, ctime, difftime, gmtime, localtime, mktime, 
  15931.           time, tzset 
  15932.  
  15933. Example: 
  15934.  
  15935.                     #include <stdio.h>
  15936.                     #include <time.h>
  15937.  
  15938.                     void main()
  15939.                       {
  15940.                         time_t time_of_day;
  15941.                         char buffer[ 80 ];
  15942.  
  15943.                         time_of_day = time( NULL );
  15944.                         strftime( buffer, 80, "Today is %A %B %d, %Y",
  15945.                                    localtime( &time_of_day ) );
  15946.                         printf( "%s\n", buffer );
  15947.                       }
  15948.  
  15949.           produces the following: 
  15950.  
  15951.                     Today is Friday December 25, 1987
  15952.  
  15953. Classification: ANSI, POSIX 
  15954.  
  15955.  
  15956. ΓòÉΓòÉΓòÉ 283. stricmp, _fstricmp ΓòÉΓòÉΓòÉ
  15957.  
  15958. Synopsis: 
  15959.  
  15960.                     #include <string.h>
  15961.                     int stricmp( const char *s1, const char *s2 );
  15962.                     int _fstricmp( const char __far *s1,
  15963.                                    const char __far *s2 );
  15964.  
  15965. Description: The stricmp and _fstricmp functions compare, with case 
  15966.           insensitivity, the string pointed to by s1 to the string pointed to 
  15967.           by s2. All upper-case characters from s1 and s2 are mapped to 
  15968.           lower-case for the purposes of doing the comparison. 
  15969.  
  15970.           The _fstricmp function is a data model independent form of the 
  15971.           stricmp function that accepts far pointer arguments.  It is most 
  15972.           useful in mixed memory model applications. 
  15973.  
  15974. Returns:  The stricmp and _fstricmp functions return an integer less than, 
  15975.           equal to, or greater than zero, indicating that the string pointed to 
  15976.           by s1 is less than, equal to, or greater than the string pointed to 
  15977.           by s2. 
  15978.  
  15979. See Also: strcmp, strcmpi, strncmp, strnicmp 
  15980.  
  15981. Example: 
  15982.  
  15983.                     #include <stdio.h>
  15984.                     #include <string.h>
  15985.  
  15986.                     void main()
  15987.                       {
  15988.                         printf( "%d\n", stricmp( "AbCDEF", "abcdef" ) );
  15989.                         printf( "%d\n", stricmp( "abcdef", "ABC"    ) );
  15990.                         printf( "%d\n", stricmp( "abc",    "ABCdef" ) );
  15991.                         printf( "%d\n", stricmp( "Abcdef", "mnopqr" ) );
  15992.                         printf( "%d\n", stricmp( "Mnopqr", "abcdef" ) );
  15993.                       }
  15994.  
  15995.           produces the following: 
  15996.  
  15997.                     0
  15998.                     100
  15999.                     -100
  16000.                     -12
  16001.                     12
  16002.  
  16003. Classification: WATCOM 
  16004.  
  16005.  
  16006. ΓòÉΓòÉΓòÉ 284. strlen, _fstrlen ΓòÉΓòÉΓòÉ
  16007.  
  16008. Synopsis: 
  16009.  
  16010.                     #include <string.h>
  16011.                     size_t strlen( const char *s );
  16012.                     size_t _fstrlen( const char __far *s );
  16013.  
  16014. Description: The strlen and _fstrlen functions compute the length of the string 
  16015.           pointed to by s. 
  16016.  
  16017.           The _fstrlen function is a data model independent form of the strlen 
  16018.           function that accepts far pointer arguments.  It is most useful in 
  16019.           mixed memory model applications. 
  16020.  
  16021. Returns:  The strlen and _fstrlen functions return the number of characters 
  16022.           that precede the terminating null character. 
  16023.  
  16024. Example: 
  16025.  
  16026.                     #include <stdio.h>
  16027.                     #include <string.h>
  16028.  
  16029.                     void main()
  16030.                       {
  16031.                         printf( "%d\n", strlen( "Howdy" ) );
  16032.                         printf( "%d\n", strlen( "Hello world\n" ) );
  16033.                         printf( "%d\n", strlen( "" ) );
  16034.                       }
  16035.  
  16036.           produces the following: 
  16037.  
  16038.                     5
  16039.                     12
  16040.                     0
  16041.  
  16042. Classification: strlen is ANSI, _fstrlen is not ANSI 
  16043.  
  16044.  
  16045. ΓòÉΓòÉΓòÉ 285. strlwr, _fstrlwr ΓòÉΓòÉΓòÉ
  16046.  
  16047. Synopsis: 
  16048.  
  16049.                     #include <string.h>
  16050.                     char *strlwr( char *str );
  16051.                     char __far *_fstrlwr( char __far *str );
  16052.  
  16053. Description: The strlwr and _fstrlwr functions replace the string str with 
  16054.           lower-case characters by invoking the tolower function for each 
  16055.           character in the string. 
  16056.  
  16057.           The _fstrlwr function is a data model independent form of the strlwr 
  16058.           function.  It accepts far pointer arguments and returns a far 
  16059.           pointer.  It is most useful in mixed memory model applications. 
  16060.  
  16061. Returns:  The address of the original string str is returned. 
  16062.  
  16063. See Also: strupr 
  16064.  
  16065. Example: 
  16066.  
  16067.                     #include <stdio.h>
  16068.                     #include <string.h>
  16069.  
  16070.                     char source[] = { "A mixed-case STRING" };
  16071.  
  16072.                     void main()
  16073.                       {
  16074.                         printf( "%s\n", source );
  16075.                         printf( "%s\n", strlwr( source ) );
  16076.                         printf( "%s\n", source );
  16077.                       }
  16078.  
  16079.           produces the following: 
  16080.  
  16081.                     A mixed-case STRING
  16082.                     a mixed-case string
  16083.                     a mixed-case string
  16084.  
  16085. Classification: WATCOM 
  16086.  
  16087.  
  16088. ΓòÉΓòÉΓòÉ 286. strncat, _fstrncat ΓòÉΓòÉΓòÉ
  16089.  
  16090. Synopsis: 
  16091.  
  16092.                     #include <string.h>
  16093.                     char *strncat( char *dst, const char *src, size_t n );
  16094.                     char __far *_fstrncat( char __far *dst,
  16095.                                            const char __far *src,
  16096.                                            size_t n );
  16097.  
  16098. Description: The strncat and _fstrncat functions append not more than n 
  16099.           characters of the string pointed to by src to the end of the string 
  16100.           pointed to by dst. The first character of src overwrites the null 
  16101.           character at the end of dst. A terminating null character is always 
  16102.           appended to the result. 
  16103.  
  16104.           The _fstrncat function is a data model independent form of the 
  16105.           strncat function.  It accepts far pointer arguments and returns a far 
  16106.           pointer.  It is most useful in mixed memory model applications. 
  16107.  
  16108. Returns:  The strncat and _fstrncat functions return the value of dst. 
  16109.  
  16110. See Also: strcat 
  16111.  
  16112. Example: 
  16113.  
  16114.                     #include <stdio.h>
  16115.                     #include <string.h>
  16116.  
  16117.                     char buffer[80];
  16118.  
  16119.                     void main()
  16120.                       {
  16121.                         strcpy( buffer, "Hello " );
  16122.                         strncat( buffer, "world", 8 );
  16123.                         printf( "%s\n", buffer );
  16124.                         strncat( buffer, "*************", 4 );
  16125.                         printf( "%s\n", buffer );
  16126.                       }
  16127.  
  16128.           produces the following: 
  16129.  
  16130.                     Hello world
  16131.                     Hello world****
  16132.  
  16133. Classification: strncat is ANSI, _fstrncat is not ANSI 
  16134.  
  16135.  
  16136. ΓòÉΓòÉΓòÉ 287. strncmp, _fstrncmp ΓòÉΓòÉΓòÉ
  16137.  
  16138. Synopsis: 
  16139.  
  16140.                     #include <string.h>
  16141.                     int strncmp( const char *s1,
  16142.                                  const char *s2,
  16143.                                  size_t n );
  16144.                     int _fstrncmp( const char __far *s1,
  16145.                                    const char __far *s2,
  16146.                                    size_t n );
  16147.  
  16148. Description: The strncmp and _fstrncmp functions compare not more than n 
  16149.           characters from the string pointed to by s1 to the string pointed to 
  16150.           by s2. 
  16151.  
  16152.           The _fstrncmp function is a data model independent form of the 
  16153.           strncmp function that accepts far pointer arguments.  It is most 
  16154.           useful in mixed memory model applications. 
  16155.  
  16156. Returns:  The strncmp and _fstrncmp functions return an integer less than, 
  16157.           equal to, or greater than zero, indicating that the string pointed to 
  16158.           by s1 is less than, equal to, or greater than the string pointed to 
  16159.           by s2. 
  16160.  
  16161. See Also: strcmp, stricmp, strnicmp 
  16162.  
  16163. Example: 
  16164.  
  16165.                     #include <stdio.h>
  16166.                     #include <string.h>
  16167.  
  16168.                     void main()
  16169.                       {
  16170.                         printf( "%d\n", strncmp( "abcdef", "abcDEF", 10 ) );
  16171.                         printf( "%d\n", strncmp( "abcdef", "abcDEF",  6 ) );
  16172.                         printf( "%d\n", strncmp( "abcdef", "abcDEF",  3 ) );
  16173.                         printf( "%d\n", strncmp( "abcdef", "abcDEF",  0 ) );
  16174.                       }
  16175.  
  16176.           produces the following: 
  16177.  
  16178.                     1
  16179.                     1
  16180.                     0
  16181.                     0
  16182.  
  16183. Classification: strncmp is ANSI, _fstrncmp is not ANSI 
  16184.  
  16185.  
  16186. ΓòÉΓòÉΓòÉ 288. strncpy, _fstrncpy ΓòÉΓòÉΓòÉ
  16187.  
  16188. Synopsis: 
  16189.  
  16190.                     #include <string.h>
  16191.                     char *strncpy( char *dst,
  16192.                                    const char *src,
  16193.                                    size_t n );
  16194.                     char __far *_fstrncpy( char __far *dst,
  16195.                                            const char __far *src,
  16196.                                            size_t n );
  16197.  
  16198. Description: The strncpy and _fstrncpy functions copy no more than n characters 
  16199.           from the string pointed to by src into the array pointed to by dst. 
  16200.           Copying of overlapping objects is not guaranteed to work properly. 
  16201.           See the memmove function if you wish to copy objects that overlap. 
  16202.  
  16203.           If the string pointed to by src is shorter than n characters, null 
  16204.           characters are appended to the copy in the array pointed to by dst, 
  16205.           until n characters in all have been written.  If the string pointed 
  16206.           to by src is longer than n characters, then the result will not be 
  16207.           terminated by a null character. 
  16208.  
  16209.           The _fstrncpy function is a data model independent form of the 
  16210.           strncpy function.  It accepts far pointer arguments and returns a far 
  16211.           pointer.  It is most useful in mixed memory model applications. 
  16212.  
  16213. Returns:  The strncpy and _fstrncpy functions return the value of dst. 
  16214.  
  16215. See Also: strcpy, strdup 
  16216.  
  16217. Example: 
  16218.  
  16219.                     #include <stdio.h>
  16220.                     #include <string.h>
  16221.  
  16222.                     void main()
  16223.                       {
  16224.                         char buffer[15];
  16225.  
  16226.                         printf( "%s\n", strncpy( buffer, "abcdefg", 10 ) );
  16227.                         printf( "%s\n", strncpy( buffer, "1234567",  6 ) );
  16228.                         printf( "%s\n", strncpy( buffer, "abcdefg",  3 ) );
  16229.                         printf( "%s\n", strncpy( buffer, "*******",  0 ) );
  16230.                       }
  16231.  
  16232.           produces the following: 
  16233.  
  16234.                     abcdefg
  16235.                     123456g
  16236.                     abc456g
  16237.                     abc456g
  16238.  
  16239. Classification: strncpy is ANSI, _fstrncpy is not ANSI 
  16240.  
  16241.  
  16242. ΓòÉΓòÉΓòÉ 289. strnicmp, _fstrnicmp ΓòÉΓòÉΓòÉ
  16243.  
  16244. Synopsis: 
  16245.  
  16246.                     #include <string.h>
  16247.                     int strnicmp( const char *s1,
  16248.                                   const char *s2,
  16249.                                   size_t len );
  16250.                     int _fstrnicmp( const char __far *s1,
  16251.                                     const char __far *s2,
  16252.                                     size_t len );
  16253.  
  16254. Description: The strnicmp and _fstrnicmp functions compare, without case 
  16255.           sensitivity, the string pointed to by s1 to the string pointed to by 
  16256.           s2, for at most len characters. 
  16257.  
  16258.           The _fstrnicmp function is a data model independent form of the 
  16259.           strnicmp function that accepts far pointer arguments.  It is most 
  16260.           useful in mixed memory model applications. 
  16261.  
  16262. Returns:  The strnicmp and _fstrnicmp functions return an integer less than, 
  16263.           equal to, or greater than zero, indicating that the string pointed to 
  16264.           by s1 is less than, equal to, or greater than the string pointed to 
  16265.           by s2. 
  16266.  
  16267. See Also: strcmp, stricmp, strncmp 
  16268.  
  16269. Example: 
  16270.  
  16271.                     #include <stdio.h>
  16272.                     #include <string.h>
  16273.  
  16274.                     void main()
  16275.                       {
  16276.                         printf( "%d\n", strnicmp( "abcdef", "ABCXXX", 10 ) );
  16277.                         printf( "%d\n", strnicmp( "abcdef", "ABCXXX",  6 ) );
  16278.                         printf( "%d\n", strnicmp( "abcdef", "ABCXXX",  3 ) );
  16279.                         printf( "%d\n", strnicmp( "abcdef", "ABCXXX",  0 ) );
  16280.                       }
  16281.  
  16282.           produces the following: 
  16283.  
  16284.                     -20
  16285.                     -20
  16286.                     0
  16287.                     0
  16288.  
  16289. Classification: WATCOM 
  16290.  
  16291.  
  16292. ΓòÉΓòÉΓòÉ 290. strnset, _fstrnset ΓòÉΓòÉΓòÉ
  16293.  
  16294. Synopsis: 
  16295.  
  16296.                     #include <string.h>
  16297.                     char *strnset( char *s1,
  16298.                                    int fill,
  16299.                                    const size_t len );
  16300.                     char __far *_fstrnset( char __far *s1,
  16301.                                            int fill,
  16302.                                            const size_t len );
  16303.  
  16304. Description: The strnset and _fstrnset functions fill the string s1 with the 
  16305.           value of the argument fill, converted to be a character value.  When 
  16306.           the value of len is greater than the length of the string, the entire 
  16307.           string is filled. Otherwise, that number of characters at the start 
  16308.           of the string are set to the fill character. 
  16309.  
  16310.           The _fstrnset function is a data model independent form of the 
  16311.           strnset function.  It accepts far pointer arguments and returns a far 
  16312.           pointer.  It is most useful in mixed memory model applications. 
  16313.  
  16314. Returns:  The address of the original string s1 is returned. 
  16315.  
  16316. See Also: strset 
  16317.  
  16318. Example: 
  16319.  
  16320.                     #include <stdio.h>
  16321.                     #include <string.h>
  16322.  
  16323.                     char source[] = { "A sample STRING" };
  16324.  
  16325.                     void main()
  16326.                       {
  16327.                         printf( "%s\n", source );
  16328.                         printf( "%s\n", strnset( source, '=', 100 ) );
  16329.                         printf( "%s\n", strnset( source, '*', 7 ) );
  16330.                       }
  16331.  
  16332.           produces the following: 
  16333.  
  16334.                     A sample STRING
  16335.                     ===============
  16336.                     *******========
  16337.  
  16338. Classification: WATCOM 
  16339.  
  16340.  
  16341. ΓòÉΓòÉΓòÉ 291. strpbrk, _fstrpbrk ΓòÉΓòÉΓòÉ
  16342.  
  16343. Synopsis: 
  16344.  
  16345.                     #include <string.h>
  16346.                     char *strpbrk( const char *str, const char *charset );
  16347.                     char __far *_fstrpbrk( const char __far *str,
  16348.                                            const char __far *charset );
  16349.  
  16350. Description: The strpbrk and _fstrpbrk functions locate the first occurrence in 
  16351.           the string pointed to by str of any character from the string pointed 
  16352.           to by charset. 
  16353.  
  16354.           The _fstrpbrk function is a data model independent form of the 
  16355.           strpbrk function.  It accepts far pointer arguments and returns a far 
  16356.           pointer.  It is most useful in mixed memory model applications. 
  16357.  
  16358. Returns:  The strpbrk and _fstrpbrk functions return a pointer to the located 
  16359.           character, or NULL if no character from charset occurs in str. 
  16360.  
  16361. See Also: strchr, strrchr, strtok 
  16362.  
  16363. Example: 
  16364.  
  16365.                     #include <stdio.h>
  16366.                     #include <string.h>
  16367.  
  16368.                     void main()
  16369.                       {
  16370.                         char *p = "Find all vowels";
  16371.  
  16372.                         while( p != NULL ) {
  16373.                           printf( "%s\n", p );
  16374.                           p = strpbrk( p+1, "aeiouAEIOU" );
  16375.                         }
  16376.                       }
  16377.  
  16378.           produces the following: 
  16379.  
  16380.                     Find all vowels
  16381.                     ind all vowels
  16382.                     all vowels
  16383.                     owels
  16384.                     els
  16385.  
  16386. Classification: strpbrk is ANSI, _fstrpbrk is not ANSI 
  16387.  
  16388.  
  16389. ΓòÉΓòÉΓòÉ 292. strrchr, _fstrrchr ΓòÉΓòÉΓòÉ
  16390.  
  16391. Synopsis: 
  16392.  
  16393.                     #include <string.h>
  16394.                     char *strrchr( const char *s, int c );
  16395.                     char __far *_fstrrchr( const char __far *s, int c );
  16396.  
  16397. Description: The strrchr and _fstrrchr functions locate the last occurrence of 
  16398.           c (converted to a char) in the string pointed to by s. The 
  16399.           terminating null character is considered to be part of the string. 
  16400.  
  16401.           The _fstrrchr function is a data model independent form of the 
  16402.           strrchr function.  It accepts far pointer arguments and returns a far 
  16403.           pointer.  It is most useful in mixed memory model applications. 
  16404.  
  16405. Returns:  The strrchr and _fstrrchr functions return a pointer to the located 
  16406.           character, or a NULL pointer if the character does not occur in the 
  16407.           string. 
  16408.  
  16409. See Also: strchr, strpbrk 
  16410.  
  16411. Example: 
  16412.  
  16413.                     #include <stdio.h>
  16414.                     #include <string.h>
  16415.  
  16416.                     void main()
  16417.                       {
  16418.                         printf( "%s\n", strrchr( "abcdeabcde", 'a' ) );
  16419.                         if( strrchr( "abcdeabcde", 'x' ) == NULL )
  16420.                             printf( "NULL\n" );
  16421.                       }
  16422.  
  16423.           produces the following: 
  16424.  
  16425.                     abcde
  16426.                     NULL
  16427.  
  16428. Classification: strrchr is ANSI, _fstrrchr is not ANSI 
  16429.  
  16430.  
  16431. ΓòÉΓòÉΓòÉ 293. strrev, _fstrrev ΓòÉΓòÉΓòÉ
  16432.  
  16433. Synopsis: 
  16434.  
  16435.                     #include <string.h>
  16436.                     char *strrev( char *s1 );
  16437.                     char __far *_fstrrev( char __far *s1 );
  16438.  
  16439. Description: The strrev and _fstrrev functions replace the string s1 with a 
  16440.           string whose characters are in the reverse order. 
  16441.  
  16442.           The _fstrrev function is a data model independent form of the strrev 
  16443.           function.  It accepts far pointer arguments and returns a far 
  16444.           pointer.  It is most useful in mixed memory model applications. 
  16445.  
  16446. Returns:  The address of the original string s1 is returned. 
  16447.  
  16448. Example: 
  16449.  
  16450.                     #include <stdio.h>
  16451.                     #include <string.h>
  16452.  
  16453.                     char source[] = { "A sample STRING" };
  16454.  
  16455.                     void main()
  16456.                       {
  16457.                         printf( "%s\n", source );
  16458.                         printf( "%s\n", strrev( source ) );
  16459.                         printf( "%s\n", strrev( source ) );
  16460.                       }
  16461.  
  16462.           produces the following: 
  16463.  
  16464.                     A sample STRING
  16465.                     GNIRTS elpmas A
  16466.                     A sample STRING
  16467.  
  16468. Classification: WATCOM 
  16469.  
  16470.  
  16471. ΓòÉΓòÉΓòÉ 294. strset, _fstrset ΓòÉΓòÉΓòÉ
  16472.  
  16473. Synopsis: 
  16474.  
  16475.                     #include <string.h>
  16476.                     char *strset( char *s1, char fill );
  16477.                     char __far *_fstrset( char __far *s1, char fill );
  16478.  
  16479. Description: The strset and _fstrset functions fill the string pointed to by s1 
  16480.           with the character fill. The terminating null character in the 
  16481.           original string remains unchanged. 
  16482.  
  16483.           The _fstrset function is a data model independent form of the strset 
  16484.           function.  It accepts far pointer arguments and returns a far 
  16485.           pointer.  It is most useful in mixed memory model applications. 
  16486.  
  16487. Returns:  The address of the original string s1 is returned. 
  16488.  
  16489. See Also: strnset 
  16490.  
  16491. Example: 
  16492.  
  16493.                     #include <stdio.h>
  16494.                     #include <string.h>
  16495.  
  16496.                     char source[] = { "A sample STRING" };
  16497.  
  16498.                     void main()
  16499.                       {
  16500.                         printf( "%s\n", source );
  16501.                         printf( "%s\n", strset( source, '=' ) );
  16502.                         printf( "%s\n", strset( source, '*' ) );
  16503.                       }
  16504.  
  16505.           produces the following: 
  16506.  
  16507.                     A sample STRING
  16508.                     ===============
  16509.                     ***************
  16510.  
  16511. Classification: WATCOM 
  16512.  
  16513.  
  16514. ΓòÉΓòÉΓòÉ 295. strspn, _fstrspn ΓòÉΓòÉΓòÉ
  16515.  
  16516. Synopsis: 
  16517.  
  16518.                     #include <string.h>
  16519.                     size_t strspn( const char *str,
  16520.                                    const char *charset );
  16521.                     size_t _fstrspn( const char __far *str,
  16522.                                      const char __far *charset );
  16523.  
  16524. Description: The strspn and _fstrspn functions compute the length of the 
  16525.           initial segment of the string pointed to by str which consists of 
  16526.           characters from the string pointed to by charset. The terminating 
  16527.           null character is not considered to be part of charset. 
  16528.  
  16529.           The _fstrspn function is a data model independent form of the strspn 
  16530.           function that accepts far pointer arguments.  It is most useful in 
  16531.           mixed memory model applications. 
  16532.  
  16533. Returns:  The strspn and _fstrspn functions return the length of the segment. 
  16534.  
  16535. See Also: strcspn 
  16536.  
  16537. Example: 
  16538.  
  16539.                     #include <stdio.h>
  16540.                     #include <string.h>
  16541.  
  16542.                     void main()
  16543.                       {
  16544.                         printf( "%d\n", strspn( "out to lunch", "aeiou" ) );
  16545.                         printf( "%d\n", strspn( "out to lunch", "xyz" ) );
  16546.                       }
  16547.  
  16548.           produces the following: 
  16549.  
  16550.                     2
  16551.                     0
  16552.  
  16553. Classification: strspn is ANSI, _fstrspn is not ANSI 
  16554.  
  16555.  
  16556. ΓòÉΓòÉΓòÉ 296. strstr, _fstrstr ΓòÉΓòÉΓòÉ
  16557.  
  16558. Synopsis: 
  16559.  
  16560.                     #include <string.h>
  16561.                     char *strstr( const char *str,
  16562.                                   const char *substr );
  16563.                     char __far *_fstrstr( const char __far *str,
  16564.                                           const char __far *substr );
  16565.  
  16566. Description: The strstr and _fstrstr functions locate the first occurrence in 
  16567.           the string pointed to by str of the sequence of characters (excluding 
  16568.           the terminating null character) in the string pointed to by substr. 
  16569.  
  16570.           The _fstrstr function is a data model independent form of the strstr 
  16571.           function.  It accepts far pointer arguments and returns a far 
  16572.           pointer.  It is most useful in mixed memory model applications. 
  16573.  
  16574. Returns:  The strstr and _fstrstr functions return a pointer to the located 
  16575.           string, or NULL if the string is not found. 
  16576.  
  16577. See Also: strcspn 
  16578.  
  16579. Example: 
  16580.  
  16581.                     #include <stdio.h>
  16582.                     #include <string.h>
  16583.  
  16584.                     void main()
  16585.                       {
  16586.                         printf( "%s\n",
  16587.                                 strstr( "This is an example", "is" )
  16588.                               );
  16589.                       }
  16590.  
  16591.           produces the following: 
  16592.  
  16593.                     is is an example
  16594.  
  16595. Classification: strstr is ANSI, _fstrstr is not ANSI 
  16596.  
  16597.  
  16598. ΓòÉΓòÉΓòÉ 297. strtod ΓòÉΓòÉΓòÉ
  16599.  
  16600. Synopsis: 
  16601.  
  16602.                     #include <stdlib.h>
  16603.                     double strtod( const char *ptr, char **endptr );
  16604.  
  16605. Description: The strtod function converts the string pointed to by ptr to 
  16606.           double representation.  The function recognizes a string containing : 
  16607.  
  16608.    o optional white space, 
  16609.    o an optional plus or minus sign, 
  16610.    o a sequence of digits containing an optional decimal point, 
  16611.    o an optional 'e' or 'E' followed by an optionally signed sequence of 
  16612.      digits. 
  16613.  
  16614.           The conversion ends at the first unrecognized character.  A pointer 
  16615.           to that character will be stored in the object to which endptr points 
  16616.           if endptr is not NULL. 
  16617.  
  16618. Returns:  The strtod function returns the converted value.  If the correct 
  16619.           value would cause overflow, plus or minus HUGE_VAL is returned 
  16620.           according to the sign, and errno is set to ERANGE. If the correct 
  16621.           value would cause underflow, then zero is returned, and errno is set 
  16622.           to ERANGE. Zero is returned when the input string cannot be 
  16623.           converted.  When an error has occurred, errno contains a value 
  16624.           indicating the type of error that has been detected. 
  16625.  
  16626. See Also: atof 
  16627.  
  16628. Example: 
  16629.  
  16630.                     #include <stdio.h>
  16631.                     #include <stdlib.h>
  16632.  
  16633.                     void main()
  16634.                       {
  16635.                         double pi;
  16636.  
  16637.                         pi = strtod( "3.141592653589793", NULL );
  16638.                         printf( "pi=%17.15f\n",pi );
  16639.                       }
  16640.  
  16641. Classification: ANSI 
  16642.  
  16643.  
  16644. ΓòÉΓòÉΓòÉ 298. strtok, _fstrtok ΓòÉΓòÉΓòÉ
  16645.  
  16646. Synopsis: 
  16647.  
  16648.                     #include <string.h>
  16649.                     char *strtok( char *s1, const char *s2 );
  16650.                     char __far *_fstrtok( char __far *s1,
  16651.                                           const char __far *s2 );
  16652.  
  16653. Description: The strtok and _fstrtok functions are used to break the string 
  16654.           pointed to by s1 into a sequence of tokens, each of which is 
  16655.           delimited by a character from the string pointed to by s2. The first 
  16656.           call to strtok will return a pointer to the first token in the string 
  16657.           pointed to by s1. Subsequent calls to strtok must pass a NULL pointer 
  16658.           as the first argument, in order to get the next token in the string. 
  16659.           The set of delimiters used in each of these calls to strtok can be 
  16660.           different from one call to the next. 
  16661.  
  16662.           The first call in the sequence searches s1 for the first character 
  16663.           that is not contained in the current delimiter string s2. If no such 
  16664.           character is found, then there are no tokens in s1 and the strtok 
  16665.           function returns a NULL pointer.  If such a character is found, it is 
  16666.           the start of the first token. 
  16667.  
  16668.           The strtok function then searches from there for a character that is 
  16669.           contained in the current delimiter string.  If no such character is 
  16670.           found, the current token extends to the end of the string pointed to 
  16671.           by s1. If such a character is found, it is overwritten by a null 
  16672.           character, which terminates the current token.  The strtok function 
  16673.           saves a pointer to the following character, from which the next 
  16674.           search for a token will start when the first argument is a NULL 
  16675.           pointer. 
  16676.  
  16677.           Because strtok may modify the original string, that string should be 
  16678.           duplicated if the string is to be re-used. 
  16679.  
  16680.           The _fstrtok function is a data model independent form of the strtok 
  16681.           function.  It accepts far pointer arguments and returns a far 
  16682.           pointer.  It is most useful in mixed memory model applications. 
  16683.  
  16684. Returns:  The strtok and _fstrtok functions return a pointer to the first 
  16685.           character of a token or NULL if there is no token found. 
  16686.  
  16687. See Also: strcspn, strpbrk 
  16688.  
  16689. Example: 
  16690.  
  16691.                     #include <stdio.h>
  16692.                     #include <string.h>
  16693.                     void main()
  16694.                       {
  16695.                         char *p;
  16696.                         char *buffer;
  16697.                         char *delims = { " .," };
  16698.                         buffer = strdup( "Find words, all of them." );
  16699.                         printf( "%s\n", buffer );
  16700.                         p = strtok( buffer, delims );
  16701.                         while( p != NULL ) {
  16702.                           printf( "word: %s\n", p );
  16703.                           p = strtok( NULL, delims );
  16704.                         }
  16705.                         printf( "%s\n", buffer );
  16706.                       }
  16707.  
  16708.           produces the following: 
  16709.  
  16710.                     Find words, all of them.
  16711.                     word: Find
  16712.                     word: words
  16713.                     word: all
  16714.                     word: of
  16715.                     word: them
  16716.                     Find
  16717.  
  16718. Classification: strtok is ANSI, _fstrtok is not ANSI 
  16719.  
  16720.  
  16721. ΓòÉΓòÉΓòÉ 299. strtol ΓòÉΓòÉΓòÉ
  16722.  
  16723. Synopsis: 
  16724.  
  16725.                     #include <stdlib.h>
  16726.                     long int strtol( const char *ptr,
  16727.                                      char **endptr,
  16728.                                      int base );
  16729.  
  16730. Description: The strtol function converts the string pointed to by ptr to an 
  16731.           object of type long int. The function recognizes a string containing: 
  16732.  
  16733.    o optional white space, 
  16734.    o an optional plus or minus sign, 
  16735.    o a sequence of digits and letters. 
  16736.  
  16737.           The conversion ends at the first unrecognized character.  A pointer 
  16738.           to that character will be stored in the object to which endptr points 
  16739.           if endptr is not NULL. 
  16740.  
  16741.           If base is zero, the first characters after the optional sign 
  16742.           determine the base used for the conversion.  If the first characters 
  16743.           are "0x" or "0X" the digits are treated as hexadecimal.  If the first 
  16744.           character is '0', the digits are treated as octal.  Otherwise the 
  16745.           digits are treated as decimal. 
  16746.  
  16747.           If base is not zero, it must have a value between 2 and 36.  The 
  16748.           letters a-z and A-Z represent the values 10 through 35.  Only those 
  16749.           letters whose designated values are less than base are permitted.  If 
  16750.           the value of base is 16, the characters "0x" or "0X" may optionally 
  16751.           precede the sequence of letters and digits. 
  16752.  
  16753. Returns:  The strtol function returns the converted value.  If the correct 
  16754.           value would cause overflow, LONG_MAX or LONG_MIN is returned 
  16755.           according to the sign, and errno is set to ERANGE. If base is out of 
  16756.           range, zero is returned and errno is set to EDOM. 
  16757.  
  16758. See Also: ltoa, strtoul 
  16759.  
  16760. Example: 
  16761.  
  16762.                     #include <stdlib.h>
  16763.  
  16764.                     void main()
  16765.                       {
  16766.                         long int v;
  16767.  
  16768.                         v = strtol( "12345678", NULL, 10 );
  16769.                       }
  16770.  
  16771. Classification: ANSI 
  16772.  
  16773.  
  16774. ΓòÉΓòÉΓòÉ 300. strtoul ΓòÉΓòÉΓòÉ
  16775.  
  16776. Synopsis: 
  16777.  
  16778.                     #include <stdlib.h>
  16779.                     unsigned long int strtoul( const char *ptr,
  16780.                                                char **endptr,
  16781.                                                int base );
  16782.  
  16783. Description: The strtoul function converts the string pointed to by ptr to an 
  16784.           unsigned long. The function recognizes a string containing optional 
  16785.           white space, followed by a sequence of digits and letters.  The 
  16786.           conversion ends at the first unrecognized character.  A pointer to 
  16787.           that character will be stored in the object endptr points to if 
  16788.           endptr is not NULL. 
  16789.  
  16790.           If base is zero, the first characters determine the base used for the 
  16791.           conversion. If the first characters are "0x" or "0X" the digits are 
  16792.           treated as hexadecimal.  If the first character is '0', the digits 
  16793.           are treated as octal.  Otherwise the digits are treated as decimal. 
  16794.  
  16795.           If base is not zero, it must have a value of between 2 and 36.  The 
  16796.           letters a-z and A-Z represent the values 10 through 35.  Only those 
  16797.           letters whose designated values are less than base are permitted.  If 
  16798.           the value of base is 16, the characters "0x" or "0X" may optionally 
  16799.           precede the sequence of letters and digits. 
  16800.  
  16801. Returns:  The strtoul function returns the converted value.  If the correct 
  16802.           value would cause overflow, ULONG_MAX is returned and errno is set to 
  16803.           ERANGE. If base is out of range, zero is returned and errno is set to 
  16804.           EDOM. 
  16805.  
  16806. See Also: ltoa, strtol, ultoa 
  16807.  
  16808. Example: 
  16809.  
  16810.                     #include <stdlib.h>
  16811.  
  16812.                     void main()
  16813.                       {
  16814.                         unsigned long int v;
  16815.  
  16816.                         v = strtoul( "12345678", NULL, 10 );
  16817.                       }
  16818.  
  16819. Classification: ANSI 
  16820.  
  16821.  
  16822. ΓòÉΓòÉΓòÉ 301. strupr, _fstrupr ΓòÉΓòÉΓòÉ
  16823.  
  16824. Synopsis: 
  16825.  
  16826.                     #include <string.h>
  16827.                     char *strupr( char *s1 );
  16828.                     char __far *_fstrupr( char __far *s1 );
  16829.  
  16830. Description: The strupr and _fstrupr functions replace the string s1 with 
  16831.           upper-case characters by invoking the toupper function for each 
  16832.           character in the string. 
  16833.  
  16834.           The _fstrupr function is a data model independent form of the strupr 
  16835.           function.  It accepts far pointer arguments and returns a far 
  16836.           pointer.  It is most useful in mixed memory model applications. 
  16837.  
  16838. Returns:  The address of the original string s1 is returned. 
  16839.  
  16840. See Also: strlwr 
  16841.  
  16842. Example: 
  16843.  
  16844.                     #include <stdio.h>
  16845.                     #include <string.h>
  16846.  
  16847.                     char source[] = { "A mixed-case STRING" };
  16848.  
  16849.                     void main()
  16850.                       {
  16851.                         printf( "%s\n", source );
  16852.                         printf( "%s\n", strupr( source ) );
  16853.                         printf( "%s\n", source );
  16854.                       }
  16855.  
  16856.           produces the following: 
  16857.  
  16858.                     A mixed-case STRING
  16859.                     A MIXED-CASE STRING
  16860.                     A MIXED-CASE STRING
  16861.  
  16862. Classification: WATCOM 
  16863.  
  16864.  
  16865. ΓòÉΓòÉΓòÉ 302. strxfrm ΓòÉΓòÉΓòÉ
  16866.  
  16867. Synopsis: 
  16868.  
  16869.                     #include <string.h>
  16870.                     size_t strxfrm( char *dst,
  16871.                                     const char *src,
  16872.                                     size_t n );
  16873.  
  16874. Description: The strxfrm function transforms, for no more than n characters, 
  16875.           the string pointed to by src to the buffer pointed to by dst. The 
  16876.           transformation uses the collating sequence selected by the setlocale 
  16877.           function so that two transformed strings will compare identically 
  16878.           (using the strncmp function) to a comparison of the original two 
  16879.           strings using the strcoll function.  The function will be equivalent 
  16880.           to the strncpy function (except there is no padding of the dst 
  16881.           argument with null characters when the argument src is shorter than n 
  16882.           characters) when the collating sequence is selected from the "C" 
  16883.           locale. 
  16884.  
  16885. Returns:  The strxfrm function returns the length of the transformed string. 
  16886.           If this length is more than n, the contents of the array pointed to 
  16887.           by dst are indeterminate. 
  16888.  
  16889. See Also: setlocale, strcoll 
  16890.  
  16891. Classification: ANSI 
  16892.  
  16893.  
  16894. ΓòÉΓòÉΓòÉ 303. swab ΓòÉΓòÉΓòÉ
  16895.  
  16896. Synopsis: 
  16897.  
  16898.                     #include <stdlib.h>
  16899.                     void swab( char *src, char *dest, int num );
  16900.  
  16901. Description: The swab function copies num bytes (which should be even) from src 
  16902.           to dest swapping every pair of characters.  This is useful for 
  16903.           preparing binary data to be transferred to another machine that has a 
  16904.           different byte ordering. 
  16905.  
  16906. Returns:  The swab function has no return value. 
  16907.  
  16908. Example: 
  16909.  
  16910.                     #include <stdio.h>
  16911.                     #include <string.h>
  16912.                     #include <stdlib.h>
  16913.                     char *msg = "hTsim seasegi  swspaep.d";
  16914.                     #define NBYTES 24
  16915.  
  16916.                     void main()
  16917.                       {
  16918.                         auto char buffer[80];
  16919.  
  16920.                         printf( "%s\n", msg );
  16921.                         memset( buffer, '\0', 80 );
  16922.                         swab( msg, buffer, NBYTES );
  16923.                         printf( "%s\n", buffer );
  16924.                       }
  16925.  
  16926.           produces the following: 
  16927.  
  16928.                     hTsim seasegi  swspaep.d
  16929.                     This message is swapped.
  16930.  
  16931. Classification: WATCOM 
  16932.  
  16933.  
  16934. ΓòÉΓòÉΓòÉ 304. system ΓòÉΓòÉΓòÉ
  16935.  
  16936. Synopsis: 
  16937.  
  16938.                     #include <stdlib.h>
  16939.                     int system( const char *command );
  16940.  
  16941. Description: If the value of command is NULL, then the system function 
  16942.           determines whether or not a command processor is present (COMMAND.COM 
  16943.           in DOS or CMD.EXE in OS/2). 
  16944.  
  16945.           Otherwise, the system function invokes a copy of the command 
  16946.           processor, and passes the string command to it for processing.  This 
  16947.           function uses spawnl to load a copy of the command processor 
  16948.           identified by the COMSPEC environment variable. 
  16949.  
  16950.           This means that any command that can be entered to DOS can be 
  16951.           executed, including programs, DOS commands and batch files.  The 
  16952.           exec... and spawn... functions can only cause programs to be 
  16953.           executed. 
  16954.  
  16955. Returns:  If the value of command is NULL, then the system function returns 
  16956.           zero if the command processor is not present, a non-zero value if the 
  16957.           command processor is present. 
  16958.  
  16959.           Otherwise, the system function returns the result of invoking a copy 
  16960.           of the command processor.  A non-zero value is returned if the 
  16961.           command processor could not be loaded; otherwise, zero is returned. 
  16962.           When an error has occurred, errno contains a value indicating the 
  16963.           type of error that has been detected. 
  16964.  
  16965. See Also: abort, atexit, exec Functions, exit, _exit, getcmd, getenv, main, 
  16966.           onexit, putenv, spawn Functions 
  16967.  
  16968. Example: 
  16969.  
  16970.                     #include <stdlib.h>
  16971.                     #include <stdio.h>
  16972.  
  16973.                     void main()
  16974.                       {
  16975.                         int rc;
  16976.  
  16977.                         rc = system( "dir" );
  16978.                         if( rc != 0 ) {
  16979.                           printf( "shell could not be run\n" );
  16980.                         }
  16981.                       }
  16982.  
  16983. Classification: ANSI 
  16984.  
  16985.  
  16986. ΓòÉΓòÉΓòÉ 305. tan ΓòÉΓòÉΓòÉ
  16987.  
  16988. Synopsis: 
  16989.  
  16990.                     #include <math.h>
  16991.                     double tan( double x );
  16992.  
  16993. Description: The tan function computes the tangent of x (measured in radians). 
  16994.           A large magnitude argument may yield a result with little or no 
  16995.           significance. 
  16996.  
  16997. Returns:  The tan function returns the tangent value.  When an error has 
  16998.           occurred, errno contains a value indicating the type of error that 
  16999.           has been detected. 
  17000.  
  17001. See Also: atan, atan2, cos, sin, tanh 
  17002.  
  17003. Example: 
  17004.  
  17005.                     #include <stdio.h>
  17006.                     #include <math.h>
  17007.  
  17008.                     void main()
  17009.                       {
  17010.                         printf( "%f\n", tan(.5) );
  17011.                       }
  17012.  
  17013.           produces the following: 
  17014.  
  17015.                     0.546302
  17016.  
  17017. Classification: ANSI 
  17018.  
  17019.  
  17020. ΓòÉΓòÉΓòÉ 306. tanh ΓòÉΓòÉΓòÉ
  17021.  
  17022. Synopsis: 
  17023.  
  17024.                     #include <math.h>
  17025.                     double tanh( double x );
  17026.  
  17027. Description: The tanh function computes the hyperbolic tangent of x. 
  17028.  
  17029.           When the x argument is large, partial or total loss of significance 
  17030.           may occur.  The matherr function will be invoked in this case. 
  17031.  
  17032. Returns:  The tanh function returns the hyperbolic tangent value. When an error 
  17033.           has occurred, errno contains a value indicating the type of error 
  17034.           that has been detected. 
  17035.  
  17036. See Also: cosh, sinh, matherr 
  17037.  
  17038. Example: 
  17039.  
  17040.                     #include <stdio.h>
  17041.                     #include <math.h>
  17042.  
  17043.                     void main()
  17044.                       {
  17045.                         printf( "%f\n", tanh(.5) );
  17046.                       }
  17047.  
  17048.           produces the following: 
  17049.  
  17050.                     0.462117
  17051.  
  17052. Classification: ANSI 
  17053.  
  17054.  
  17055. ΓòÉΓòÉΓòÉ 307. tell ΓòÉΓòÉΓòÉ
  17056.  
  17057. Synopsis: 
  17058.  
  17059.                     #include <io.h>
  17060.                     long int tell( int handle );
  17061.  
  17062. Description: The tell function determines the current file position at the 
  17063.           operating system level.  The handle value is the file handle returned 
  17064.           by a successful execution of the open function. 
  17065.  
  17066.           The returned value may be used in conjunction with the lseek function 
  17067.           to reset the current file position. 
  17068.  
  17069. Returns:  When an error occurs, -1 is returned.  When an error has occurred, 
  17070.           errno contains a value indicating the type of error that has been 
  17071.           detected. 
  17072.  
  17073.           Otherwise, the current file position is returned in a 
  17074.           system-dependent manner.  A value of 0 indicates the start of the 
  17075.           file. 
  17076.  
  17077. See Also: close, creat, dup, dup2, eof, exec Functions, filelength, fileno, 
  17078.           fstat, isatty, lseek, open, read, setmode, sopen, stat, write, umask 
  17079.  
  17080. Example: 
  17081.  
  17082.                     #include <stdio.h>
  17083.                     #include <sys\stat.h>
  17084.                     #include <io.h>
  17085.                     #include <fcntl.h>
  17086.  
  17087.                     const char buffer[]
  17088.                             = { "A text record to be written" };
  17089.                     void main()
  17090.                       {
  17091.                         int handle;
  17092.                         int size_written;
  17093.  
  17094.                         /* open a file for output             */
  17095.                         /* replace existing file if it exists */
  17096.  
  17097.                         handle = open( "file",
  17098.                                     O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
  17099.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  17100.                         if( handle != -1 ) {
  17101.  
  17102.                           /* print file position */
  17103.                           printf( "%ld\n", tell( handle ) );
  17104.  
  17105.                           /* write the text */
  17106.                           size_written = write( handle,
  17107.                                               buffer, sizeof( buffer ) );
  17108.  
  17109.                           /* print file position */
  17110.                           printf( "%ld\n", tell( handle ) );
  17111.  
  17112.                           /* close the file */
  17113.                           close( handle );
  17114.                         }
  17115.                       }
  17116.  
  17117.           produces the following: 
  17118.  
  17119.                     0
  17120.                     28
  17121.  
  17122. Classification: WATCOM 
  17123.  
  17124.  
  17125. ΓòÉΓòÉΓòÉ 308. time ΓòÉΓòÉΓòÉ
  17126.  
  17127. Synopsis: 
  17128.  
  17129.                     #include <time.h>
  17130.                     time_t time( time_t *tloc );
  17131.  
  17132. Description: The time function determines the current calendar time and encodes 
  17133.           it into the type time_t. 
  17134.  
  17135.           The time represents the time since January 1, 1970 Coordinated 
  17136.           Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)). 
  17137.  
  17138.           The time set on the computer with the DOS time command and the DOS 
  17139.           date command reflects the local time.  The environment variable TZ is 
  17140.           used to establish the time zone to which this local time applies. 
  17141.           See the section The TZ Environment Variable  for a discussion of how 
  17142.           to set the time zone. 
  17143.  
  17144. Returns:  The time function returns the current calendar time.  If tloc is not 
  17145.           NULL, the current calendar time is also stored in the object pointed 
  17146.           to by tloc. 
  17147.  
  17148. See Also: asctime, clock, ctime, difftime, gmtime, localtime, mktime, strftime, 
  17149.           tzset 
  17150.  
  17151. Example: 
  17152.  
  17153.                     #include <stdio.h>
  17154.                     #include <time.h>
  17155.  
  17156.                     void main()
  17157.                       {
  17158.                         time_t time_of_day;
  17159.  
  17160.                         time_of_day = time( NULL );
  17161.                         printf( "It is now: %s", ctime( &time_of_day ) );
  17162.                       }
  17163.  
  17164.           produces the following: 
  17165.  
  17166.                     It is now: Fri Dec 25 15:58:42 1987
  17167.  
  17168. Classification: ANSI, POSIX 1003.1 
  17169.  
  17170.  
  17171. ΓòÉΓòÉΓòÉ 309. tmpfile ΓòÉΓòÉΓòÉ
  17172.  
  17173. Synopsis: 
  17174.  
  17175.                     #include <stdio.h>
  17176.                     FILE *tmpfile( void );
  17177.  
  17178. Description: The tmpfile function creates a temporary binary file that will 
  17179.           automatically be removed when it is closed or at program termination. 
  17180.           The file is opened for update. 
  17181.  
  17182. Returns:  The tmpfile function returns a pointer to the stream of the file that 
  17183.           it created.  If the file cannot be created, the tmpfile function 
  17184.           returns NULL. When an error has occurred, errno contains a value 
  17185.           indicating the type of error that has been detected. 
  17186.  
  17187. See Also: fopen, freopen, tmpnam 
  17188.  
  17189. Example: 
  17190.  
  17191.                     #include <stdio.h>
  17192.  
  17193.                     static FILE *TempFile;
  17194.  
  17195.                     void main()
  17196.                       {
  17197.                         TempFile = tmpfile();
  17198.                         .
  17199.                         .
  17200.                         .
  17201.                       }
  17202.  
  17203. Classification: ANSI 
  17204.  
  17205.  
  17206. ΓòÉΓòÉΓòÉ 310. tmpnam ΓòÉΓòÉΓòÉ
  17207.  
  17208. Synopsis: 
  17209.  
  17210.                     #include <stdio.h>
  17211.                     char *tmpnam( char *buffer );
  17212.  
  17213. Description: The tmpnam function generates a unique string for use as a valid 
  17214.           filename. 
  17215.  
  17216. Returns:  If the argument buffer is a NULL pointer, the tmpnam function leaves 
  17217.           its result in an internal static buffer and returns a pointer to that 
  17218.           buffer.  If the argument buffer is not a NULL pointer, it is assumed 
  17219.           to point to an array of at least L_tmpnam characters; the tmpnam 
  17220.           function stores its result in that array and returns the argument 
  17221.           buffer as its value. 
  17222.  
  17223.           Because a static buffer is used to contain the filename when NULL is 
  17224.           passed, the string indicated by an initial call to tmpnam will be 
  17225.           changed when a subsequent call to tmpnam is made (with a NULL 
  17226.           argument). 
  17227.  
  17228. See Also: tmpfile 
  17229.  
  17230. Example: 
  17231.  
  17232.                     #include <stdio.h>
  17233.  
  17234.                     void main()
  17235.                       {
  17236.                         char filename[ L_tmpnam ];
  17237.                         FILE *fp;
  17238.  
  17239.                         tmpnam( filename );
  17240.                         fp = fopen( filename, "w+b" );
  17241.                         .
  17242.                         .
  17243.                         .
  17244.                         fclose( fp );
  17245.                         remove( filename );
  17246.                       }
  17247.  
  17248. Classification: ANSI 
  17249.  
  17250.  
  17251. ΓòÉΓòÉΓòÉ 311. tolower ΓòÉΓòÉΓòÉ
  17252.  
  17253. Synopsis: 
  17254.  
  17255.                     #include <ctype.h>
  17256.                     int tolower( int c );
  17257.  
  17258. Description: The tolower function converts an upper-case letter to the 
  17259.           corresponding lower-case letter. 
  17260.  
  17261. Returns:  The tolower function returns the corresponding lower-case letter when 
  17262.           the argument is an upper-case letter; otherwise, the original 
  17263.           character is returned. 
  17264.  
  17265. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, 
  17266.           ispunct, isspace, isupper, isxdigit, strlwr, strupr, toupper 
  17267.  
  17268. Classification: ANSI 
  17269.  
  17270.  
  17271. ΓòÉΓòÉΓòÉ 312. toupper ΓòÉΓòÉΓòÉ
  17272.  
  17273. Synopsis: 
  17274.  
  17275.                     #include <ctype.h>
  17276.                     int toupper( int c );
  17277.  
  17278. Description: The function converts a lower-case character to the corresponding 
  17279.           upper-case character. 
  17280.  
  17281. Returns:  The toupper function returns the corresponding upper-case letter when 
  17282.           the argument is an lower-case letter; otherwise, the original 
  17283.           character is returned. 
  17284.  
  17285. See Also: isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, 
  17286.           ispunct, isspace, isupper, isxdigit, strlwr, strupr, tolower 
  17287.  
  17288. Classification: ANSI 
  17289.  
  17290.  
  17291. ΓòÉΓòÉΓòÉ 313. tzset ΓòÉΓòÉΓòÉ
  17292.  
  17293. Synopsis: 
  17294.  
  17295.                     #include <time.h>
  17296.                     void tzset( void );
  17297.  
  17298. Description: The tzset function sets the global variables daylight, timezone 
  17299.           and tzname according to the value of the TZ environment variable. 
  17300.           The section The TZ Environment Variable  describes how to set this 
  17301.           variable. 
  17302.  
  17303.           The global variables have the following values after tzset is 
  17304.           executed: 
  17305.  
  17306.    daylight  Zero indicates that daylight saving time is not supported in the 
  17307.              locale; a non-zero value indicates that daylight saving time is 
  17308.              supported in the locale.  This variable is cleared/set after a 
  17309.              call to the tzset function depending on whether a daylight saving 
  17310.              time abbreviation is specified in the TZ environment variable. 
  17311.  
  17312.    timezone  Contains the number of seconds that the local time zone is earlier 
  17313.              than Coordinated Universal Time (UTC) (formerly known as Greenwich 
  17314.              Mean Time (GMT)). 
  17315.  
  17316.    tzname    Two-element array pointing to strings giving the abbreviations for 
  17317.              the name of the time zone when standard and daylight saving time 
  17318.              are in effect. 
  17319.  
  17320.           The time set on the computer with the DOS time command and the DOS 
  17321.           date command reflects the local time.  The environment variable TZ is 
  17322.           used to establish the time zone to which this local time applies. 
  17323.           See the section The TZ Environment Variable  for a discussion of how 
  17324.           to set the time zone. 
  17325.  
  17326. Returns:  The function does not return a value. 
  17327.  
  17328. See Also: ctime, localtime, mktime, strftime 
  17329.  
  17330. Example: 
  17331.  
  17332.                     #include <stdio.h>
  17333.                     #include <env.h>
  17334.                     #include <time.h>
  17335.                     void main()
  17336.                       {
  17337.                         print_zone();
  17338.                         setenv( "TZ", "PST8PDT", 1 );
  17339.                         tzset();
  17340.                         print_zone();
  17341.                       }
  17342.                     void print_zone()
  17343.                       {
  17344.                         char *tz;
  17345.  
  17346.                         printf( "TZ: %s\n", (tz = getenv( "TZ" ))
  17347.                                         ? tz : "default EST5EDT" );
  17348.                         printf( "  daylight: %d\n", daylight );
  17349.                         printf( "  timezone: %ld\n", timezone );
  17350.                         printf( "  time zone names: %s %s\n",
  17351.                                 tzname[1], tzname[2] );
  17352.                       }
  17353.  
  17354.           produces the following: 
  17355.  
  17356.                     TZ: default EST5EDT
  17357.                       daylight: 1
  17358.                       timezone: 18000
  17359.                       time zone names: EST EDT
  17360.                     TZ: PST8PDT
  17361.                       daylight: 1
  17362.                       timezone: 28800
  17363.                       time zone names: PST PDT
  17364.  
  17365. Classification: POSIX 1003.1 
  17366.  
  17367.  
  17368. ΓòÉΓòÉΓòÉ 314. ultoa ΓòÉΓòÉΓòÉ
  17369.  
  17370. Synopsis: 
  17371.  
  17372.                     #include <stdlib.h>
  17373.                     char *ultoa( unsigned long int value,
  17374.                                  char *buffer,
  17375.                                  int radix );
  17376.  
  17377. Description: The ultoa function converts the unsigned binary integer value into 
  17378.           the equivalent string in base radix notation storing the result in 
  17379.           the character array pointed to by buffer. A null character is 
  17380.           appended to the result.  The size of buffer must be at least 33 bytes 
  17381.           when converting values in base 2. 
  17382.  
  17383. Returns:  The ultoa function returns the pointer to the result. 
  17384.  
  17385. See Also: atol, ltoa, strtol, strtoul, utoa 
  17386.  
  17387. Example: 
  17388.  
  17389.                     #include <stdio.h>
  17390.                     #include <stdlib.h>
  17391.  
  17392.                     void print_value( unsigned long int value )
  17393.                       {
  17394.                         int base;
  17395.                         char buffer[18];
  17396.  
  17397.                         for( base=2; base<36; ++base )
  17398.                           printf( "%s\n", ultoa( value, buffer, base ) );
  17399.                       }
  17400.  
  17401. Classification: WATCOM 
  17402.  
  17403.  
  17404. ΓòÉΓòÉΓòÉ 315. umask ΓòÉΓòÉΓòÉ
  17405.  
  17406. Synopsis: 
  17407.  
  17408.                     #include <sys\types.h>
  17409.                     #include <sys\stat.h>
  17410.                     #include <fcntl.h>
  17411.                     #include <io.h>
  17412.                     int umask( int cmask );
  17413.  
  17414. Description: The umask function sets the process's file mode creation mask to 
  17415.           cmask. The process's file mode creation mask is used during creat, 
  17416.           open, or sopen to turn off permission bits in the permission argument 
  17417.           supplied.  In other words, if a bit in the mask is on, then the 
  17418.           corresponding bit in the file's requested permission value is 
  17419.           disallowed. 
  17420.  
  17421.           The argument cmask is a constant expression involving the constants 
  17422.           described below.  The access permissions for the file or directory 
  17423.           are specified as a combination of bits (defined in the <sys\stat.h> 
  17424.           header file). 
  17425.  
  17426.           The following bits define permissions for the owner. 
  17427.  
  17428.    Permission    Meaning 
  17429.    S_IRWXU       Read, write, execute/search 
  17430.    S_IRUSR       Read permission 
  17431.    S_IWUSR       Write permission 
  17432.    S_IXUSR       Execute/search permission 
  17433.  
  17434.           The following bits define permissions for the group. 
  17435.  
  17436.    Permission    Meaning 
  17437.    S_IRWXG       Read, write, execute/search 
  17438.    S_IRGRP       Read permission 
  17439.    S_IWGRP       Write permission 
  17440.    S_IXGRP       Execute/search permission 
  17441.  
  17442.           The following bits define permissions for others. 
  17443.  
  17444.    Permission    Meaning 
  17445.    S_IRWXO       Read, write, execute/search 
  17446.    S_IROTH       Read permission 
  17447.    S_IWOTH       Write permission 
  17448.    S_IXOTH       Execute/search permission 
  17449.  
  17450.           The following bits define miscellaneous permissions used by other 
  17451.           implementations. 
  17452.  
  17453.    Permission    Meaning 
  17454.    S_IREAD       is equivalent to S_IRUSR (read permission) 
  17455.    S_IWRITE      is equivalent to S_IWUSR (write permission) 
  17456.    S_IEXEC       is equivalent to S_IXUSR (execute/search permission) 
  17457.  
  17458.           For example, if S_IREAD is specified, then reading is not allowed 
  17459.           (i.e., the file is write only).  If S_IWRITE is specified, then 
  17460.           writing is not allowed (i.e., the file is read only). 
  17461.  
  17462. Returns:  The umask function returns the previous value of cmask. 
  17463.  
  17464. See Also: chmod, creat, open, sopen 
  17465.  
  17466. Example: 
  17467.  
  17468.                     #include <sys\types.h>
  17469.                     #include <sys\stat.h>
  17470.                     #include <fcntl.h>
  17471.                     #include <io.h>
  17472.  
  17473.                     void main()
  17474.                       {
  17475.                         int old_mask;
  17476.  
  17477.                         /* set mask to create read-only files */
  17478.                         old_mask = umask( S_IWUSR | S_IWGRP | S_IWOTH |
  17479.                                           S_IXUSR | S_IXGRP | S_IXOTH );
  17480.                       }
  17481.  
  17482. Classification: POSIX 1003.1 
  17483.  
  17484.  
  17485. ΓòÉΓòÉΓòÉ 316. ungetc ΓòÉΓòÉΓòÉ
  17486.  
  17487. Synopsis: 
  17488.  
  17489.                     #include <stdio.h>
  17490.                     int ungetc( int c, FILE *fp );
  17491.  
  17492. Description: The ungetc function pushes the character specified by c back onto 
  17493.           the input stream pointed to by fp. This character will be returned by 
  17494.           the next read on the stream.  The pushed-back character will be 
  17495.           discarded if a call is made to the fflush function or to a file 
  17496.           positioning function (fseek, fsetpos or rewind) before the next read 
  17497.           operation is performed. 
  17498.  
  17499.           Only one character (the most recent one) of pushback is remembered. 
  17500.  
  17501.           The ungetc function clears the end-of-file indicator, unless the 
  17502.           value of c is EOF. 
  17503.  
  17504. Returns:  The ungetc function returns the character pushed back. 
  17505.  
  17506. See Also: fopen, getc 
  17507.  
  17508. Example: 
  17509.  
  17510.                     #include <stdio.h>
  17511.  
  17512.                     void main()
  17513.                       {
  17514.                         FILE *fp;
  17515.                         int c, value;
  17516.  
  17517.                         fp = fopen( "data.fil", "r" );
  17518.                         value = 0;
  17519.                         c = fgetc( fp );
  17520.                         while( isdigit(c) ) {
  17521.                             value = value*10 + c - '0';
  17522.                             c = fgetc( fp );
  17523.                         }
  17524.                         ungetc( c, fp ); /* put last character back */
  17525.                         fclose( fp );
  17526.                       }
  17527.  
  17528. Classification: ANSI 
  17529.  
  17530.  
  17531. ΓòÉΓòÉΓòÉ 317. ungetch ΓòÉΓòÉΓòÉ
  17532.  
  17533. Synopsis: 
  17534.  
  17535.                     #include <conio.h>
  17536.                     int ungetch( int c );
  17537.  
  17538. Description: The ungetch function pushes the character specified by c back onto 
  17539.           the input stream for the console.  This character will be returned by 
  17540.           the next read from the console (with getch or getche functions) and 
  17541.           will be detected by the function kbhit. Only the last character 
  17542.           returned in this way is remembered. 
  17543.  
  17544.           The ungetch function clears the end-of-file indicator, unless the 
  17545.           value of c is EOF. 
  17546.  
  17547. Returns:  The ungetch function returns the character pushed back. 
  17548.  
  17549. See Also: getch, getche, kbhit, putch 
  17550.  
  17551. Example: 
  17552.  
  17553.                     #include <conio.h>
  17554.  
  17555.                     void main()
  17556.                       {
  17557.                         int c, value;
  17558.  
  17559.                         value = 0;
  17560.                         c = getche();
  17561.                         while( isdigit( c ) ) {
  17562.                             value = value*10 + c - '0';
  17563.                             c = getche();
  17564.                         }
  17565.                         ungetch( c );
  17566.                       }
  17567.  
  17568. Classification: WATCOM 
  17569.  
  17570.  
  17571. ΓòÉΓòÉΓòÉ 318. unlink ΓòÉΓòÉΓòÉ
  17572.  
  17573. Synopsis: 
  17574.  
  17575.                     #include <io.h>
  17576.                     int unlink( const char *path );
  17577.  
  17578. Description: The unlink function deletes the file whose name is the string 
  17579.           pointed to by path. This function is equivalent to the remove 
  17580.           function. 
  17581.  
  17582. Returns:  The unlink function returns zero if the operation succeeds, non-zero 
  17583.           if it fails. 
  17584.  
  17585. See Also: chdir, chmod, close, getcwd, mkdir, open, remove, rename 
  17586.  
  17587. Example: 
  17588.  
  17589.                     #include <io.h>
  17590.  
  17591.                     void main()
  17592.                       {
  17593.                         unlink( "vm.tmp" );
  17594.                       }
  17595.  
  17596. Classification: POSIX 1003.1 
  17597.  
  17598.  
  17599. ΓòÉΓòÉΓòÉ 319. unlock ΓòÉΓòÉΓòÉ
  17600.  
  17601. Synopsis: 
  17602.  
  17603.                     #include <io.h>
  17604.                     int unlock( int handle,
  17605.                                 unsigned long offset,
  17606.                                 unsigned long nbytes );
  17607.  
  17608. Description: The unlock function unlocks nbytes amount of previously locked 
  17609.           data in the file designated by handle starting at byte offset in the 
  17610.           file.  This allows other processes to lock this region of the file. 
  17611.  
  17612.           All locked regions of a file must be unlocked before a file is 
  17613.           closed. 
  17614.  
  17615. Returns:  The unlock function returns zero if successful, and -1 when an error 
  17616.           occurs.  When an error has occurred, errno contains a value 
  17617.           indicating the type of error that has been detected. 
  17618.  
  17619. See Also: lock, locking, open, sopen 
  17620.  
  17621. Example: 
  17622.  
  17623.                     #include <stdio.h>
  17624.                     #include <fcntl.h>
  17625.                     #include <io.h>
  17626.  
  17627.                     void main()
  17628.                       {
  17629.                         int handle;
  17630.                         char buffer[20];
  17631.  
  17632.                         handle = open( "file", O_RDWR | O_TEXT );
  17633.                         if( handle != -1 ) {
  17634.                           if( lock( handle, 0L, 20L ) ) {
  17635.                             printf( "Lock failed\n" );
  17636.                           } else {
  17637.                             read( handle, buffer, 20 );
  17638.                             /* update the buffer here */
  17639.                             lseek( handle, 0L, SEEK_SET );
  17640.                             write( handle, buffer, 20 );
  17641.                             unlock( handle, 0L, 20L );
  17642.                           }
  17643.                           close( handle );
  17644.                         }
  17645.                       }
  17646.  
  17647. Classification: WATCOM 
  17648.  
  17649.  
  17650. ΓòÉΓòÉΓòÉ 320. utime ΓòÉΓòÉΓòÉ
  17651.  
  17652. Synopsis: 
  17653.  
  17654.                     #include <sys\utime.h>
  17655.                     int utime( const char *path, const struct utimbuf *times );
  17656.                     struct utimbuf {
  17657.                         time_t   actime;    /* access time */
  17658.                         time_t   modtime;   /* modification time */
  17659.                     };
  17660.  
  17661. Description: The utime function records the access and modification times for 
  17662.           the file identified by path. Write access to this file must be 
  17663.           permitted for the time to be recorded. 
  17664.  
  17665.           When the times argument is NULL, the current time is recorded. 
  17666.           Otherwise, the argument must point at an object whose type is struct 
  17667.           utimbuf. The modification time is taken from the modtime field in 
  17668.           this structure. 
  17669.  
  17670. Returns:  The utime function returns zero when the time was successfully 
  17671.           recorded.  A value of -1 indicates an error occurred. 
  17672.  
  17673. Errors:   When an error has occurred, errno contains a value indicating the 
  17674.           type of error that has been detected. 
  17675.  
  17676.    Constant  Meaning 
  17677.  
  17678.    EACCES    Search permission is denied for a component of path or the times 
  17679.              argument is NULL and the effective user ID of the process does not 
  17680.              match the owner of the file and write access is denied. 
  17681.  
  17682.    EMFILE    There are too many open files. 
  17683.  
  17684.    ENOENT    The specified path does not exist or path is an empty string. 
  17685.  
  17686. Example: 
  17687.  
  17688.                     #include <stdio.h>
  17689.                     #include <sys\utime.h>
  17690.  
  17691.                     void main( int argc, char *argv[] )
  17692.                       {
  17693.                         if( (utime( argv[1], NULL ) != 0) && (argc > 1) ) {
  17694.                            printf( "Unable to set time for %s\n", argv[1] );
  17695.                         }
  17696.                       }
  17697.  
  17698. Classification: POSIX 1003.1 
  17699.  
  17700.  
  17701. ΓòÉΓòÉΓòÉ 321. utoa ΓòÉΓòÉΓòÉ
  17702.  
  17703. Synopsis: 
  17704.  
  17705.                     #include <stdlib.h>
  17706.                     char *utoa( unsigned int value,
  17707.                                 char *buffer,
  17708.                                 int radix );
  17709.  
  17710. Description: The utoa function converts the unsigned binary integer value into 
  17711.           the equivalent string in base radix notation storing the result in 
  17712.           the character array pointed to by buffer. A null character is 
  17713.           appended to the result.  The size of buffer must be at least (8 * 
  17714.           sizeof(int) + 1) bytes when converting values in base 2.  That makes 
  17715.           the size 17 bytes on 16-bit machines, and 33 bytes on 32-bit 
  17716.           machines. 
  17717.  
  17718. Returns:  The utoa function returns the pointer to the result. 
  17719.  
  17720. See Also: atoi, itoa, strtol, strtoul 
  17721.  
  17722. Example: 
  17723.  
  17724.                     #include <stdio.h>
  17725.                     #include <stdlib.h>
  17726.  
  17727.                     void print_value( unsigned int value )
  17728.                       {
  17729.                         int base;
  17730.                         char buffer[8*sizeof(int)+1];
  17731.  
  17732.                         for( base=2; base<36; ++base )
  17733.                           printf( "%s\n", utoa( value, buffer, base ) );
  17734.                       }
  17735.  
  17736. Classification: WATCOM 
  17737.  
  17738.  
  17739. ΓòÉΓòÉΓòÉ 322. va_arg ΓòÉΓòÉΓòÉ
  17740.  
  17741. Synopsis: 
  17742.  
  17743.                     #include <stdarg.h>
  17744.                     type va_arg( va_list param, type );
  17745.  
  17746. Description: va_arg is a macro that can be used to obtain the next argument in 
  17747.           a list of variable arguments.  It must be used with the associated 
  17748.           macros va_start and va_end. A sequence such as 
  17749.  
  17750.                         va_list curr_arg;
  17751.                         type next_arg;
  17752.  
  17753.                         next_arg = va_arg( curr_arg, type );
  17754.  
  17755.           causes next_arg to be assigned the value of the next variable 
  17756.           argument.  The type is the type of the argument originally passed. 
  17757.  
  17758.           The macro va_start must be executed first in order to properly 
  17759.           initialize the variable next_arg and the macro va_end should be 
  17760.           executed after all arguments have been obtained. 
  17761.  
  17762.           The data item curr_arg is of type va_list which contains the 
  17763.           information to permit successive acquisitions of the arguments. 
  17764.  
  17765. Returns:  The macro returns the value of the next variable argument, according 
  17766.           to type passed as the second parameter. 
  17767.  
  17768. See Also: va_end, va_start, vfprintf, vprintf, vsprintf 
  17769.  
  17770. Example: 
  17771.  
  17772.                     #include <stdio.h>
  17773.                     #include <stdarg.h>
  17774.                     void test_fn( const char *msg,
  17775.                                   const char *types,
  17776.                                   ... );
  17777.                     void main()
  17778.                       {
  17779.                         printf( "VA...TEST\n" );
  17780.                         test_fn( "PARAMETERS: 1, \"abc\", 546",
  17781.                                  "isi", 1, "abc", 546 );
  17782.                         test_fn( "PARAMETERS: \"def\", 789",
  17783.                                  "si", "def", 789 );
  17784.                       }
  17785.                     static void test_fn(
  17786.                       const char *msg,   /* message to be printed    */
  17787.                       const char *types, /* parameter types (i,s)    */
  17788.                       ... )              /* variable arguments       */
  17789.                       {
  17790.                         va_list argument;
  17791.                         int   arg_int;
  17792.                         char *arg_string;
  17793.                         const char *types_ptr;
  17794.                         types_ptr = types;
  17795.                         printf( "\n%s -- %s\n", msg, types );
  17796.                         va_start( argument, types );
  17797.                         while( *types_ptr != '\0' ) {
  17798.                           if (*types_ptr == 'i') {
  17799.                             arg_int = va_arg( argument, int );
  17800.                             printf( "integer: %d\n", arg_int );
  17801.                           } else if (*types_ptr == 's') {
  17802.                             arg_string = va_arg( argument, char * );
  17803.                             printf( "string:  %s\n", arg_string );
  17804.                           }
  17805.                           ++types_ptr;
  17806.                         }
  17807.                         va_end( argument );
  17808.                       }
  17809.  
  17810.           produces the following: 
  17811.  
  17812.                     VA...TEST
  17813.  
  17814.                     PARAMETERS: 1, "abc", 546 -- isi
  17815.                     integer: 1
  17816.                     string:  abc
  17817.                     integer: 546
  17818.  
  17819.                     PARAMETERS: "def", 789 -- si
  17820.                     string:  def
  17821.                     integer: 789
  17822.  
  17823. Classification: ANSI 
  17824.  
  17825.  
  17826. ΓòÉΓòÉΓòÉ 323. va_end ΓòÉΓòÉΓòÉ
  17827.  
  17828. Synopsis: 
  17829.  
  17830.                     #include <stdarg.h>
  17831.                     void va_end( va_list param );
  17832.  
  17833. Description: va_end is a macro used to complete the acquisition of arguments 
  17834.           from a list of variable arguments.  It must be used with the 
  17835.           associated macros va_start and va_arg. See the description for va_arg 
  17836.           for complete documentation on these macros. 
  17837.  
  17838. Returns:  The macro does not return a value. 
  17839.  
  17840. See Also: va_arg, va_start, vfprintf, vprintf, vsprintf 
  17841.  
  17842. Classification: ANSI 
  17843.  
  17844.  
  17845. ΓòÉΓòÉΓòÉ 324. va_start ΓòÉΓòÉΓòÉ
  17846.  
  17847. Synopsis: 
  17848.  
  17849.                     #include <stdarg.h>
  17850.                     void va_start( va_list param, previous );
  17851.  
  17852. Description: va_start is a macro used to start the acquisition of arguments 
  17853.           from a list of variable arguments.  The param argument is used by the 
  17854.           va_arg macro to locate the current acquired argument.  The previous 
  17855.           argument is the argument that immediately precedes the "..." notation 
  17856.           in the original function definition.  It must be used with the 
  17857.           associated macros va_arg and va_end. See the description of va_arg 
  17858.           for complete documentation on these macros. 
  17859.  
  17860. Returns:  The macro does not return a value. 
  17861.  
  17862. See Also: va_arg, va_end, vfprintf, vprintf, vsprintf 
  17863.  
  17864. Classification: ANSI 
  17865.  
  17866.  
  17867. ΓòÉΓòÉΓòÉ 325. vfprintf ΓòÉΓòÉΓòÉ
  17868.  
  17869. Synopsis: 
  17870.  
  17871.                     #include <stdio.h>
  17872.                     #include <stdarg.h>
  17873.                     int vfprintf( FILE *fp,
  17874.                                   const char *format,
  17875.                                   va_list arg );
  17876.  
  17877. Description: The vfprintf function writes output to the file pointed to by fp 
  17878.           under control of the argument format. The format string is described 
  17879.           under the description of the printf function.  The vfprintf function 
  17880.           is equivalent to the fprintf function, with the variable argument 
  17881.           list replaced with arg, which has been initialized by the va_start 
  17882.           macro. 
  17883.  
  17884. Returns:  The vfprintf function returns the number of characters written, or a 
  17885.           negative value if an output error occurred.  When an error has 
  17886.           occurred, errno contains a value indicating the type of error that 
  17887.           has been detected. 
  17888.  
  17889. See Also: cprintf, fprintf, printf, sprintf, va_arg, va_end, va_start, vprintf, 
  17890.           vsprintf 
  17891.  
  17892. Example: 
  17893.  
  17894.                     #include <stdio.h>
  17895.                     #include <stdarg.h>
  17896.  
  17897.                     extern FILE *LogFile;
  17898.  
  17899.                     /* a general error routine */
  17900.  
  17901.                     void errmsg( char *format, ... )
  17902.                       {
  17903.                         va_list arglist;
  17904.  
  17905.                         va_start( arglist, format );
  17906.                         vfprintf( stderr, format, arglist );
  17907.                         va_end( arglist );
  17908.                         if( LogFile != NULL ) {
  17909.                           va_start( arglist, format );
  17910.                           vfprintf( LogFile, format, arglist );
  17911.                           va_end( arglist );
  17912.                         }
  17913.                       }
  17914.  
  17915. Classification: ANSI 
  17916.  
  17917.  
  17918. ΓòÉΓòÉΓòÉ 326. vfscanf ΓòÉΓòÉΓòÉ
  17919.  
  17920. Synopsis: 
  17921.  
  17922.                     #include <stdio.h>
  17923.                     #include <stdarg.h>
  17924.                     int vfscanf( FILE *fp,
  17925.                                  const char *format,
  17926.                                  va_list arg );
  17927.  
  17928. Description: The vfscanf function scans input from the file designated by fp 
  17929.           under control of the argument format. The format string is described 
  17930.           under the description of the scanf function. 
  17931.  
  17932.           The vfscanf function is equivalent to the fscanf function, with a 
  17933.           variable argument list replaced with arg, which has been initialized 
  17934.           using the va_start macro. 
  17935.  
  17936. Returns:  The vfscanf function returns EOF when the scanning is terminated by 
  17937.           reaching the end of the input stream.  Otherwise, the number of input 
  17938.           arguments for which values were successfully scanned and stored is 
  17939.           returned.  When a file input error occurs, the errno global variable 
  17940.           may be set. 
  17941.  
  17942. See Also: fscanf, scanf, sscanf, va_arg, va_end, va_start 
  17943.  
  17944. Example: 
  17945.  
  17946.                     #include <stdio.h>
  17947.                     #include <stdarg.h>
  17948.  
  17949.                     void ffind( FILE *fp,
  17950.                                 char *format,
  17951.                                 char *arg, ... )
  17952.                       {
  17953.                         va_list arglist;
  17954.  
  17955.                         va_start( arglist, arg );
  17956.                         vfscanf( fp, format, arglist );
  17957.                         va_end( arglist );
  17958.                       }
  17959.  
  17960. Classification: WATCOM 
  17961.  
  17962.  
  17963. ΓòÉΓòÉΓòÉ 327. vprintf ΓòÉΓòÉΓòÉ
  17964.  
  17965. Synopsis: 
  17966.  
  17967.                     #include <stdio.h>
  17968.                     #include <stdarg.h>
  17969.                     int vprintf( const char *format, va_list arg );
  17970.  
  17971. Description: The vprintf function writes output to the file stdout under 
  17972.           control of the argument format. The format string is described under 
  17973.           the description of the printf function.  The vprintf function is 
  17974.           equivalent to the printf function, with the variable argument list 
  17975.           replaced with arg, which has been initialized by the va_start macro. 
  17976.  
  17977. Returns:  The vprintf function returns the number of characters written, or a 
  17978.           negative value if an output error occurred.  When an error has 
  17979.           occurred, errno contains a value indicating the type of error that 
  17980.           has been detected. 
  17981.  
  17982. See Also: cprintf, fprintf, printf, sprintf, va_arg, va_end, va_start, 
  17983.           vfprintf, vsprintf 
  17984.  
  17985. Example: 
  17986.  
  17987.           The following shows the use of vprintf in a general error message 
  17988.           routine. 
  17989.  
  17990.                     #include <stdio.h>
  17991.                     #include <stdarg.h>
  17992.  
  17993.                     void errmsg( char *format, ... )
  17994.                       {
  17995.                         va_list arglist;
  17996.  
  17997.                         printf( "Error: " );
  17998.                         va_start( arglist, format );
  17999.                         vprintf( format, arglist );
  18000.                         va_end( arglist );
  18001.                       }
  18002.  
  18003.  
  18004. Classification: ANSI 
  18005.  
  18006.  
  18007. ΓòÉΓòÉΓòÉ 328. vscanf ΓòÉΓòÉΓòÉ
  18008.  
  18009. Synopsis: 
  18010.  
  18011.                     #include <stdio.h>
  18012.                     #include <stdarg.h>
  18013.                     int vscanf( const char *format,
  18014.                                 va_list arg );
  18015.  
  18016. Description: The vscanf function scans input from the file designated by stdin 
  18017.           under control of the argument format. The format string is described 
  18018.           under the description of the scanf function. 
  18019.  
  18020.           The vscanf function is equivalent to the scanf function, with a 
  18021.           variable argument list replaced with arg, which has been initialized 
  18022.           using the va_start macro. 
  18023.  
  18024. Returns:  The vscanf function returns EOF when the scanning is terminated by 
  18025.           reaching the end of the input stream.  Otherwise, the number of input 
  18026.           arguments for which values were successfully scanned and stored is 
  18027.           returned. 
  18028.  
  18029. See Also: fscanf, scanf, sscanf, va_arg, va_end, va_start 
  18030.  
  18031. Example: 
  18032.  
  18033.                     #include <stdio.h>
  18034.                     #include <stdarg.h>
  18035.  
  18036.                     void find( char *format,
  18037.                                char *arg, ... )
  18038.                       {
  18039.                         va_list arglist;
  18040.  
  18041.                         va_start( arglist, arg );
  18042.                         vscanf( format, arglist );
  18043.                         va_end( arglist );
  18044.                       }
  18045.  
  18046. Classification: WATCOM 
  18047.  
  18048.  
  18049. ΓòÉΓòÉΓòÉ 329. vsprintf ΓòÉΓòÉΓòÉ
  18050.  
  18051. Synopsis: 
  18052.  
  18053.                     #include <stdio.h>
  18054.                     #include <stdarg.h>
  18055.                     int vsprintf( char *buf,
  18056.                                   const char *format,
  18057.                                   va_list arg );
  18058.  
  18059. Description: The vsprintf function formats data under control of the format 
  18060.           control string and writes the result to buf. The format string is 
  18061.           described under the description of the printf function.  The vsprintf 
  18062.           function is equivalent to the sprintf function, with the variable 
  18063.           argument list replaced with arg, which has been initialized by the 
  18064.           va_start macro. 
  18065.  
  18066. Returns:  The vsprintf function returns the number of characters written, or a 
  18067.           negative value if an output error occurred. 
  18068.  
  18069. See Also: cprintf, fprintf, printf, sprintf, va_arg, va_end, va_start, 
  18070.           vfprintf, vprintf 
  18071.  
  18072. Example: 
  18073.  
  18074.           The following shows the use of vsprintf in a general error message 
  18075.           routine. 
  18076.  
  18077.                     #include <stdio.h>
  18078.                     #include <stdarg.h>
  18079.  
  18080.                     char msgbuf[80];
  18081.  
  18082.                     char *fmtmsg( char *format, ... )
  18083.                       {
  18084.                         va_list arglist;
  18085.  
  18086.                         va_start( arglist, format );
  18087.                         strcpy( msgbuf, "Error: " );
  18088.                         vsprintf( &msgbuf[7], format, arglist );
  18089.                         va_end( arglist );
  18090.                         return( msgbuf );
  18091.                       }
  18092.  
  18093.  
  18094. Classification: ANSI 
  18095.  
  18096.  
  18097. ΓòÉΓòÉΓòÉ 330. vsscanf ΓòÉΓòÉΓòÉ
  18098.  
  18099. Synopsis: 
  18100.  
  18101.                     #include <stdio.h>
  18102.                     #include <stdarg.h>
  18103.                     int vsscanf( const char *in_string,
  18104.                                  const char *format,
  18105.                                  va_list arg );
  18106.  
  18107. Description: The vsscanf function scans input from the string designated by 
  18108.           in_string under control of the argument format. The format string is 
  18109.           described under the description of the scanf function. 
  18110.  
  18111.           The vsscanf function is equivalent to the sscanf function, with a 
  18112.           variable argument list replaced with arg, which has been initialized 
  18113.           using the va_start macro. 
  18114.  
  18115. Returns:  The vsscanf function returns EOF when the scanning is terminated by 
  18116.           reaching the end of the input string.  Otherwise, the number of input 
  18117.           arguments for which values were successfully scanned and stored is 
  18118.           returned. 
  18119.  
  18120. See Also: fscanf, scanf, sscanf, va_arg, va_end, va_start 
  18121.  
  18122. Example: 
  18123.  
  18124.                     #include <stdio.h>
  18125.                     #include <stdarg.h>
  18126.  
  18127.                     void sfind( char *string,
  18128.                                 char *format,
  18129.                                 char *arg, ... )
  18130.                       {
  18131.                         va_list arglist;
  18132.  
  18133.                         va_start( arglist, arg )
  18134.                         vsscanf( string, format, arglist );
  18135.                         va_end( arglist );
  18136.                       }
  18137.  
  18138. Classification: WATCOM 
  18139.  
  18140.  
  18141. ΓòÉΓòÉΓòÉ 331. wait ΓòÉΓòÉΓòÉ
  18142.  
  18143. Synopsis: 
  18144.  
  18145.                     #include <process.h>
  18146.                     int wait( int *status );
  18147.  
  18148. Description: The wait function suspends the calling process until any of the 
  18149.           caller's immediate child processes terminate. 
  18150.  
  18151.           If status is not NULL, it points to a word that will be filled in 
  18152.           with the termination status word and return code of the terminated 
  18153.           child process. 
  18154.  
  18155.           If the child process terminated normally, then the low order byte of 
  18156.           the status word will be set to 0, and the high order byte will 
  18157.           contain the low order byte of the return code that the child process 
  18158.           passed to the DOSEXIT function.  The DOSEXIT function is called 
  18159.           whenever main returns, or exit or _exit are explicity called. 
  18160.  
  18161.           If the child process did not terminate normally, then the high order 
  18162.           byte of the status word will be set to 0, and the low order byte will 
  18163.           contain one of the following values: 
  18164.  
  18165.    Value     Meaning 
  18166.    1         Hard-error abort 
  18167.    2         Trap operation 
  18168.    3         SIGTERM signal not intercepted 
  18169.  
  18170. Returns:  The wait function returns the child's process id if the child process 
  18171.           terminated normally.  Otherwise, wait returns -1 and sets errno to 
  18172.           one of the following values: 
  18173.  
  18174.    Constant  Meaning 
  18175.  
  18176.    ECHILD    No child processes exist for the calling process. 
  18177.  
  18178.    EINTR     The child process terminated abnormally. 
  18179.  
  18180. See Also: cwait, exit, _exit, spawn Functions 
  18181.  
  18182. Example: 
  18183.  
  18184.                     #include <process.h>
  18185.  
  18186.                     void main()
  18187.                       {
  18188.                          int   process_id, status;
  18189.  
  18190.                          process_id = spawnl( P_NOWAIT, "child.exe",
  18191.                                     "child", "parm", NULL );
  18192.                          wait( &status );
  18193.                       }
  18194.  
  18195. Classification: OS/2 
  18196.  
  18197.  
  18198. ΓòÉΓòÉΓòÉ 332. wcstombs ΓòÉΓòÉΓòÉ
  18199.  
  18200. Synopsis: 
  18201.  
  18202.                     #include <stdlib.h>
  18203.                     size_t wcstombs( char *s,const wchar_t *pwcs,size_t n );
  18204.  
  18205. Description: The wcstombs function converts a sequence of wide character codes 
  18206.           from the array pointed to by pwcs into a sequence of multibyte 
  18207.           characters and stores them in the array pointed to by s. The wcstombs 
  18208.           function stops if a multibyte character would exceed the limit of n 
  18209.           total bytes, or if the null character is stored.  At most n bytes of 
  18210.           the array pointed to by s will be modified. 
  18211.  
  18212. Returns:  If an invalid multibyte character is encountered, the wcstombs 
  18213.           function returns (size_t)-1. Otherwise, the wcstombs function returns 
  18214.           the number of array elements modified, not including the terminating 
  18215.           zero code if present. 
  18216.  
  18217. See Also: mblen, mbtowc, mbstowcs, wctomb 
  18218.  
  18219. Classification: ANSI 
  18220.  
  18221.  
  18222. ΓòÉΓòÉΓòÉ 333. wctomb ΓòÉΓòÉΓòÉ
  18223.  
  18224. Synopsis: 
  18225.  
  18226.                     #include <stdlib.h>
  18227.                     int wctomb( char *s, wchar_t wchar );
  18228.  
  18229. Description: The wctomb function determines the number of bytes required to 
  18230.           represent the multibyte character corresponding to the code contained 
  18231.           in wchar. If s is not a NULL pointer, the multibyte character 
  18232.           representation is stored in the array pointed to by s. At most 
  18233.           MB_CUR_MAX characters will be stored. 
  18234.  
  18235. Returns:  If s is a NULL pointer, the wctomb function returns zero if multibyte 
  18236.           character encodings do not have state-dependent encoding, and 
  18237.           non-zero otherwise.  If s is not a NULL pointer, the wctomb function 
  18238.           returns: 
  18239.  
  18240.    Value     Meaning 
  18241.  
  18242.    -1        if the value of wchar does not correspond to a valid multibyte 
  18243.              character 
  18244.  
  18245.    len       the number of bytes that comprise the multibyte character 
  18246.              corresponding to the value of wchar. 
  18247.  
  18248. See Also: mblen, mbstowcs, mbtowc, wcstombs 
  18249.  
  18250. Classification: ANSI 
  18251.  
  18252.  
  18253. ΓòÉΓòÉΓòÉ 334. write ΓòÉΓòÉΓòÉ
  18254.  
  18255. Synopsis: 
  18256.  
  18257.                     #include <io.h>
  18258.                     int write( int handle, const char *buffer, int len );
  18259.  
  18260. Description: The write function writes data at the operating system level.  The 
  18261.           number of bytes transmitted is given by len and the data to be 
  18262.           transmitted is located at the address specified by buffer. 
  18263.  
  18264.           The handle value is returned by the open function.  The access mode 
  18265.           must have included either O_WRONLY or O_RDWR when the open function 
  18266.           was invoked. 
  18267.  
  18268.           The data is written to the file at the end when the file was opened 
  18269.           with O_APPEND included as part of the access mode; otherwise, it is 
  18270.           written at the current file position for the file in question.  This 
  18271.           file position can be determined with the tell function and can be set 
  18272.           with the lseek function. 
  18273.  
  18274.           When O_BINARY is included in the access mode, the data is transmitted 
  18275.           unchanged.  When O_TEXT is included in the access mode, the data is 
  18276.           transmitted with extra carriage return characters inserted before 
  18277.           each linefeed character encountered in the original data. 
  18278.  
  18279. Returns:  The write function returns the number of bytes (does not include any 
  18280.           extra carriage-return characters transmitted) of data transmitted to 
  18281.           the file.  When there is no error, this is the number given by the 
  18282.           len argument.  In the case of an error, such as there being no space 
  18283.           available to contain the file data, the return value will be less 
  18284.           than the number of bytes transmitted.  A value of -1 may be returned 
  18285.           in the case of some output errors.  When an error has occurred, errno 
  18286.           contains a value indicating the type of error that has been detected. 
  18287.  
  18288. See Also: close, creat, dup, dup2, eof, exec Functions, filelength, fileno, 
  18289.           fstat, isatty, lseek, open, read, setmode, sopen, stat, tell, umask 
  18290.  
  18291. Example: 
  18292.  
  18293.                     #include <stdio.h>
  18294.                     #include <io.h>
  18295.                     #include <fcntl.h>
  18296.                     const char buffer[]
  18297.                             = { "A text record to be written" };
  18298.                     void main()
  18299.                       {
  18300.                         int handle;
  18301.                         int size_written;
  18302.                         /* open a file for output             */
  18303.                         /* replace existing file if it exists */
  18304.                         handle = open( "file",
  18305.                                     O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
  18306.                                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
  18307.                         if( handle != -1 ) {
  18308.                           /* write the text                     */
  18309.                           size_written = write( handle, buffer,
  18310.                                                 sizeof( buffer ) );
  18311.                           /* test for error                     */
  18312.                           if( size_written != sizeof( buffer ) ) {
  18313.                               printf( "Error writing file\n" );
  18314.                           }
  18315.                           /* close the file                     */
  18316.                           close( handle );
  18317.                         }
  18318.                       }
  18319.  
  18320. Classification: POSIX 1003.1 
  18321.