home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / books / clibref.db < prev    next >
Encoding:
Text File  |  1991-03-01  |  1.6 MB  |  42,325 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1. %@1@%%@AB@%Microsoft  C - RUN-TIME LIBRARY REFERENCE%@AE@%%@EH@%%@NL@%
  2.                                       %@NL@%
  3.                                       %@NL@%
  4.                                       %@NL@%
  5.                                       %@NL@%
  6.                                       %@NL@%
  7.                                       %@NL@%
  8.                                       %@NL@%
  9.  
  10. ────────────────────────────────────────────────────────────────────────────%@NL@%
  11.                 %@AB@%Microsoft (R) C - RUN-TIME LIBRARY REFERENCE%@AE@%%@NL@%
  12.                                       %@NL@%
  13.                              %@AB@%FOR THE MS-DOS (R)
  14.                               %@AB@%OPERATING SYSTEM%@AE@%%@NL@%
  15. ────────────────────────────────────────────────────────────────────────────%@NL@%
  16.                                       %@NL@%
  17.                                       %@NL@%
  18.                            MICROSOFT CORPORATION %@NL@%
  19.                                       %@NL@%
  20. %@NL@%
  21. %@NL@%
  22. %@NL@%
  23. %@NL@%%@NL@%
  24. %@NL@%
  25.  
  26.  
  27. PUBLISHED BY
  28. Microsoft Press
  29. A Division of Microsoft Corporation
  30. One Microsoft Way, Redmond, Washington 98052-6399
  31.  
  32. Copyright (C)  1990 by Microsoft Press
  33.  
  34. All rights reserved. No part of the contents of this book may be reproduced
  35. or transmitted in any form or by any means without the written permission of
  36. the publisher.
  37.  
  38. Library of Congress Cataloging-in-Publication Data
  39.  
  40. Microsoft C run-time library reference.
  41.  
  42. Includes  index.
  43. 1. C (Computer program language) 2. Microsoft C
  44. (Computer program) 3. Macro instructions (Electronic
  45. computers) I. Microsoft.
  46. QA76.73.C15M52  1990         005.13'3         89-12240
  47. ISBN 1-55615-225-6
  48.  
  49. Printed and bound in the United States of America.
  50.  
  51. 1 2 3 4 5 6 7 8 9  HCHC 3 2 1 0 9
  52.  
  53. Distributed to the book trade in Canada by General Publishing Company, Ltd.
  54.  
  55. Distributed to the book trade outside the United States and Canada by
  56. Penguin
  57. Books  Ltd.
  58.  
  59. Penguin Books Ltd., Harmondsworth, Middlesex, England
  60. Penguin Books Australia Ltd., Ringwood, Victoria, Australia
  61. Penguin Books N.Z. Ltd., 182-190 Wairau Road, Auckland 10, New Zealand
  62.  
  63. British Cataloging in Publication Data available.
  64.  
  65.                                             %@AB@%Sample%@AE@%
  66. %@AB@%Writers:%@AE@%           %@AB@%Editors:%@AE@%                 %@AB@%Programs:%@AE@%
  67. Phil Nelson        Amanda Clark             Bruce McKinney
  68. Terry Ward         Moira Macdonald
  69.                    Marjorie Manwaring
  70.                    Bill Nolan%@NL@%
  71. %@NL@%
  72. Microsoft, the Microsoft logo, MS-DOS, QuickC, and XENIX are
  73. registered trademarks and Windows is a trademark of Microsoft Corporation.%@NL@%
  74. %@NL@%
  75. AT&T and UNIX are registered trademarks of American Telephone
  76. and Telegraph Company.%@NL@%
  77. %@NL@%
  78. Hercules is a registered trademark of Hercules Computer
  79. Technology.%@NL@%
  80. %@NL@%
  81. IBM is a registered trademark of International Business
  82. Machines Corporation.%@NL@%
  83. %@NL@%
  84. Olivetti is a registered trademark of Ing. C. Olivetti.%@NL@%
  85. %@NL@%
  86. Document No. 410840021-520-R00-1088
  87. Part No. 04412%@NL@%
  88. %@NL@%
  89. %@NL@%
  90. %@NL@%
  91. %@NL@%
  92. %@1@%%@AB@%Table of Contents%@AE@%%@EH@%%@NL@%
  93. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@NL@%
  94. %@NL@%
  95.  
  96. %@NL@%
  97. %@AB@%Introduction%@AE@%%@BO:        60e8@%%@NL@%
  98.      About the C Run-Time Library%@BO:        681f@%%@NL@%
  99.             ANSI C Compatibility%@BO:        6ad6@%%@NL@%
  100.             OS/2 and XENIX(R) Programming%@BO:        6ef0@%%@NL@%
  101.             Expanded Graphics Library%@BO:        7195@%%@NL@%
  102.      About This Book%@BO:        7603@%%@NL@%
  103.      Other Books of Interest%@BO:        7cc7@%%@NL@%
  104.      Document Conventions%@BO:        8d75@%%@NL@%
  105. %@NL@%
  106. %@NL@%
  107. %@AB@%PART I%@AE@%%@BO:        9ce2@%  %@AB@%Overview%@AE@%%@NL@%
  108. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@NL@%
  109. %@NL@%
  110. %@NL@%
  111. %@AB@%Chapter 1%@AE@%%@BO:        9f3e@%  %@AB@%Using C Library Routines%@AE@%%@NL@%
  112. %@NL@%
  113.      1.1%@BO:        a17a@%   Calling Library Routines%@NL@%
  114.      1.2%@BO:        acbb@%   Using Header Files%@NL@%
  115.             1.2.1%@BO:        adcb@%    Including Necessary Definitions%@NL@%
  116.             1.2.2%@BO:        b402@%    Including Function Declarations%@NL@%
  117.      1.3%@BO:        c64f@%   File Names and Path Names%@NL@%
  118.      1.4%@BO:        cd69@%   Choosing Between Functions and Macros%@NL@%
  119.      1.5%@BO:        e2d8@%   Stack Checking on Entry%@NL@%
  120.      1.6%@BO:        e7ec@%   Handling Errors%@NL@%
  121.      1.7%@BO:        f3f7@%   Operating-System Considerations%@NL@%
  122.      1.8%@BO:        ff84@%   Floating-Point Support%@NL@%
  123.      1.9%@BO:       1101b@%   Using Huge Arrays with Library Functions%@NL@%
  124. %@NL@%
  125. %@AB@%Chapter 2%@AE@%%@BO:       117ed@%  %@AB@%Run-Time Routines by Category%@AE@%%@NL@%
  126. %@NL@%
  127.      2.1%@BO:       11d28@%   Buffer Manipulation%@NL@%
  128.      2.2%@BO:       12a93@%   Character Classification and Conversion%@NL@%
  129.      2.3%@BO:       136c7@%   Data Conversion %@NL@%
  130.      2.4%@BO:       14030@%   Directory Control%@NL@%
  131.      2.5%@BO:       1456f@%   File Handling%@NL@%
  132.      2.6%@BO:       1555d@%   Graphics%@NL@%
  133.             2.6.1%@BO:       15786@%    Low-Level Graphics and Character-Font Functions%@NL@%
  134.             2.6.2%@BO:       1afcf@%    Presentation-Graphics Functions%@NL@%
  135.      2.7%@BO:       1cc64@%   Input and Output%@NL@%
  136.             2.7.1%@BO:       1d597@%    Text and Binary Modes%@NL@%
  137.             2.7.2%@BO:       1e13d@%    Stream Routines%@NL@%
  138.             2.7.3%@BO:       221df@%    Low-Level Routines%@NL@%
  139.             2.7.4%@BO:       239df@%    Console and Port I/O%@NL@%
  140.      2.8%@BO:       24c42@%   Internationalization%@NL@%
  141.      2.9%@BO:       250cb@%   Math%@NL@%
  142.      2.10%@BO:       2719e@%  Memory Allocation %@NL@%
  143.             2.10.1%@BO:       28704@%   Near and Far Heaps%@NL@%
  144.             2.10.2%@BO:       28cf2@%   Based Heaps%@NL@%
  145.      2.11%@BO:       29437@%  Process and Environment Control %@NL@%
  146.      2.12%@BO:       2c9a9@%  Searching and Sorting %@NL@%
  147.      2.13%@BO:       2cd6b@%  String Manipulation%@NL@%
  148.      2.14%@BO:       2dde5@%  System Calls%@NL@%
  149.             2.14.1%@BO:       2df7d@%   BIOS Interface %@NL@%
  150.             2.14.2%@BO:       2e68c@%   DOS Interface%@NL@%
  151.      2.15%@BO:       31041@%  Time%@NL@%
  152.      2.16%@BO:       3212e@%  Variable-Length Argument Lists%@NL@%
  153. %@NL@%
  154. %@AB@%Chapter 3%@AE@%%@BO:       325f9@%  %@AB@%Global Variables and Standard Types%@AE@%%@NL@%
  155. %@NL@%
  156.      3.1%@BO:       3283e@%   _amblksiz%@NL@%
  157.      3.2%@BO:       330b2@%   daylight, timezone, tzname%@NL@%
  158.      3.3%@BO:       33a2f@%   _doserrno, errno, sys_errlist, sys_nerr    %@NL@%
  159.      3.4%@BO:       34df1@%   _fmode  %@NL@%
  160.      3.5%@BO:       35126@%   _osmajor, _osminor, _osmode, _osversion    %@NL@%
  161.      3.6%@BO:       358aa@%   environ%@NL@%
  162.      3.7%@BO:       35e51@%   _psp%@NL@%
  163.      3.8%@BO:       36186@%   Standard Types%@NL@%
  164. %@NL@%
  165. %@NL@%
  166. %@AB@%PART II%@AE@%%@BO:       388bb@%  %@AB@%Run-Time Functions%@AE@%%@NL@%
  167. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%%@NL@%
  168. %@NL@%
  169.      About the Run-Time Reference%@BO:       38b14@%%@NL@%
  170.             abort%@BO:       3918f@%%@NL@%
  171.             abs%@BO:       39c83@%%@NL@%
  172.             access%@BO:       3a51d@%%@NL@%
  173.             acos Functions%@BO:       3b2f2@%%@NL@%
  174.             alloca%@BO:       3bfb2@%%@NL@%
  175.             _arc Functions%@BO:       3cd40@%%@NL@%
  176.             asctime%@BO:       3dfa0@%%@NL@%
  177.             asin Functions%@BO:       3ef49@%%@NL@%
  178.             assert%@BO:       3fba2@%%@NL@%
  179.             atan Functions%@BO:       40aaa@%%@NL@%
  180.             atexit%@BO:       4182b@%%@NL@%
  181.             atof, atoi, atol, _atold%@BO:       42491@%%@NL@%
  182.             bdos%@BO:       4396d@%%@NL@%
  183.             _beginthread%@BO:       44616@%%@NL@%
  184.             Bessel Functions%@BO:       467cf@%%@NL@%
  185.             _bfreeseg%@BO:       47c82@%%@NL@%
  186.             _bheapseg%@BO:       48b9d@%%@NL@%
  187.             _bios_disk%@BO:       49d7c@%%@NL@%
  188.             _bios_equiplist%@BO:       4c4f3@%%@NL@%
  189.             _bios_keybrd%@BO:       4d003@%%@NL@%
  190.             _bios_memsize%@BO:       4e8f5@%%@NL@%
  191.             _bios_printer%@BO:       4ef09@%%@NL@%
  192.             _bios_serialcom%@BO:       50135@%%@NL@%
  193.             _bios_timeofday%@BO:       51aa3@%%@NL@%
  194.             bsearch%@BO:       526b2@%%@NL@%
  195.             cabs, cabsl%@BO:       53a4b@%%@NL@%
  196.             calloc Functions%@BO:       544f9@%%@NL@%
  197.             ceil, ceill%@BO:       555d7@%%@NL@%
  198.             _cexit, _c_exit%@BO:       5608d@%%@NL@%
  199.             cgets%@BO:       56b23@%%@NL@%
  200.             _chain_intr%@BO:       577bb@%%@NL@%
  201.             chdir%@BO:       585ac@%%@NL@%
  202.             _chdrive%@BO:       593ee@%%@NL@%
  203.             chmod%@BO:       5a293@%%@NL@%
  204.             chsize%@BO:       5b15c@%%@NL@%
  205.             _clear87%@BO:       5bfa2@%%@NL@%
  206.             clearerr%@BO:       5c99b@%%@NL@%
  207.             _clearscreen%@BO:       5d349@%%@NL@%
  208.             clock%@BO:       5dd96@%%@NL@%
  209.             close%@BO:       5ea6b@%%@NL@%
  210.             _control87%@BO:       5f46c@%%@NL@%
  211.             cos Functions%@BO:       608a6@%%@NL@%
  212.             cprintf%@BO:       615fd@%%@NL@%
  213.             cputs%@BO:       62053@%%@NL@%
  214.             creat%@BO:       6275b@%%@NL@%
  215.             cscanf%@BO:       63b00@%%@NL@%
  216.             ctime%@BO:       646ec@%%@NL@%
  217.             cwait%@BO:       65444@%%@NL@%
  218.             dieeetomsbin, dmsbintoieee%@BO:       674ae@%%@NL@%
  219.             difftime%@BO:       67d18@%%@NL@%
  220.             _displaycursor%@BO:       686db@%%@NL@%
  221.             div%@BO:       69024@%%@NL@%
  222.             _dos_allocmem%@BO:       69bf6@%%@NL@%
  223.             _dos_close%@BO:       6a817@%%@NL@%
  224.             _dos_creat Functions%@BO:       6b1ef@%%@NL@%
  225.             _dos_find Functions%@BO:       6c149@%%@NL@%
  226.             _dos_freemem%@BO:       6df3c@%%@NL@%
  227.             _dos_getdate%@BO:       6ea74@%%@NL@%
  228.             _dos_getdiskfree%@BO:       6f474@%%@NL@%
  229.             _dos_getdrive%@BO:       7006a@%%@NL@%
  230.             _dos_getfileattr%@BO:       70a67@%%@NL@%
  231.             _dos_getftime%@BO:       71b5c@%%@NL@%
  232.             _dos_gettime%@BO:       72d14@%%@NL@%
  233.             _dos_getvect%@BO:       736d0@%%@NL@%
  234.             _dos_keep%@BO:       73dbd@%%@NL@%
  235.             _dos_open%@BO:       74998@%%@NL@%
  236.             _dos_read%@BO:       75c4f@%%@NL@%
  237.             _dos_setblock%@BO:       76a0b@%%@NL@%
  238.             _dos_setdate%@BO:       7760e@%%@NL@%
  239.             _dos_setdrive%@BO:       782a0@%%@NL@%
  240.             _dos_setfileattr%@BO:       78e46@%%@NL@%
  241.             _dos_setftime%@BO:       7a046@%%@NL@%
  242.             _dos_settime%@BO:       7b17b@%%@NL@%
  243.             _dos_setvect%@BO:       7bdfd@%%@NL@%
  244.             _dos_write%@BO:       7d825@%%@NL@%
  245.             dosexterr%@BO:       7e534@%%@NL@%
  246.             dup, dup2%@BO:       7f385@%%@NL@%
  247.             ecvt%@BO:       803c0@%%@NL@%
  248.             _ellipse Functions%@BO:       8119d@%%@NL@%
  249.             _enable%@BO:       82278@%%@NL@%
  250.             _endthread%@BO:       825f4@%%@NL@%
  251.             eof%@BO:       82ba1@%%@NL@%
  252.             exec Functions%@BO:       83572@%%@NL@%
  253.             exit, _exit%@BO:       86c0b@%%@NL@%
  254.             exp, expl%@BO:       87c85@%%@NL@%
  255.             _expand Functions%@BO:       88501@%%@NL@%
  256.             fabs, fabsl%@BO:       89b71@%%@NL@%
  257.             fclose, fcloseall%@BO:       8a5c9@%%@NL@%
  258.             fcvt%@BO:       8b384@%%@NL@%
  259.             fdopen%@BO:       8c1f2@%%@NL@%
  260.             feof%@BO:       8d62b@%%@NL@%
  261.             ferror%@BO:       8e0f7@%%@NL@%
  262.             fflush%@BO:       8eb47@%%@NL@%
  263.             fgetc, fgetchar%@BO:       8f6d7@%%@NL@%
  264.             fgetpos%@BO:       903d7@%%@NL@%
  265.             fgets%@BO:       9124b@%%@NL@%
  266.             fieeetomsbin, fmsbintoieee%@BO:       91df3@%%@NL@%
  267.             filelength%@BO:       9260a@%%@NL@%
  268.             fileno%@BO:       92fa7@%%@NL@%
  269.             _floodfill, _floodfill_w%@BO:       937b9@%%@NL@%
  270.             floor, floorl%@BO:       9445a@%%@NL@%
  271.             flushall%@BO:       94ebe@%%@NL@%
  272.             fmod, fmodl%@BO:       956a5@%%@NL@%
  273.             fopen%@BO:       96058@%%@NL@%
  274.             FP_OFF, FP_SEG%@BO:       97d48@%%@NL@%
  275.             _fpreset%@BO:       98566@%%@NL@%
  276.             fprintf%@BO:       99b20@%%@NL@%
  277.             fputc, fputchar%@BO:       9a664@%%@NL@%
  278.             fputs%@BO:       9b19d@%%@NL@%
  279.             fread%@BO:       9b8ea@%%@NL@%
  280.             free Functions%@BO:       9c89a@%%@NL@%
  281.             _freect%@BO:       9dbfa@%%@NL@%
  282.             freopen%@BO:       9e721@%%@NL@%
  283.             frexp, frexpl%@BO:       a0465@%%@NL@%
  284.             fscanf%@BO:       a0f0e@%%@NL@%
  285.             fseek%@BO:       a1cd1@%%@NL@%
  286.             fsetpos%@BO:       a2edd@%%@NL@%
  287.             _fsopen%@BO:       a3d28@%%@NL@%
  288.             fstat%@BO:       a5e7a@%%@NL@%
  289.             ftell%@BO:       a7374@%%@NL@%
  290.             ftime%@BO:       a8370@%%@NL@%
  291.             _fullpath%@BO:       a9207@%%@NL@%
  292.             fwrite%@BO:       aa009@%%@NL@%
  293.             gcvt%@BO:       aae6c@%%@NL@%
  294.             _getactivepage%@BO:       ab89b@%%@NL@%
  295.             _getarcinfo%@BO:       ac314@%%@NL@%
  296.             _getbkcolor%@BO:       accf6@%%@NL@%
  297.             getc, getchar%@BO:       ad644@%%@NL@%
  298.             getch, getche%@BO:       ae25a@%%@NL@%
  299.             _getcolor%@BO:       aebc0@%%@NL@%
  300.             _getcurrentposition Functions%@BO:       af76f@%%@NL@%
  301.             getcwd%@BO:       b069d@%%@NL@%
  302.             _getdcwd%@BO:       b13ae@%%@NL@%
  303.             _getdrive%@BO:       b25f3@%%@NL@%
  304.             getenv%@BO:       b2a78@%%@NL@%
  305.             _getfillmask%@BO:       b3958@%%@NL@%
  306.             _getfontinfo%@BO:       b47b4@%%@NL@%
  307.             _getgtextextent%@BO:       b518c@%%@NL@%
  308.             _getimage Functions%@BO:       b578c@%%@NL@%
  309.             _getlinestyle%@BO:       b6b86@%%@NL@%
  310.             _getphyscoord%@BO:       b79d6@%%@NL@%
  311.             getpid%@BO:       b8070@%%@NL@%
  312.             _getpixel Functions%@BO:       b872a@%%@NL@%
  313.             gets%@BO:       b93d1@%%@NL@%
  314.             _gettextcolor%@BO:       b9c6b@%%@NL@%
  315.             _gettextcursor%@BO:       ba2b6@%%@NL@%
  316.             _gettextposition%@BO:       ba79f@%%@NL@%
  317.             _gettextwindow%@BO:       bb713@%%@NL@%
  318.             _getvideoconfig%@BO:       bbf34@%%@NL@%
  319.             _getviewcoord Functions%@BO:       bdaa1@%%@NL@%
  320.             _getvisualpage%@BO:       be761@%%@NL@%
  321.             getw%@BO:       bed02@%%@NL@%
  322.             _getwindowcoord%@BO:       bf896@%%@NL@%
  323.             _getwritemode%@BO:       bffc1@%%@NL@%
  324.             gmtime%@BO:       c0c44@%%@NL@%
  325.             _grstatus%@BO:       c1b7a@%%@NL@%
  326.             halloc%@BO:       c50a1@%%@NL@%
  327.             _hard Functions%@BO:       c5ae8@%%@NL@%
  328.             _heapadd Functions%@BO:       c8111@%%@NL@%
  329.             _heapchk Functions%@BO:       c986a@%%@NL@%
  330.             _heapmin Functions%@BO:       ca8c3@%%@NL@%
  331.             _heapset Functions%@BO:       cb359@%%@NL@%
  332.             _heapwalk Functions%@BO:       cc691@%%@NL@%
  333.             hfree%@BO:       ce432@%%@NL@%
  334.             hypot, hypotl%@BO:       ced41@%%@NL@%
  335.             _imagesize Functions%@BO:       cf737@%%@NL@%
  336.             inp, inpw%@BO:       d034f@%%@NL@%
  337.             int86%@BO:       d0c38@%%@NL@%
  338.             int86x%@BO:       d1a2f@%%@NL@%
  339.             intdos%@BO:       d2a93@%%@NL@%
  340.             intdosx%@BO:       d37ba@%%@NL@%
  341.             is Functions%@BO:       d467d@%%@NL@%
  342.             isatty%@BO:       d5fa1@%%@NL@%
  343.             itoa%@BO:       d66b5@%%@NL@%
  344.             kbhit%@BO:       d7284@%%@NL@%
  345.             labs%@BO:       d7a47@%%@NL@%
  346.             ldexp, ldexpl%@BO:       d82cd@%%@NL@%
  347.             ldiv%@BO:       d8bf5@%%@NL@%
  348.             lfind%@BO:       d9730@%%@NL@%
  349.             _lineto Functions%@BO:       da6e4@%%@NL@%
  350.             localeconv%@BO:       db323@%%@NL@%
  351.             localtime%@BO:       dd16a@%%@NL@%
  352.             locking%@BO:       de396@%%@NL@%
  353.             log Functions%@BO:       dfccd@%%@NL@%
  354.             long double Functions%@BO:       e08bc@%%@NL@%
  355.             longjmp%@BO:       e14ca@%%@NL@%
  356.             _lrotl, _lrotr%@BO:       e22e1@%%@NL@%
  357.             lsearch%@BO:       e2b64@%%@NL@%
  358.             lseek%@BO:       e37af@%%@NL@%
  359.             ltoa%@BO:       e4a65@%%@NL@%
  360.             _makepath%@BO:       e564b@%%@NL@%
  361.             malloc Functions%@BO:       e6d90@%%@NL@%
  362.             matherr, _matherrl%@BO:       e9184@%%@NL@%
  363.             max%@BO:       ead81@%%@NL@%
  364.             _memavl%@BO:       eb4bb@%%@NL@%
  365.             memccpy, _fmemccpy%@BO:       ebfb6@%%@NL@%
  366.             memchr, _fmemchr%@BO:       eccf2@%%@NL@%
  367.             memcmp, _fmemcmp%@BO:       edb82@%%@NL@%
  368.             memcpy, _fmemcpy%@BO:       eecbb@%%@NL@%
  369.             memicmp, _fmemicmp%@BO:       f019c@%%@NL@%
  370.             _memmax%@BO:       f1163@%%@NL@%
  371.             memmove, _fmemmove%@BO:       f1b64@%%@NL@%
  372.             memset, _fmemset%@BO:       f2e58@%%@NL@%
  373.             min%@BO:       f3a2b@%%@NL@%
  374.             mkdir%@BO:       f4166@%%@NL@%
  375.             mktemp%@BO:       f4dcd@%%@NL@%
  376.             mktime%@BO:       f5f19@%%@NL@%
  377.             modf, modfl%@BO:       f6e15@%%@NL@%
  378.             movedata%@BO:       f7841@%%@NL@%
  379.             _moveto Functions%@BO:       f863b@%%@NL@%
  380.             _msize Functions%@BO:       f93b6@%%@NL@%
  381.             onexit%@BO:       fa55b@%%@NL@%
  382.             open%@BO:       fb0e9@%%@NL@%
  383.             _outgtext%@BO:       fd68e@%%@NL@%
  384.             _outmem%@BO:       fea80@%%@NL@%
  385.             outp, outpw%@BO:       ff351@%%@NL@%
  386.             _outtext%@BO:      10053b@%%@NL@%
  387.             _pclose%@BO:      10126a@%%@NL@%
  388.             perror%@BO:      101a68@%%@NL@%
  389.             _pg_analyzechart Functions%@BO:      102aba@%%@NL@%
  390.             _pg_analyzepie%@BO:      10438e@%%@NL@%
  391.             _pg_analyzescatter Functions%@BO:      104bad@%%@NL@%
  392.             _pg_chart Functions%@BO:      10587e@%%@NL@%
  393.             _pg_chartscatter Functions%@BO:      106ee0@%%@NL@%
  394.             _pg_chartpie%@BO:      107ac6@%%@NL@%
  395.             _pg_defaultchart%@BO:      10849d@%%@NL@%
  396.             _pg_getchardef%@BO:      109371@%%@NL@%
  397.             _pg_getpalette%@BO:      1098dc@%%@NL@%
  398.             _pg_getstyleset%@BO:      10b2f4@%%@NL@%
  399.             _pg_hlabelchart%@BO:      10b7a5@%%@NL@%
  400.             _pg_initchart%@BO:      10bea1@%%@NL@%
  401.             _pg_resetpalette%@BO:      10c693@%%@NL@%
  402.             _pg_resetstyleset%@BO:      10cc89@%%@NL@%
  403.             _pg_setchardef%@BO:      10d100@%%@NL@%
  404.             _pg_setpalette%@BO:      10d692@%%@NL@%
  405.             _pg_setstyleset%@BO:      10dd45@%%@NL@%
  406.             _pg_vlabelchart%@BO:      10e1de@%%@NL@%
  407.             _pie Functions%@BO:      10e8d4@%%@NL@%
  408.             _pipe%@BO:      10fd2d@%%@NL@%
  409.             _polygon Functions%@BO:      111db1@%%@NL@%
  410.             _popen%@BO:      112f74@%%@NL@%
  411.             pow Functions%@BO:      113f34@%%@NL@%
  412.             printf%@BO:      114b08@%%@NL@%
  413.             putc, putchar%@BO:      11afff@%%@NL@%
  414.             putch%@BO:      11ba7c@%%@NL@%
  415.             putenv%@BO:      11c223@%%@NL@%
  416.             _putimage Functions%@BO:      11d544@%%@NL@%
  417.             puts%@BO:      11e6e5@%%@NL@%
  418.             putw%@BO:      11edcd@%%@NL@%
  419.             qsort%@BO:      11f8f4@%%@NL@%
  420.             raise%@BO:      1209b7@%%@NL@%
  421.             rand%@BO:      121769@%%@NL@%
  422.             read%@BO:      121fe1@%%@NL@%
  423.             realloc Functions%@BO:      12321d@%%@NL@%
  424.             _rectangle Functions%@BO:      124988@%%@NL@%
  425.             _registerfonts%@BO:      125b2e@%%@NL@%
  426.             _remapallpalette, _remappalette%@BO:      1265e5@%%@NL@%
  427.             remove%@BO:      129398@%%@NL@%
  428.             rename%@BO:      129be8@%%@NL@%
  429.             rewind%@BO:      12a97e@%%@NL@%
  430.             rmdir%@BO:      12b52b@%%@NL@%
  431.             rmtmp%@BO:      12c0fc@%%@NL@%
  432.             _rotl, _rotr%@BO:      12cabd@%%@NL@%
  433.             scanf%@BO:      12d39b@%%@NL@%
  434.             _scrolltextwindow%@BO:      131185@%%@NL@%
  435.             _searchenv%@BO:      132443@%%@NL@%
  436.             segread%@BO:      133031@%%@NL@%
  437.             _selectpalette%@BO:      1338f3@%%@NL@%
  438.             _setactivepage%@BO:      134f2f@%%@NL@%
  439.             _setbkcolor%@BO:      135d81@%%@NL@%
  440.             setbuf%@BO:      136986@%%@NL@%
  441.             _setcliprgn%@BO:      1375e9@%%@NL@%
  442.             _setcolor%@BO:      137f24@%%@NL@%
  443.             _setfillmask%@BO:      138c65@%%@NL@%
  444.             _setfont%@BO:      139939@%%@NL@%
  445.             _setgtextvector%@BO:      13b65a@%%@NL@%
  446.             setjmp%@BO:      13bff2@%%@NL@%
  447.             _setlinestyle%@BO:      13c8cb@%%@NL@%
  448.             setlocale%@BO:      13cf6e@%%@NL@%
  449.             setmode%@BO:      13e030@%%@NL@%
  450.             _setpixel Functions%@BO:      13efb1@%%@NL@%
  451.             _settextcolor%@BO:      13fbad@%%@NL@%
  452.             _settextcursor%@BO:      140ea8@%%@NL@%
  453.             _settextposition%@BO:      141a4a@%%@NL@%
  454.             _settextrows%@BO:      1428ed@%%@NL@%
  455.             _settextwindow%@BO:      143229@%%@NL@%
  456.             setvbuf%@BO:      143a0b@%%@NL@%
  457.             _setvideomode%@BO:      144bab@%%@NL@%
  458.             _setvideomoderows%@BO:      1471df@%%@NL@%
  459.             _setvieworg%@BO:      147cb4@%%@NL@%
  460.             _setviewport%@BO:      148835@%%@NL@%
  461.             _setvisualpage%@BO:      149155@%%@NL@%
  462.             _setwindow%@BO:      149700@%%@NL@%
  463.             _setwritemode%@BO:      14b303@%%@NL@%
  464.             signal%@BO:      14ba04@%%@NL@%
  465.             sin Functions%@BO:      14fca4@%%@NL@%
  466.             sopen%@BO:      1509fa@%%@NL@%
  467.             spawn Functions%@BO:      1530a2@%%@NL@%
  468.             _splitpath%@BO:      15729e@%%@NL@%
  469.             sprintf%@BO:      1581ec@%%@NL@%
  470.             sqrt, sqrtl%@BO:      158dcd@%%@NL@%
  471.             srand%@BO:      1596bc@%%@NL@%
  472.             sscanf%@BO:      15a07a@%%@NL@%
  473.             stackavail%@BO:      15ac8b@%%@NL@%
  474.             stat%@BO:      15b49e@%%@NL@%
  475.             _status87%@BO:      15c7a1@%%@NL@%
  476.             strcat, _fstrcat%@BO:      15d21c@%%@NL@%
  477.             strchr, _fstrchr%@BO:      15ddf9@%%@NL@%
  478.             strcmp, _fstrcmp%@BO:      15ef39@%%@NL@%
  479.             strcmpi%@BO:      160083@%%@NL@%
  480.             strcoll%@BO:      160916@%%@NL@%
  481.             strcpy, _fstrcpy%@BO:      161199@%%@NL@%
  482.             strcspn, _fstrcspn%@BO:      161d81@%%@NL@%
  483.             _strdate%@BO:      1629b2@%%@NL@%
  484.             strdup Functions%@BO:      16324c@%%@NL@%
  485.             strerror, _strerror%@BO:      1640af@%%@NL@%
  486.             strftime%@BO:      1651ca@%%@NL@%
  487.             stricmp, _fstricmp%@BO:      166454@%%@NL@%
  488.             strlen, _fstrlen%@BO:      166ff9@%%@NL@%
  489.             strlwr, _fstrlwr%@BO:      1678a7@%%@NL@%
  490.             strncat, _fstrncat%@BO:      1682e1@%%@NL@%
  491.             strncmp, _fstrncmp%@BO:      168fa4@%%@NL@%
  492.             strncpy, _fstrncpy%@BO:      16a1c0@%%@NL@%
  493.             strnicmp, _fstrnicmp%@BO:      16aec9@%%@NL@%
  494.             strnset, _fstrnset%@BO:      16b9a8@%%@NL@%
  495.             strpbrk, _fstrpbrk%@BO:      16c426@%%@NL@%
  496.             strrchr, _fstrrchr%@BO:      16d07b@%%@NL@%
  497.             strrev, _fstrrev%@BO:      16e11b@%%@NL@%
  498.             strset, _fstrset%@BO:      16ec0f@%%@NL@%
  499.             strspn, _fstrspn%@BO:      16f56c@%%@NL@%
  500.             strstr, _fstrstr%@BO:      170273@%%@NL@%
  501.             _strtime%@BO:      170fa5@%%@NL@%
  502.             strtod, strtol, _strtold, strtoul%@BO:      1718a0@%%@NL@%
  503.             strtok, _fstrtok%@BO:      1736b8@%%@NL@%
  504.             strupr, _fstrupr%@BO:      17484b@%%@NL@%
  505.             strxfrm%@BO:      175200@%%@NL@%
  506.             swab%@BO:      175c20@%%@NL@%
  507.             system%@BO:      17646b@%%@NL@%
  508.             tan Functions%@BO:      17742e@%%@NL@%
  509.             tell%@BO:      1782fe@%%@NL@%
  510.             tempnam, tmpnam%@BO:      178b8a@%%@NL@%
  511.             time%@BO:      17a158@%%@NL@%
  512.             tmpfile%@BO:      17a9fb@%%@NL@%
  513.             toascii, tolower, toupper Functions%@BO:      17b4c9@%%@NL@%
  514.             tzset%@BO:      17ca1b@%%@NL@%
  515.             ultoa%@BO:      17dd29@%%@NL@%
  516.             umask%@BO:      17e88d@%%@NL@%
  517.             ungetc%@BO:      17f63c@%%@NL@%
  518.             ungetch%@BO:      1805dc@%%@NL@%
  519.             unlink%@BO:      18106f@%%@NL@%
  520.             _unregisterfonts%@BO:      1818e9@%%@NL@%
  521.             utime%@BO:      181e8c@%%@NL@%
  522.             va_arg, va_end, va_start%@BO:      182ded@%%@NL@%
  523.             vfprintf, vprintf, vsprintf%@BO:      185300@%%@NL@%
  524.             wait%@BO:      1869bd@%%@NL@%
  525.             _wrapon%@BO:      18855d@%%@NL@%
  526.             write%@BO:      189031@%%@NL@%
  527.  
  528. %@AB@%Index%@AE@%%@BO:      18a0ba@%
  529.  
  530.  
  531. %@NL@%
  532. %@NL@%
  533. %@CR:C6A-Intro   @%%@1@%%@AB@%Introduction%@AE@%%@EH@%%@NL@%
  534. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  535. %@NL@%
  536. The Microsoft(R) C Run-Time Library is a set of over 500 ready-to-use
  537. functions and macros designed for use in C programs. The run-time library
  538. makes programming easier by providing  %@NL@%
  539. %@NL@%
  540. %@NL@%
  541.   ■   Fast and efficient routines to perform common programming tasks (such
  542.       as string manipulation), sparing you the time and effort needed to
  543.       write such routines%@NL@%
  544. %@NL@%
  545.   ■   Reliable methods of performing operating-system functions (such as
  546.       opening and closing files)%@NL@%
  547. %@NL@%
  548. %@NL@%
  549. The C run-time library is important because it provides basic functions not
  550. provided by the C language itself. These functions include input and output,
  551. memory allocation, process control, graphics, and many others.  %@NL@%
  552. %@NL@%
  553. This book describes the Microsoft C run-time library routines included with
  554. the Microsoft Professional Development System version 6.0. These comprise
  555. all of the routines included with earlier versions of Microsoft C, as well
  556. as many new routines.  %@NL@%
  557. %@NL@%
  558. ────────────────────────────────────────────────────────────────────────────%@NL@%
  559. NOTE
  560.  
  561. %@AI@%Microsoft documentation uses the term "OS/2" to refer to the OS/2
  562. %@AI@%systems─Microsoft Operating System/2 (MS%@AI@%(R)%@AE@%%@AI@% OS/2) and IBM%@AE@%%@AI@%(R)%@AE@%%@AI@% OS/2.
  563. %@AI@%Similarly, the term "DOS" refers to both the MS-DOS%@AE@%%@AI@%(R)%@AE@%%@AI@% %@AE@%%@AI@%and IBM Personal
  564. %@AI@%Computer DOS operating systems. The name of a specific operating system is
  565. %@AI@%used when it is necessary to note features that are unique to that system.%@AE@%%@AE@%%@NL@%
  566. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  567. %@NL@%
  568. %@NL@%
  569. %@2@%%@CR:C6A00000001 @%%@AB@%About the C Run-Time Library%@AE@%%@EH@%%@NL@%
  570. %@NL@%
  571. The Microsoft C run-time library contains a number of new routines and
  572. features which support American National Standards Institute (ANSI) C
  573. compatibility, OS/2 and XENIX(R) programming, and sophisticated graphics
  574. programming.  %@NL@%
  575. %@NL@%
  576. To ease the task of transporting programs from one operating system to
  577. another, the description of each library routine includes compatibility
  578. boxes, which show at a glance whether the routine is compatible with ANSI C,
  579. MS-DOS, OS/2, UNIX(R), and XENIX. (In this book, references to XENIX systems
  580. also encompass UNIX and other UNIX-like systems.)  %@NL@%
  581. %@NL@%
  582. %@NL@%
  583. %@3@%%@CR:C6A00000002 @%%@AB@%ANSI C Compatibility%@AE@%%@EH@%%@NL@%
  584. %@NL@%
  585. The C run-time library routines are designed for compatibility with the ANSI
  586. C standard, which Microsoft C compilers support. The major innovation of
  587. ANSI C is to permit argument-type lists in function prototypes
  588. (declarations). Given the information in the function prototype, the
  589. compiler can check later references to the function to make sure that the
  590. references use the correct number and type of arguments and the correct
  591. return value.  %@NL@%
  592. %@NL@%
  593. To take advantage of the compiler's type-checking ability, the include files
  594. that accompany the C run-time library have been expanded. In addition to the
  595. definitions and declarations required by library routines, the include files
  596. now contain function declarations with argument-type lists. Several new
  597. include files have also been added. The names of these files are chosen to
  598. maximize compatibility with the ANSI C standard and with XENIX and UNIX
  599. names.%@CR:C6A00000003 @%%@CR:C6A00000004 @%  %@NL@%
  600. %@NL@%
  601. %@NL@%
  602. %@3@%%@CR:C6A00000005 @%%@AB@%OS/2 and XENIX(R) Programming%@AE@%%@EH@%%@NL@%
  603. %@NL@%
  604. Microsoft C run-time library routines are designed to maintain maximum
  605. compatibility between MS-DOS, OS/2, and XENIX or UNIX systems. The library
  606. offers a number of operating-system interface routines that allow you to
  607. take advantage of specific DOS and OS/2 features.  %@NL@%
  608. %@NL@%
  609. Most of the functions in the C library for DOS and OS/2 are compatible with
  610. like-named routines in the C library for XENIX. For additional
  611. compatibility, the math library functions have been extended to provide
  612. exception handling in the same manner as the UNIX System V math functions.  %@NL@%
  613. %@NL@%
  614. %@NL@%
  615. %@3@%%@CR:C6A00000006 @%%@AB@%Expanded Graphics Library%@AE@%%@EH@%%@NL@%
  616. %@NL@%
  617. The Microsoft C run-time library now contains over one hundred graphics
  618. routines. The core of this library consists of several dozen low-level
  619. graphics routines, which allow your programs to select video modes, set
  620. points, draw lines, change colors, and draw shapes such as rectangles and
  621. ellipses. You can display real-valued data, such as floating-point values,
  622. within windows of different sizes by using various coordinate systems.  %@NL@%
  623. %@NL@%
  624. Recent additions to the graphics library include presentation graphics and
  625. fonts. The presentation-graphics library provides powerful tools for adding
  626. presentation-quality graphics to your programs. These routines can display
  627. data as a variety of graphs, including pie charts, bar and column charts,
  628. line graphs, and scatter diagrams.  %@NL@%
  629. %@NL@%
  630. The fonts library allows your programs to display various styles and sizes
  631. of text in graphics images or charts. You can use font-manipulation routines
  632. with any graphics routines that display text, including presentation
  633. graphics.  %@NL@%
  634. %@NL@%
  635. %@NL@%
  636. %@2@%%@CR:C6A00000007 @%%@AB@%About This Book%@AE@%%@EH@%%@NL@%
  637. %@NL@%
  638. This book assumes that you understand the C language and know how to compile
  639. and link programs. If you have questions about these subjects, consult your
  640. compiler documentation.  %@NL@%
  641. %@NL@%
  642. This book has two parts. Part 1, "Overview," introduces the Microsoft C
  643. library. It describes general rules for using the library and summarizes the
  644. main categories of library routines. Part 1 contains the following chapters:
  645. %@NL@%
  646. %@NL@%
  647. %@NL@%
  648.   ■   Chapter 1, "Using C Library Routines," gives general rules for
  649.       understanding and using C library routines and mentions special
  650.       considerations that apply to certain routines. It is recommended that
  651.       you read this chapter before using the run-time library; you may also
  652.       want to turn to Chapter 1 when you have questions about library
  653.       procedures.%@NL@%
  654. %@NL@%
  655.   ■   Chapter 2, "Run-Time Routines by Category," lists the C library
  656.       routines by category and discusses considerations that apply to each
  657.       category. This chapter makes it easy to locate routines by task. Once
  658.       you find the routine you want, turn to the reference page in Part 2
  659.       for a detailed description.%@NL@%
  660. %@NL@%
  661.   ■   Chapter 3, "Global Variables and Standard Types," describes variables
  662.       and types that are used by library routines. Global variables and
  663.       standard types are also described in the reference descriptions of the
  664.       routines that use them.%@NL@%
  665. %@NL@%
  666. %@NL@%
  667. Part 2, "Run-Time Functions," describes the library routines in alphabetical
  668. order. Once you are familiar with the C library rules and procedures, you
  669. will probably use this part most often.  %@NL@%
  670. %@NL@%
  671. %@NL@%
  672. %@2@%%@CR:C6A00000008 @%%@AB@%Other Books of Interest%@AE@%%@EH@%%@NL@%
  673. %@NL@%
  674. This book provides a guide to the C run-time library provided with the
  675. Microsoft C Professional Development System version 6.0.  %@NL@%
  676. %@NL@%
  677. The following books cover a variety of topics that you may find useful. They
  678. are listed only for your convenience. With the exception of its own
  679. publications, Microsoft does not endorse these books or recommend them over
  680. others on the same subject.  %@NL@%
  681. %@NL@%
  682. %@NL@%
  683.   ■   Barkakati, Nabajyoti. %@AI@%The Waite Group's Microsoft C Bible%@AE@%.
  684.       Indianapolis, IN: Howard W. Sams, 1988.%@NL@%
  685. %@NL@%
  686. %@STUB@%      A topical guide to the Microsoft C run-time library. A similar volume
  687.       is available for the Microsoft QuickC(R) product.%@NL@%
  688. %@NL@%
  689.   ■   Campbell, Joe. %@AI@%C Programmer's Guide to Serial Communications%@AE@%.
  690.       Indianapolis, IN: Howard W. Sams & Company, 1987.%@NL@%
  691. %@NL@%
  692. %@STUB@%      A comprehensive guide to the specialized area of serial communication
  693.       programming in C.%@NL@%
  694. %@NL@%
  695.   ■   Hansen, Augie. %@AI@%Proficient C: The Microsoft Guide to Intermediate &
  696. %@AI@%      Advanced C Programming%@AE@%. Redmond, WA: Microsoft Press, 1987.%@NL@%
  697. %@NL@%
  698. %@STUB@%      An intermediate-level guide to C programming.%@NL@%
  699. %@NL@%
  700.   ■   Harbison, Samuel P., and Guy L. Steele, Jr. %@AI@%C: A Reference Manual%@AE@%, 2d
  701.       ed. Englewood Cliffs, NJ: Prentice Hall, 1987.%@NL@%
  702. %@NL@%
  703. %@STUB@%      A comprehensive guide to the C language and the standard library.%@NL@%
  704. %@NL@%
  705.   ■   Kernighan, Brian W., and Dennis M. Ritchie. %@AI@%The C Programming
  706. %@AI@%      Language%@AE@%, 2d ed. Englewood Cliffs, NJ: Prentice Hall, 1988.%@NL@%
  707. %@NL@%
  708. %@STUB@%      The first edition of this book is the classic definition of the C
  709.       language. The second edition includes new information on the proposed
  710.       ANSI C standard.%@NL@%
  711. %@NL@%
  712.   ■   Lafore, Robert. %@AI@%Microsoft C Programming for the IBM%@AE@%. Indianapolis, IN:
  713.       Howard W. Sams & Company, 1987.%@NL@%
  714. %@NL@%
  715. %@STUB@%      The first half of this book teaches C. The second half concentrates on
  716.       specifics of the PC environment, such as BIOS calls, memory, and video
  717.       displays.%@NL@%
  718. %@NL@%
  719.   ■   Mark Williams Company. %@AI@%ANSI C: A Lexical Guide%@AE@%. Englewood Cliffs, NJ:
  720.       Prentice Hall, 1988.%@NL@%
  721. %@NL@%
  722. %@STUB@%      A dictionary-style guide to the ANSI C standard.%@NL@%
  723. %@NL@%
  724.   ■   Plauger, P. J., and Jim Brodie. %@AI@%Standard C%@AE@%. Redmond, WA: Microsoft
  725.       Press, 1989.%@NL@%
  726. %@NL@%
  727. %@STUB@%      A quick reference guide to the ANSI C implementation by the secretary
  728.       and chairman of the ANSI-authorized C Programming Language Standards
  729.       Committee.%@NL@%
  730. %@NL@%
  731.   ■   Plum, Thomas. %@AI@%Reliable Data Structures in C%@AE@%. Cardiff, NJ: Plum Hall,
  732.       1985.%@NL@%
  733. %@NL@%
  734. %@STUB@%      An intermediate-level look at data structures using the C language.%@NL@%
  735. %@NL@%
  736.   ■   Plum, Thomas, and Jim Brodie. %@AI@%Efficient C%@AE@%. Cardiff, NJ: Plum Hall,
  737.       1985.%@NL@%
  738. %@NL@%
  739. %@STUB@%      A guide to techniques for increasing the efficiency of C programs.%@NL@%
  740. %@NL@%
  741.   ■   Press, William H., Brian P. Flannery, Saul A. Teukolsky, and William
  742.       T. Vetterling. %@AI@%Numerical Recipes in C: The Art of Scientific
  743. %@AI@%      Computing%@AE@%. New York: Cambridge University Press, 1988.%@NL@%
  744. %@NL@%
  745. %@STUB@%      A comprehensive look at numerical techniques using the C language.%@NL@%
  746. %@NL@%
  747.   ■   Schustack, Steve. %@AI@%Variations in C: Programming Techniques for
  748. %@AI@%      Developing Efficient Professional Applications%@AE@%. Redmond, WA: Microsoft
  749.       Press, 1985.%@NL@%
  750. %@NL@%
  751. %@STUB@%      An intermediate-level guide to developing business applications in C.%@NL@%
  752. %@NL@%
  753.   ■   Ward, Robert. %@AI@%Debugging C%@AE@%. Indianapolis, IN: Que Corporation, 1986.%@NL@%
  754. %@NL@%
  755. %@STUB@%      An advanced guide to the theory and practice of debugging C programs.%@NL@%
  756. %@NL@%
  757.   ■   Wilton, Richard. %@AI@%Programmer's Guide to PC and PS/2 Video
  758. %@AI@%      Systems:Maximum Video Performance from the EGA, VGA, HGC, & MCGA%@AE@%.
  759.       Redmond, WA: Microsoft Press, 1987.%@NL@%
  760. %@NL@%
  761. %@STUB@%      An advanced guide to all the PC and PS/2 video modes.%@NL@%
  762. %@NL@%
  763. %@NL@%
  764. %@NL@%
  765. %@2@%%@CR:C6A00000009 @%%@AB@%Document Conventions%@AE@%%@EH@%%@NL@%
  766. %@NL@%
  767. This book uses the following document conventions :%@CR:C6A00000010 @%  %@NL@%
  768. %@NL@%
  769. %@AB@%Example%@AE@%                           %@AB@%Description%@AE@%
  770. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  771. STDIO.H                           Uppercase letters indicate file names, 
  772.                                   segment names, registers, and terms used
  773.                                   at the operating-system command level. %@CR:C6A00000011 @%
  774.  
  775. %@AB@%_far%@AE@%                              Boldface letters indicate C keywords, 
  776.                                   operators, language-specific characters,
  777.                                   and library routines. Within discussions
  778.                                   of syntax, bold type indicates that the 
  779.                                   text must be entered exactly as shown. %@CR:C6A00000012 @%
  780.  
  781. %@AI@%expression%@AE@%                        Words in italics indicate placeholders 
  782.                                   for information you must supply, such as
  783.                                   a file name. Italics are also 
  784.                                   occasionally used for emphasis in the 
  785.                                   text. %@CR:C6A00000013 @%
  786.  
  787. [[%@AI@%option%@AE@%]]                        Items inside double square brackets are 
  788.                                   optional. %@CR:C6A00000014 @%%@CR:C6A00000015 @%
  789.  
  790. %@AB@%#pragma pack%@AE@% {%@AB@%1%@AE@%|%@AB@%2%@AE@%}                Braces and a vertical bar indicate a 
  791.                                   choice among two or more items. You must
  792.                                   choose one of these items unless double 
  793.                                   square brackets surround the braces.
  794.  
  795. %@AS@%#include <io.h>%@AE@%                   This font is used for examples, user 
  796.                                   input, program output, and error 
  797.                                   messages in text. %@CR:C6A00000016 @%
  798.  
  799. %@AB@%CL%@AE@% %@AI@%options%@AE@% [[%@AI@%files%@AE@%...]]           Three dots following an item indicate 
  800.                                   that more items having the same form may
  801.                                   appear. %@CR:C6A00000017 @%
  802.  
  803. %@AS@%while()%@AE@%                           A column of three dots tells you that 
  804. %@AS@%{%@AE@%                                 part of the example program has been 
  805. %@AS@%   .%@AE@%                              intentionally omitted. %@CR:C6A00000018 @%
  806. %@AS@%   .%@AE@%                              
  807. %@AS@%   .%@AE@%                              
  808. %@AS@%}%@AE@%                                 
  809.  
  810. CTRL+ENTER                        Small capital letters are used for the 
  811.                                   names of keys on the keyboard. When you 
  812.                                   see a plus sign (+) between two key 
  813.                                   names, you should hold down the first 
  814.                                   key while pressing the second. %@CR:C6A00000019 @%
  815.  
  816.                                   The carriage-return key, sometimes 
  817.                                   marked as a bent arrow on the keyboard, 
  818.                                   is called ENTER.
  819.  
  820. "argument"                        Quotation marks enclose a new term the 
  821.                                   first time it is defined in text. %@CR:C6A00000020 @%
  822.  
  823. %@AS@%"C string"%@AE@%                        Some C constructs, such as strings, 
  824.                                   require quotation marks. Quotation marks
  825.                                   required by the language have the form %@AS@%"%@AE@%
  826.                                   %@AS@%"%@AE@% and %@AS@%' '%@AE@% rather than " " and ' '.
  827.  
  828. Color Graphics Adapter (CGA)      The first time an acronym is used, it is
  829.                                   often spelled out.
  830.  
  831. %@NL@%
  832. %@NL@%
  833. %@NL@%
  834. %@NL@%
  835. %@NL@%
  836. %@CR:C6A-Part 01 @%%@1@%%@AB@%PART I  Overview%@AE@%%@EH@%%@NL@%
  837. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  838. %@NL@%
  839. The first part of this book provides an overview of the run-time library
  840. provided with the Microsoft C Professional Development System.  %@NL@%
  841. %@NL@%
  842. Chapter 1 is a general guide to the use of the run-time library routines.  %@NL@%
  843. %@NL@%
  844. Chapter 2 lists the routines by category.  %@NL@%
  845. %@NL@%
  846. Chapter 3 tells how to access global variables and types defined in the
  847. run-time library.  %@NL@%
  848. %@NL@%
  849. %@NL@%
  850. %@NL@%
  851. %@NL@%
  852. %@NL@%
  853. %@NL@%
  854. %@CR:C6A00010001 @%%@1@%%@AB@%Chapter 1  Using C Library Routines%@AE@%%@EH@%%@NL@%
  855. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  856. %@NL@%
  857. This chapter provides basic information about how to use Microsoft C library
  858. routines. It also describes some special rules, such as file- and path-name
  859. conventions, that apply to particular routines. You should read this chapter
  860. before you begin to use C library routines, and you may also want to refer
  861. back to it if you have questions about library procedures.  %@NL@%
  862. %@NL@%
  863. %@NL@%
  864. %@2@%%@CR:C6A00010002 @%%@AB@%1.1  Calling Library Routines%@AE@%%@EH@%%@NL@%
  865. %@NL@%
  866. To use a C library routine, simply call it in your program, just as if it is
  867. defined there. For instance, suppose you write the following program and
  868. name it SAMPLE.C:  %@NL@%
  869. %@NL@%
  870. %@AS@%  #include <stdio.h>
  871. %@AS@%  main()
  872. %@AS@%  {
  873. %@AS@%     printf( "Microsoft C" );
  874. %@AS@%  }%@AE@%%@NL@%
  875. %@NL@%
  876. The program prints %@AS@% Microsoft C %@AE@% by calling the %@AB@%printf%@AE@% routine, which is
  877. part of the standard C library. Calling a library routine normally involves
  878. two groups of files:  %@NL@%
  879. %@NL@%
  880. %@NL@%
  881.   1.  Header ("include") files that contain declarations and type
  882.       definitions required by library routines %@NL@%
  883. %@NL@%
  884.   2.  Library files that contain the library routines in compiled form%@NL@%
  885. %@NL@%
  886. %@NL@%
  887. Header files and library files are both included with Microsoft C. Header
  888. files are used when compiling, and library files are used when linking.  %@NL@%
  889. %@NL@%
  890. You include the necessary header files in your program source code with
  891. %@AB@%#include%@AE@% directives. The description of each library routine in Part 2,
  892. "Reference," tells you what header file the routine requires. Since %@AB@%printf%@AE@%
  893. requires the STDIO.H header file, the SAMPLE.C program contains the
  894. following line:  %@NL@%
  895. %@NL@%
  896. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  897. %@NL@%
  898. This line causes the compiler to insert the contents of STDIO.H into the
  899. source file SAMPLE.C.  %@NL@%
  900. %@NL@%
  901. After you compile the source file, you link the resulting object (.OBJ) file
  902. with the appropriate library (.LIB) file to create an executable (.EXE)
  903. file. Your object file contains the name of every routine that your program
  904. calls, including library routines. If a routine is not defined in your
  905. program, the linker searches for its code in a library file and includes
  906. that code in the executable file.  %@NL@%
  907. %@NL@%
  908. Normally, the code for standard library routines is contained in the
  909. "default library" that you create when installing Microsoft C. Since the
  910. linker automatically searches the default library, you do not need to
  911. specify that library's name when linking your program. The following command
  912. links the example program with the default library:  %@NL@%
  913. %@NL@%
  914. %@AS@%  link sample,,,;%@AE@%%@NL@%
  915. %@NL@%
  916. If you call a library routine that is not contained in the default library,
  917. you must give the linker the name of the library file that contains the
  918. routine. For instance, suppose your program uses a Microsoft C graphics
  919. routine and you did not make GRAPHICS.LIB part of your default library when
  920. installing Microsoft C. You would then link the program using a line like
  921. the following:  %@NL@%
  922. %@NL@%
  923. %@AS@%  link sample,,, graphics.lib;%@AE@%%@NL@%
  924. %@NL@%
  925. For more information about libraries and linking, consult the installation
  926. documentation for your compiler.  %@NL@%
  927. %@NL@%
  928. %@NL@%
  929. %@2@%%@CR:C6A00010003 @%%@AB@%1.2  Using Header Files%@AE@%%@EH@%%@NL@%
  930. %@NL@%
  931. As stated in the previous section, you should include C header files when
  932. using library routines. This section describes particular reasons why header
  933. files are required.  %@NL@%
  934. %@NL@%
  935. %@NL@%
  936. %@3@%%@CR:C6A00010004 @%%@AB@%1.2.1  Including Necessary Definitions%@AE@%%@EH@%%@NL@%
  937. %@NL@%
  938. Many C library routines use constants, type definitions, or macros defined
  939. in a header file. To use the routine, you must include the header file
  940. containing the needed definition(s). The following list gives examples:  %@NL@%
  941. %@NL@%
  942. %@AB@%Definition%@AE@%                        %@AB@%Example%@AE@%
  943. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  944. Macro                             If a library routine is implemented as a
  945.                                   macro, the macro definition appears in a
  946.                                   header file. For instance, the %@AB@%toupper%@AE@% 
  947.                                   macro is defined in the header file 
  948.                                   CTYPE.H.
  949.  
  950. Manifest constant                 Many library routines refer to constants
  951.                                   that are defined in header files. For 
  952.                                   instance, the %@AB@%open%@AE@% routine uses 
  953.                                   constants such as %@AB@%O_CREAT%@AE@%, which is 
  954.                                   defined in the header file FCNTL.H.
  955.  
  956. Type definition                   Some library routines return a structure
  957.                                   or take a structure as an argument. For 
  958.                                   example, stream input/output routines 
  959.                                   use a structure of type %@AB@%FILE%@AE@%, which is 
  960.                                   defined in STDIO.H.
  961.  
  962. %@NL@%
  963. %@3@%%@CR:C6A00010005 @%%@AB@%1.2.2  Including Function Declarations%@AE@%%@EH@%%@NL@%
  964. %@NL@%
  965. The Microsoft C header files also contain function declarations for every
  966. function in the C library. These declarations are in the style recommended
  967. by the ANSI C standard. Given these declarations, the compiler can perform
  968. "type checking" on every reference to a library function, making sure that
  969. you have used the correct return type and arguments. Function declarations
  970. are sometimes called "prototypes," since the declaration serves as a
  971. prototype or template for every subsequent reference to the function.  %@NL@%
  972. %@NL@%
  973. A function declaration lists the name of the function, its return type, and
  974. the number and type of its arguments. For instance, below is the declaration
  975. of the %@AB@%pow%@AE@% library function from the header file MATH.H:  %@NL@%
  976. %@NL@%
  977. %@AS@%  double pow( double x, double y );%@AE@%%@NL@%
  978. %@NL@%
  979. The example declares that %@AB@%pow%@AE@% returns a value of type %@AB@%double%@AE@% and takes two
  980. arguments of type %@AB@%double%@AE@%. Given this declaration, the compiler can check
  981. every reference to %@AB@%pow%@AE@% in your program to ensure that the reference passes
  982. two %@AB@%double%@AE@% arguments to %@AB@%pow%@AE@% and takes a return value of type %@AB@%double%@AE@%.  %@NL@%
  983. %@NL@%
  984. The compiler can perform type checking only for function references that
  985. appear after the function declaration. Because of this, function
  986. declarations normally appear near the beginning of the source file, prior to
  987. any use of the functions they declare.  %@NL@%
  988. %@NL@%
  989. Function declarations are especially important for functions that return a
  990. value of some type other than %@AB@%int%@AE@%, which is the default. For example, the
  991. %@AB@%pow%@AE@% function returns a %@AB@%double%@AE@% value. If you do not declare such a function,
  992. the compiler treats its return value as %@AB@%int%@AE@%, which can cause unexpected
  993. results.  %@NL@%
  994. %@NL@%
  995. It is also a good practice to provide declarations for functions that you
  996. write. If you do not want to type the declarations by hand, you can generate
  997. them automatically by using the /Zg compiler option. This option causes the
  998. compiler to generate ANSI-standard function declarations for every function
  999. defined in the current source file. Redirect this output to a file, then
  1000. insert the file near the beginning of your source file.  %@NL@%
  1001. %@NL@%
  1002. Your program can contain more than one declaration of the same function, as
  1003. long as the declarations do not conflict. This is important if you have old
  1004. programs whose function declarations do not contain argument-type lists. For
  1005. instance, if your program contains the declaration  %@NL@%
  1006. %@NL@%
  1007. %@AS@%  char *calloc( );%@AE@%%@NL@%
  1008. %@NL@%
  1009. you can later include the following declaration:  %@NL@%
  1010. %@NL@%
  1011. %@AS@%  char *calloc(unsigned, unsigned);%@AE@%%@NL@%
  1012. %@NL@%
  1013. Because the two declarations are compatible, even though they are not
  1014. identical, no conflict occurs. The second declaration simply gives more
  1015. information about function arguments than the second. A conflict would
  1016. arise, however, if the declarations gave a different number of arguments or
  1017. gave arguments of different types.  %@NL@%
  1018. %@NL@%
  1019. Some library functions can take a variable number of arguments. For
  1020. instance, the %@AB@%printf %@AE@%function can take one argument or several. The compiler
  1021. can perform only limited type checking on such functions, a factor that
  1022. affects the following library functions:  %@NL@%
  1023. %@NL@%
  1024. %@NL@%
  1025.   ■   In calls to %@AB@%cprintf%@AE@%, %@AB@%cscanf%@AE@%, %@AB@%printf%@AE@%, and %@AB@%scanf%@AE@%, only the first
  1026.       argument (the format string) is type checked. %@NL@%
  1027. %@NL@%
  1028.   ■   In calls to %@AB@%fprintf%@AE@%, %@AB@%fscanf%@AE@%, %@AB@%sprintf%@AE@%, and %@AB@%sscanf%@AE@%, only the first two
  1029.       arguments (the file or buffer and the format string) are type checked.%@NL@%
  1030. %@NL@%
  1031.   ■   In calls to %@AB@%open%@AE@%, only the first two arguments (the path name and the
  1032.       %@AB@%open%@AE@% flag) are type checked. %@NL@%
  1033. %@NL@%
  1034.   ■   In calls to %@AB@%sopen%@AE@%, only the first three arguments (the path name, the
  1035.       %@AB@%open%@AE@% flag, and the sharing mode) are type checked. %@NL@%
  1036. %@NL@%
  1037.   ■   In calls to %@AB@%execl%@AE@%, %@AB@%execle%@AE@%, %@AB@%execlp%@AE@%, and %@AB@%execlpe%@AE@%, only the first two
  1038.       arguments (the path name and the first argument pointer) are type
  1039.       checked.%@NL@%
  1040. %@NL@%
  1041.   ■   In calls to %@AB@%spawnl%@AE@%, %@AB@%spawnle%@AE@%, %@AB@%spawnlp%@AE@%, and %@AB@%spawnlpe%@AE@%, only the first
  1042.       three arguments (the mode flag, the path name, and the first argument
  1043.       pointer) are type checked.%@NL@%
  1044. %@NL@%
  1045. %@NL@%
  1046. %@NL@%
  1047. %@2@%%@CR:C6A00010006 @%%@AB@%1.3  File Names and Path Names%@AE@%%@EH@%%@NL@%
  1048. %@NL@%
  1049. Many library routines take strings representing paths and file names as
  1050. arguments. If you plan to transport your programs to the XENIX operating
  1051. system, you should remember that XENIX uses file- and path-name conventions
  1052. that are different from those used by DOS and OS/2. If you do not plan to
  1053. transport your programs to XENIX, you can skip this section.  %@NL@%
  1054. %@NL@%
  1055. %@NL@%
  1056. %@4@%%@AB@%Case Sensitivity%@AE@%%@EH@%%@NL@%
  1057. %@NL@%
  1058. The DOS and OS/2 operating systems are not case sensitive (they do not
  1059. distinguish between uppercase and lowercase letters). Thus, SAMPLE.C and
  1060. Sample.C refer to the same file in DOS and OS/2. However, the XENIX
  1061. operating system is case sensitive. In XENIX, SAMPLE.C and Sample.C refer to
  1062. different files. To transport programs to XENIX, choose file and path names
  1063. that work correctly in XENIX, since either case works in DOS and OS/2. For
  1064. instance, the following directives are identical in DOS and OS/2, but only
  1065. the second works in XENIX:  %@NL@%
  1066. %@NL@%
  1067. %@AS@%  #include <STDIO.H>
  1068. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  1069. %@NL@%
  1070. %@NL@%
  1071. %@4@%%@AB@%Subdirectory Conventions%@AE@%%@EH@%%@NL@%
  1072. %@NL@%
  1073. Under XENIX, certain header files are normally placed in a subdirectory
  1074. named SYS. Microsoft C follows this convention to ease the process of
  1075. transporting programs to XENIX. If you do not plan to transport your
  1076. programs, you can place the SYS header files elsewhere.  %@NL@%
  1077. %@NL@%
  1078. %@NL@%
  1079. %@4@%%@AB@%Path-Name Delimiters%@AE@%%@EH@%%@NL@%
  1080. %@NL@%
  1081. XENIX uses the slash (%@AB@%/%@AE@%) in path names, while DOS and OS/2 use the backslash
  1082. (%@AB@%\%@AE@%). To transport programs to XENIX, it is advantageous to use path-name
  1083. delimiters that are compatible with XENIX whenever possible.  %@NL@%
  1084. %@NL@%
  1085. %@NL@%
  1086. %@2@%%@CR:C6A00010007 @%%@AB@%1.4  Choosing Between Functions and Macros%@AE@%%@EH@%%@NL@%
  1087. %@NL@%
  1088. This book uses the words "routine" and "function" interchangeably. However,
  1089. the term "routine" actually encompasses both functions and macros. Because
  1090. functions and macros have different properties, you should pay attention to
  1091. which form you are using. The descriptions in the reference section indicate
  1092. whether routines are implemented as functions or as macros.  %@NL@%
  1093. %@NL@%
  1094. Most routines in the Microsoft C library are functions. They consist of
  1095. compiled C code or assembled Microsoft Macro Assembler (MASM) code. However,
  1096. a few library routines are implemented as macros that behave like functions.
  1097. You can pass arguments to library macros and invoke them in the same way you
  1098. invoke functions.  %@NL@%
  1099. %@NL@%
  1100. The main benefit of using macros is faster execution time. A macro is
  1101. expanded (replaced by its definition) during preprocessing, creating in-line
  1102. code. Thus, macros do not have the overhead associated with function calls.
  1103. On the other hand, each use of a macro inserts the same code in your
  1104. program, whereas a function definition occurs only once regardless of how
  1105. many times it is called. Functions and macros thus offer a trade-off between
  1106. speed and size.  %@NL@%
  1107. %@NL@%
  1108. Apart from speed and size issues, macros and functions have some other
  1109. important differences:  %@NL@%
  1110. %@NL@%
  1111. %@NL@%
  1112.   ■   Some macros treat arguments with side effects incorrectly when the
  1113.       macro evaluates its arguments more than once (see the example that
  1114.       follows this list). Not every macro has this effect. To determine if a
  1115.       macro handles side effects as desired, examine its definition in the
  1116.       appropriate header file.%@NL@%
  1117. %@NL@%
  1118.   ■   A function name evaluates to an address, but a macro name does not.
  1119.       Thus, you cannot use a macro name in contexts requiring a function
  1120.       pointer. For instance, you can declare a pointer to a function, but
  1121.       you cannot declare a pointer to a macro.%@NL@%
  1122. %@NL@%
  1123.   ■   You can declare functions, but you cannot declare macros. Thus, the
  1124.       compiler cannot perform type checking of macro arguments as it does of
  1125.       function arguments. However, the compiler can detect when you pass the
  1126.       wrong number of arguments to a macro.%@NL@%
  1127. %@NL@%
  1128.   ■   You must always include the appropriate header file when using a
  1129.       library macro. Every library macro is defined with a %@AB@%#define%@AE@% directive
  1130.       in a header file. If you do not include the header file, the macro is
  1131.       undefined.%@NL@%
  1132. %@NL@%
  1133. %@NL@%
  1134. The following example demonstrates how some macros can produce unwanted side
  1135. effects. It uses the %@AB@%toupper%@AE@% routine from the standard C library.  %@NL@%
  1136. %@NL@%
  1137. %@AS@%  #include <ctype.h>
  1138. %@AS@%  
  1139. %@AS@%  int a = 'm';
  1140. %@AS@%  a = toupper(a++);%@AE@%%@NL@%
  1141. %@NL@%
  1142. The example increments %@AS@% a %@AE@% when passing it as an argument to the %@AB@%toupper%@AE@%
  1143. routine, which is implemented as a macro. It is defined in CTYPE.H:  %@NL@%
  1144. %@NL@%
  1145. %@AS@%  #define toupper(c)  ( (islower(c)) ? _toupper(c) : (c) )%@AE@%%@NL@%
  1146. %@NL@%
  1147. The definition uses the conditional operator (%@AB@%? :%@AE@%). The conditional
  1148. expression evaluates the argument %@AS@% c %@AE@% twice: once to check if it is
  1149. lowercase and again to create the result. This macro evaluates the argument %@AS@%
  1150. %@AS@%a++ %@AE@% twice, increasing %@AS@% a %@AE@% by 2 instead of 1. As a result, the value
  1151. operated on by %@AB@%islower%@AE@% differs from the value operated on by %@AB@%_toupper%@AE@%.  %@NL@%
  1152. %@NL@%
  1153. Like some other library routines, %@AB@%toupper%@AE@% is provided in both macro and
  1154. function versions. The header file CTYPE.H not only declares the %@AB@%toupper%@AE@%
  1155. function but also defines the %@AB@%toupper%@AE@% macro.  %@NL@%
  1156. %@NL@%
  1157. Choosing between the macro version and function version of such routines is
  1158. easy. If you wish to use the macro version, you can simply include the
  1159. header file that contains the macro definition. Because the macro definition
  1160. of the routine always appears after the function declaration, the macro
  1161. definition normally takes precedence. Thus, if your program includes CTYPE.H
  1162. and then calls %@AB@%toupper%@AE@%, the compiler uses the %@AB@%toupper%@AE@% macro:  %@NL@%
  1163. %@NL@%
  1164. %@AS@%  #include <ctype.h>
  1165. %@AS@%  
  1166. %@AS@%  int a = 'm';
  1167. %@AS@%  a = toupper(a);%@AE@%%@NL@%
  1168. %@NL@%
  1169. You can force the compiler to use the function version of a routine by
  1170. enclosing the routine's name in parentheses:  %@NL@%
  1171. %@NL@%
  1172. %@AS@%  #include <ctype.h>
  1173. %@AS@%  
  1174. %@AS@%  int a = 'm';
  1175. %@AS@%  a = (toupper) (a);%@AE@%%@NL@%
  1176. %@NL@%
  1177. Because the name %@AB@%toupper%@AE@% is not immediately followed by a left parenthesis,
  1178. the compiler cannot interpret it as a macro name. It must use the %@AB@%toupper%@AE@%
  1179. function.  %@NL@%
  1180. %@NL@%
  1181. A second way to do this is to "undefine" the macro definition with the
  1182. %@AB@%#undef%@AE@% directive:  %@NL@%
  1183. %@NL@%
  1184. %@AS@%  #include <ctype.h>
  1185. %@AS@%  #undef toupper%@AE@%%@NL@%
  1186. %@NL@%
  1187. Since the macro definition no longer exists, subsequent references to
  1188. %@AB@%toupper%@AE@% use the function version.  %@NL@%
  1189. %@NL@%
  1190. A third way to make sure the compiler uses the function version is to
  1191. declare the function explicitly:  %@NL@%
  1192. %@NL@%
  1193. %@AS@%  #include <ctype.h>
  1194. %@AS@%  int toupper(int _c);%@AE@%%@NL@%
  1195. %@NL@%
  1196. Since this function declaration appears after the macro definition in
  1197. CTYPE.H, it causes the compiler to use the %@AB@%toupper%@AE@% function.  %@NL@%
  1198. %@NL@%
  1199. %@NL@%
  1200. %@2@%%@CR:C6A00010008 @%%@AB@%1.5  Stack Checking on Entry%@AE@%%@EH@%%@NL@%
  1201. %@NL@%
  1202. For certain library routines, the compiler performs stack checking on entry.
  1203. (The "stack" is a memory area used for temporary storage.) Upon entry to
  1204. such a routine, the stack is checked to determine if it has enough room for
  1205. the local variables used by that routine. If it does, space is allocated by
  1206. adjusting the stack pointer. Otherwise, a "stack overflow" run-time error
  1207. occurs. If stack checking is disabled, the compiler assumes there is enough
  1208. stack space; if there is not, you might overwrite memory locations in the
  1209. data segment and receive no warning.  %@NL@%
  1210. %@NL@%
  1211. Typically, stack checking is enabled only for functions with large
  1212. local-variable requirements (more than about 150 bytes), since there is
  1213. enough free space between the stack and data segments to handle functions
  1214. with smaller requirements. If the function is called many times, stack
  1215. checking slows execution slightly.  %@NL@%
  1216. %@NL@%
  1217. Stack checking is enabled for the following library functions:  %@NL@%
  1218. %@NL@%
  1219. %@AB@%execvp          printf          spawnvpe        system%@AE@%
  1220. %@AB@%execvpe         scanf           sprintf         vprintf%@AE@%
  1221. %@AB@%fprintf         spawnvp         sscanf          write %@AE@%
  1222. %@AB@%fscanf          
  1223.  
  1224. %@2@%%@CR:C6A00010009 @%%@AB@%1.6  Handling Errors%@AE@%%@EH@%%@NL@%
  1225. %@NL@%
  1226. Many library routines return a value that indicates an error condition. To
  1227. avoid unexpected results, your code should always check such error values
  1228. and handle all of the possible error conditions. The description of each
  1229. library routine in the reference section lists the routine's return
  1230. value(s).  %@NL@%
  1231. %@NL@%
  1232. Some library functions do not have a set error return. These include
  1233. functions that return nothing and functions whose range of return values
  1234. makes it impossible to return a unique error value. To aid in error
  1235. handling, some functions in this category set the value of a global variable
  1236. named %@AB@%errno%@AE@%.  %@NL@%
  1237. %@NL@%
  1238. If the reference description of a routine states that it sets the %@AB@%errno%@AE@%
  1239. variable, you can use %@AB@%errno%@AE@% in two ways:  %@NL@%
  1240. %@NL@%
  1241. %@NL@%
  1242.   1.  Compare %@AB@%errno%@AE@% to the values defined in the header file ERRNO.H.%@NL@%
  1243. %@NL@%
  1244.   2.  Handle %@AB@%errno%@AE@% with the %@AB@%perror%@AE@% or %@AB@%strerror%@AE@% library routines. The %@AB@%perror%@AE@%
  1245.       routine prints a system error message to the standard error (%@AB@%stderr%@AE@%).
  1246.       The %@AB@%strerror%@AE@% routine stores the same information in a string for later
  1247.       use.%@NL@%
  1248. %@NL@%
  1249. %@NL@%
  1250. When you use %@AB@%errno%@AE@%, %@AB@%perror%@AE@%, and %@AB@%strerror%@AE@%, remember that the value of %@AB@%errno%@AE@%
  1251. reflects the error value for the last call that set %@AB@%errno%@AE@%. To avoid
  1252. confusion, you should always test the return value to verify that an error
  1253. actually occurred. Once you determine that an error has occurred, use %@AB@%errno%@AE@%
  1254. or %@AB@%perror%@AE@% immediately. Otherwise, the value of %@AB@%errno%@AE@% may be changed by
  1255. intervening calls.  %@NL@%
  1256. %@NL@%
  1257. Library math routines set %@AB@%errno%@AE@% by calling the %@AB@%matherr%@AE@% or %@AB@%_matherrl%@AE@% library
  1258. routines, which are described in the reference section. If you wish to
  1259. handle math errors differently from these routines, you can write your own
  1260. routine and name it %@AB@%matherr%@AE@% or %@AB@%_matherrl%@AE@%. Your routine must follow the rules
  1261. listed in the %@AB@%matherr%@AE@% reference description.  %@NL@%
  1262. %@NL@%
  1263. The %@AB@%ferror%@AE@% library routine allows you to check for errors in stream
  1264. input/output operations. This routine checks if an error indicator has been
  1265. set for a given stream. Closing or rewinding the stream automatically clears
  1266. the error indicator. You can also reset the error indicator by calling the
  1267. %@AB@%clearerr%@AE@% library routine.  %@NL@%
  1268. %@NL@%
  1269. The %@AB@%feof%@AE@% library routine tests for end-of-file on a given stream. An
  1270. end-of-file condition in low-level input and output can be detected with the
  1271. %@AB@%eof%@AE@% routine or when a %@AB@%read%@AE@% operation returns 0 as the number of bytes read.
  1272. %@NL@%
  1273. %@NL@%
  1274. The %@AB@%_grstatus%@AE@% library routine allows you to check for errors after calling
  1275. certain graphics library operations. See the reference page on the %@AB@%_grstatus%@AE@%
  1276. function for details.  %@NL@%
  1277. %@NL@%
  1278. %@NL@%
  1279. %@2@%%@CR:C6A00010010 @%%@AB@%1.7  Operating-System Considerations%@AE@%%@EH@%%@NL@%
  1280. %@NL@%
  1281. The library routines listed in this section behave differently under
  1282. different operating system versions. For more information on an individual
  1283. routine, see the description of that routine in the reference section.  %@NL@%
  1284. %@NL@%
  1285. %@AB@%Routine%@AE@%                           %@AB@%Restrictions%@AE@%
  1286. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1287. %@AB@%locking%@AE@%                           These routines are effective only in 
  1288. %@AB@%sopen%@AE@%                             OS/2 and in DOS versions 3.0 and later.
  1289. %@AB@%_fsopen%@AE@%                           
  1290.  
  1291. %@AB@%dosexterr%@AE@%                         The %@AB@%dosexterr%@AE@% routine provides error 
  1292.                                   handling for system call 0x59 (get 
  1293.                                   extended error) in DOS versions 3.0 and 
  1294.                                   later.
  1295.  
  1296. %@AB@%dup%@AE@%                               The %@AB@%dup%@AE@% and %@AB@%dup2%@AE@% routines can cause 
  1297. %@AB@%dup2%@AE@%                              unexpected results in DOS versions 
  1298.                                   earlier than 3.0. If you use %@AB@%dup%@AE@% or %@AB@%dup2%@AE@%
  1299.                                   to create a duplicate file handle for %@AB@%%@AE@%
  1300.                                   %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, %@AB@%stderr%@AE@%, %@AB@%stdaux%@AE@%, or %@AB@%stdprn%@AE@%
  1301.                                   , calling the %@AB@%close%@AE@% function with one 
  1302.                                   handle causes errors in later I/O 
  1303.                                   operations that use the other handle. 
  1304.                                   This anomaly does not occur in OS/2 or 
  1305.                                   in DOS versions 3.0 and later.
  1306.  
  1307. %@AB@%exec%@AE@%                              When using the %@AB@%exec%@AE@% and %@AB@%spawn%@AE@% families 
  1308. %@AB@%spawn%@AE@%                             of functions under DOS versions earlier 
  1309.                                   than 3.0, the value of the %@AI@%arg0%@AE@% argument
  1310.                                   (or %@AI@%argv%@AE@%[0] to the child process) is not
  1311.                                   available to the user; a null string (%@AS@%""%@AE@%
  1312.                                   ) is stored in that position instead. In
  1313.                                   OS/2, the %@AI@%arg0%@AE@% argument contains the 
  1314.                                   command name; in DOS versions 3.0 and 
  1315.                                   later, it contains the complete command 
  1316.                                   path.
  1317.  
  1318. Microsoft C defines global variables that indicate the version of the
  1319. current operating system. You can use these to determine the
  1320. operating-system version in which a program is executing. See Chapter 3,
  1321. "Global Variables and Standard Types," for more information.  %@NL@%
  1322. %@NL@%
  1323. %@NL@%
  1324. %@2@%%@CR:C6A00010011 @%%@AB@%1.8  Floating-Point Support%@AE@%%@EH@%%@NL@%
  1325. %@NL@%
  1326. Microsoft math library routines require floating-point support to perform
  1327. calculations with real numbers (numbers that can contain fractions). This
  1328. support can be provided by the floating-point libraries that accompany your
  1329. compiler software or by an 8087, 80287, or 80387 coprocessor. The names of
  1330. the functions that require floating-point support are listed below:  %@NL@%
  1331. %@NL@%
  1332. %@AB@%acos            cos             fmod            modfl%@AE@%
  1333. %@AB@%acosl           cosl            fmodl           pow%@AE@%
  1334. %@AB@%asin            cosh            fmsbintoieee    powl%@AE@%
  1335. %@AB@%asinl           coshl           _fpreset        sin%@AE@%
  1336. %@AB@%atan            dieeetomsbin    frexp           sinl%@AE@%
  1337. %@AB@%atanl           difftime        frexpl          sinh%@AE@%
  1338. %@AB@%atan2           dmsbintoieee    gcvt            sinhl%@AE@%
  1339. %@AB@%atan2l          ecvt            hypot           sqrt%@AE@%
  1340. %@AB@%atof            exp             hypotl          sqrtl%@AE@%
  1341. %@AB@%_atold          expl            ldexp           _status87%@AE@%
  1342. %@AB@%bessel          fabs            ldexpl          strtod%@AE@%
  1343. %@AB@%cabs            fabsl           log             _strtold%@AE@%
  1344. %@AB@%cabsl           fcvt            logl            tan%@AE@%
  1345. %@AB@%ceil            fieeetomsbin    log10           tanl%@AE@%
  1346. %@AB@%ceill           floor           log10l          tanh%@AE@%
  1347. %@AB@%_clear87        floorl          modf            tanhl%@AE@%
  1348. %@AB@%_control87      
  1349.  
  1350. Note that the %@AB@%bessel%@AE@% routine does not correspond to a single function, but
  1351. to twelve functions named %@AB@%j0%@AE@%, %@AB@%j1%@AE@%, %@AB@%jn%@AE@%, %@AB@%y0%@AE@%, %@AB@%y1%@AE@%, %@AB@%yn%@AE@%, %@AB@%_j0l%@AE@%, %@AB@%_j1l%@AE@%, %@AB@%_jnl%@AE@%, %@AB@%_y0l%@AE@%,
  1352. %@AB@%_y1l%@AE@%, and %@AB@%_ynl%@AE@%. Also note that the %@AB@%_clear87%@AE@% and %@AB@%_control87%@AE@% functions are not
  1353. available with the /FPa compiler option.  %@NL@%
  1354. %@NL@%
  1355. Also requiring floating-point support is the %@AB@%printf%@AE@% family of functions
  1356. (%@AB@%cprintf%@AE@%, %@AB@%fprintf%@AE@%, %@AB@%printf%@AE@%, %@AB@%sprintf%@AE@%, %@AB@%vfprintf%@AE@%, %@AB@%vprintf%@AE@%, and %@AB@%vsprintf%@AE@%). These
  1357. functions require support for floating-point input and output if used to
  1358. print floating-point values.  %@NL@%
  1359. %@NL@%
  1360. The C compiler tries to detect whether floating-point values are used in a
  1361. program so that supporting functions are loaded only if required. This
  1362. behavior saves a considerable amount of space for programs that do not
  1363. require floating-point support.  %@NL@%
  1364. %@NL@%
  1365. When you use a floating-point type specifier in the format string for a
  1366. %@AB@%printf%@AE@% or %@AB@%scanf%@AE@% call, make sure you specify floating-point values or
  1367. pointers to floating-point values in the argument list. These must
  1368. correspond to any floating-point  %@NL@%
  1369. %@NL@%
  1370. type specifiers in the format string. The presence of floating-point
  1371. arguments allows the compiler to detect that floating-point support code is
  1372. required. If a floating-point type specifier is used to print an integer
  1373. argument, for example, floating-point values will not be detected because
  1374. the compiler does not actually read the format string used in the %@AB@%printf%@AE@% and
  1375. %@AB@%scanf%@AE@% functions. For instance, the following program produces an error at
  1376. run time:  %@NL@%
  1377. %@NL@%
  1378. %@AS@%  main( ) /* This example causes an error */
  1379. %@AS@%   {
  1380. %@AS@%    long f = 10L;
  1381. %@AS@%    printf("%f", f);
  1382. %@AS@%   }%@AE@%%@NL@%
  1383. %@NL@%
  1384. In the preceding example, the functions for floating-point support are not
  1385. loaded because  %@NL@%
  1386. %@NL@%
  1387. %@NL@%
  1388.   ■   No floating-point arguments are given in the call to %@AB@%printf%@AE@%.%@NL@%
  1389. %@NL@%
  1390.   ■   No floating-point values are used elsewhere in the program.%@NL@%
  1391. %@NL@%
  1392. %@NL@%
  1393. As a result, the following error occurs:  %@NL@%
  1394. %@NL@%
  1395. %@AS@%  Floating point not loaded%@AE@%%@NL@%
  1396. %@NL@%
  1397. Here is a corrected version of the above call to %@AB@%printf%@AE@% in which the long
  1398. integer value is cast to %@AB@%double%@AE@%:  %@NL@%
  1399. %@NL@%
  1400. %@AS@%  main( ) /* This example works correctly */
  1401. %@AS@%   {
  1402. %@AS@%    long f = 10L;
  1403. %@AS@%    printf("%f", (double) f);
  1404. %@AS@%   }%@AE@%%@NL@%
  1405. %@NL@%
  1406. %@NL@%
  1407. %@2@%%@CR:C6A00010012 @%%@AB@%1.9  Using Huge Arrays with Library Functions%@AE@%%@EH@%%@NL@%
  1408. %@NL@%
  1409. In programs that use small, compact, medium, and large memory models,
  1410. Microsoft C allows you to use arrays exceeding the 64K (kilobyte) limit of
  1411. physical memory in these models by explicitly declaring the arrays as %@AB@%_huge%@AE@%.
  1412. However, generally, you cannot pass %@AB@%_huge%@AE@% data items as arguments to C
  1413. library functions. In the compact-model library used by compact-model
  1414. programs and in the large-model library used by both large-model and
  1415. huge-model programs, only the functions listed below use argument arithmetic
  1416. that works with %@AB@%_huge%@AE@% items:  %@NL@%
  1417. %@NL@%
  1418. %@AB@%bsearch         _fmemcmp        _fmemset        lsearch%@AE@%
  1419. %@AB@%fread           _fmemcpy        halloc          memccpy%@AE@%
  1420. %@AB@%fwrite          _fmemicmp       hfree           memchr%@AE@%
  1421. %@AB@%_fmemccpy       _fmemmove       lfind           %@AE@%
  1422. %@AB@%_fmemchr        
  1423.  
  1424. With this set of functions, you can read from, write to, search, sort, copy,
  1425. initialize, compare, or dynamically allocate and free %@AB@%_huge%@AE@% arrays; the
  1426. %@AB@%_huge%@AE@% array can be passed without difficulty to any of these functions in a
  1427. compact-, large-, or huge-model program. The model-independent routines in
  1428. the above list (those beginning with %@AB@%_f%@AE@%) are available in all memory models.
  1429. %@NL@%
  1430. %@NL@%
  1431. The %@AB@%memset%@AE@%, %@AB@%memcpy%@AE@%, and %@AB@%memcmp%@AE@%library routines are available in two
  1432. versions: as C functions and as intrinsic (in-line) code. The function
  1433. versions of these routines support huge pointers in compact and large memory
  1434. models, but the intrinsic versions do not support huge pointers. (The
  1435. function version of such routines generates a call to a library function,
  1436. whereas the intrinsic version inserts in-line code into your program. Your
  1437. compiler documentation explains how to select the intrinsic versions of
  1438. library routines.) %@NL@%
  1439. %@NL@%
  1440. %@NL@%
  1441. %@NL@%
  1442. %@NL@%
  1443. %@CR:C6A00020001 @%%@1@%%@AB@%Chapter 2  Run-Time Routines by Category%@AE@%%@EH@%%@NL@%
  1444. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1445. %@NL@%
  1446. Microsoft C library routines handle various kinds of tasks. If you know the
  1447. type of task you need done, but don't know exactly which routine to use, the
  1448. categorized lists of routines in this chapter can help.  %@NL@%
  1449. %@NL@%
  1450. The descriptions here are intended only to give you a brief overview of the
  1451. capabilities of the run-time library. For a complete description of the
  1452. behavior, syntax, and use of each routine, see Part 2, "Run-Time Functions."
  1453. %@NL@%
  1454. %@NL@%
  1455. The main categories of library routines are  %@NL@%
  1456. %@NL@%
  1457. %@NL@%
  1458.   ■   Buffer manipulation%@NL@%
  1459. %@NL@%
  1460.   ■   Character classification and conversion%@NL@%
  1461. %@NL@%
  1462.   ■   Data conversion%@NL@%
  1463. %@NL@%
  1464.   ■   Directory control%@NL@%
  1465. %@NL@%
  1466.   ■   File handling%@NL@%
  1467. %@NL@%
  1468.   ■   Graphics%@NL@%
  1469. %@NL@%
  1470.   ■   Input and output%@NL@%
  1471. %@NL@%
  1472.   ■   Internationalization%@NL@%
  1473. %@NL@%
  1474.   ■   Math%@NL@%
  1475. %@NL@%
  1476.   ■   Memory allocation%@NL@%
  1477. %@NL@%
  1478.   ■   Process and environment control%@NL@%
  1479. %@NL@%
  1480.   ■   Searching and sorting%@NL@%
  1481. %@NL@%
  1482.   ■   String manipulation%@NL@%
  1483. %@NL@%
  1484.   ■   System calls%@NL@%
  1485. %@NL@%
  1486.   ■   Time%@NL@%
  1487. %@NL@%
  1488.   ■   Variable-length argument lists%@NL@%
  1489. %@NL@%
  1490. %@NL@%
  1491. %@NL@%
  1492. %@2@%%@CR:C6A00020002 @%%@AB@%2.1  Buffer Manipulation%@AE@%%@EH@%%@NL@%
  1493. %@NL@%
  1494. The buffer-manipulation routines are useful for working with areas of memory
  1495. on a character-by-character basis. A "buffer" is an array of characters,
  1496. similar to a character string. However, unlike strings, buffers are not
  1497. usually terminated with a null character (%@AB@%'\0'%@AE@%). Therefore, the
  1498. buffer-manipulation routines always take a %@AI@%length%@AE@% or %@AI@%count%@AE@% argument.
  1499. Function declarations for the buffermanipulation routines are given in the
  1500. include files MEMORY.H and STRING.H, with an exception being the %@AB@%swab%@AE@%
  1501. function, which appears in STDLIB.H.%@CR:C6A00020003 @%%@CR:C6A00020004 @%  %@NL@%
  1502. %@NL@%
  1503. Routines beginning with %@AB@%_f%@AE@%  are model independent; the %@AB@%_f%@AE@%  stands for %@AB@%far%@AE@%.
  1504. These routines are useful in writing mixed-model programs because they can
  1505. be called from any program, regardless of the memory model being used.%@CR:C6A00020005 @%  %@NL@%
  1506. %@NL@%
  1507. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1508. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1509. %@AB@%memccpy%@AE@%,  %@AB@%_fmemccpy%@AE@%               Copy characters from one buffer to 
  1510.                                   another until a given character or a 
  1511.                                   given number of characters has been 
  1512.                                   copied %@CR:C6A00020006 @% %@CR:C6A00020007 @%
  1513.  
  1514. %@AB@%memchr%@AE@%,  %@AB@%_fmemchr%@AE@%                 Return a pointer to the first 
  1515.                                   occurrence, within a specified number of
  1516.                                   characters, of a given character in the 
  1517.                                   buffer %@CR:C6A00020008 @% %@CR:C6A00020009 @%
  1518.  
  1519. %@AB@%memcmp%@AE@%,  %@AB@%_fmemcmp%@AE@%                 Compare a specified number of characters
  1520.                                   from two buffers %@CR:C6A00020010 @% %@CR:C6A00020011 @%
  1521.  
  1522. %@AB@%memcpy%@AE@%,  %@AB@%_fmemcpy%@AE@%                 Copy a specified number of characters 
  1523.                                   from one buffer to another %@CR:C6A00020012 @% %@CR:C6A00020013 @%
  1524.  
  1525. %@AB@%memicmp%@AE@%, %@AB@%_fmemicmp%@AE@%                Compare a specified number of characters
  1526.                                   from two buffers without regard to the 
  1527.                                   case of the letters (uppercase and 
  1528.                                   lowercase treated as equivalent) %@CR:C6A00020014 @% %@CR:C6A00020015 @%
  1529.  
  1530. %@AB@%memmove%@AE@%,%@AB@%%@AE@%                          Copy a specified number of characters 
  1531. %@AB@%_fmemmove%@AE@%                         from one buffer to another %@CR:C6A00020016 @% %@CR:C6A00020017 @%
  1532.  
  1533. %@AB@%memset%@AE@%,  %@AB@%_fmemset%@AE@%                 Use a given character to initialize a 
  1534.                                   specified number of bytes in the buffer %@CR:C6A00020018 @%
  1535.                                   %@CR:C6A00020019 @%
  1536.  
  1537. %@AB@%swab%@AE@%                              Swaps bytes of data and stores them at 
  1538.                                   the specified location
  1539.  
  1540. When the source and target areas overlap, only the %@AB@%memmove%@AE@% and %@AB@%_fmemmove%@AE@%
  1541. functions are guaranteed to copy the full source properly. (The %@AB@%memcpy%@AE@% and
  1542. %@AB@%_fmemcpy%@AE@% routines do not always copy the full source in such cases.)  %@NL@%
  1543. %@NL@%
  1544. %@NL@%
  1545. %@2@%%@CR:C6A00020020 @%%@AB@%2.2  Character Classification and Conversion%@AE@%%@EH@%%@NL@%
  1546. %@NL@%
  1547. The character classification and conversion routines allow you to test
  1548. individual characters in a variety of ways and to convert between uppercase
  1549. and lowercase characters.  %@NL@%
  1550. %@NL@%
  1551. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1552. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1553. %@AB@%isalnum%@AE@%%@CR:C6A00020021 @%%@CR:C6A00020022 @%                           Tests for alphanumeric character
  1554.  
  1555. %@AB@%isalpha%@AE@%                           Tests for alphabetic character
  1556.  
  1557. %@AB@%isascii%@AE@%                           Tests for ASCII character
  1558.  
  1559. %@AB@%iscntrl%@AE@%                           Tests for control character
  1560.  
  1561. %@AB@%isdigit%@AE@%                           Tests for decimal digit
  1562.  
  1563. %@AB@%isgraph%@AE@%                           Tests for printable character except 
  1564.                                   space
  1565.  
  1566. %@AB@%islower%@AE@%%@CR:C6A00020023 @%%@CR:C6A00020024 @%                           Tests for lowercase character
  1567.  
  1568. %@AB@%isprint%@AE@%%@CR:C6A00020025 @%%@CR:C6A00020026 @%                           Tests for printable character
  1569.  
  1570. %@AB@%ispunct%@AE@%%@CR:C6A00020027 @%%@CR:C6A00020028 @%                           Tests for punctuation character
  1571.  
  1572. %@AB@%isspace%@AE@%%@CR:C6A00020029 @%%@CR:C6A00020030 @%                           Tests for white-space character
  1573.  
  1574. %@AB@%isupper%@AE@%%@CR:C6A00020031 @%                           Tests for uppercase character
  1575.  
  1576. %@AB@%isxdigit%@AE@%%@CR:C6A00020032 @%                          Tests for hexadecimal digit
  1577.  
  1578. %@AB@%toascii%@AE@% %@CR:C6A00020033 @%%@CR:C6A00020034 @%                          Converts character to ASCII code
  1579.  
  1580. %@AB@%tolower%@AE@%%@CR:C6A00020035 @%                           Tests character and converts to 
  1581.                                   lowercase if uppercase%@CR:C6A00020036 @%%@CR:C6A00020037 @% %@CR:C6A00020038 @%
  1582.  
  1583. %@AB@%_tolower%@AE@%                          Converts character to lowercase 
  1584.                                   (unconditional)
  1585.  
  1586. %@AB@%toupper%@AE@%                           Tests character and converts to 
  1587.                                   uppercase if
  1588.                                   lowercase
  1589.  
  1590. %@AB@%_toupper%@AE@%                          Converts character to uppercase 
  1591.                                   (unconditional)
  1592.  
  1593. The classification routines identify characters by finding them in a table
  1594. of classification codes. Using these routines to classify characters is
  1595. generally faster than writing a test expression such as the following:  %@NL@%
  1596. %@NL@%
  1597. %@AS@%  if ((c >= 0) || c <= 0x7f))%@AE@%%@NL@%
  1598. %@NL@%
  1599. All of these routines are implemented in two versions: as functions and as
  1600. macros. The function prototypes and macro definitions appear in CTYPE.H.
  1601. Section 1.4, "Choosing Between Functions and Macros," explains how to choose
  1602. the appropriate version. The %@AB@%toupper%@AE@% and %@AB@%tolower%@AE@% functions are also declared
  1603. in the STDLIB.H header file.%@CR:C6A00020039 @%%@CR:C6A00020040 @%%@CR:C6A00020041 @%  %@NL@%
  1604. %@NL@%
  1605. %@NL@%
  1606. %@2@%%@CR:C6A00020042 @%%@AB@%2.3  Data Conversion%@CR:C6A00020043 @% %@CR:C6A00020044 @%%@CR:C6A00020045 @%%@AE@%%@EH@%%@NL@%
  1607. %@NL@%
  1608. The data-conversion routines convert numbers to strings of ASCII characters
  1609. and vice versa. These routines are implemented as functions, all of which
  1610. are declared in the include file STDLIB.H. The %@AB@%atof%@AE@% function, which converts
  1611. a string to a floating-point value, is also declared in MATH.H.  %@NL@%
  1612. %@NL@%
  1613. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1614. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1615. %@AB@%abs%@AE@%                               Finds absolute value of integer
  1616.  
  1617. %@AB@%atof%@AE@%%@CR:C6A00020046 @%%@CR:C6A00020047 @%                              Converts string to %@AB@%float%@AE@%
  1618.  
  1619. %@AB@%atoi%@AE@%%@CR:C6A00020048 @%                              Converts string to %@AB@%int%@AE@%
  1620.  
  1621. %@AB@%atol%@AE@%                              Converts string to %@AB@%long%@AE@%
  1622.  
  1623. %@AB@%_atold%@AE@%                            Converts string to %@AB@%long double%@AE@%
  1624.  
  1625. %@AB@%ecvt%@AE@%%@CR:C6A00020049 @%%@CR:C6A00020050 @%                              Converts %@AB@%double%@AE@% to string
  1626.  
  1627. %@AB@%fcvt%@AE@%%@CR:C6A00020051 @%%@CR:C6A00020052 @%                              Converts %@AB@%double%@AE@% to string
  1628.  
  1629. %@AB@%gcvt%@AE@%%@CR:C6A00020053 @%%@CR:C6A00020054 @%                              Converts %@AB@%double%@AE@% to string
  1630.  
  1631. %@AB@%itoa%@AE@%%@CR:C6A00020055 @%%@CR:C6A00020056 @%                              Converts %@AB@%int%@AE@% to string
  1632.  
  1633. %@AB@%labs%@AE@%                              Finds absolute value of %@AB@%long%@AE@% integer
  1634.  
  1635. %@AB@%ltoa%@AE@%%@CR:C6A00020057 @%%@CR:C6A00020058 @%                              Converts %@AB@%long%@AE@% to string
  1636.  
  1637. %@AB@%strtod%@AE@%%@CR:C6A00020059 @%                            Converts string to %@AB@%double%@AE@%
  1638.  
  1639. %@AB@%strtol%@AE@%%@CR:C6A00020060 @%%@CR:C6A00020061 @%                            Converts string to a %@AB@%long%@AE@% integer
  1640.  
  1641. %@AB@%_strtold%@AE@%                          Converts string to %@AB@%long double%@AE@%
  1642.  
  1643. %@AB@%strtoul%@AE@%%@CR:C6A00020062 @%                           Converts string to an %@AB@%unsigned long%@AE@% 
  1644.                                   integer
  1645.  
  1646. %@AB@%ultoa%@AE@%%@CR:C6A00020063 @%%@CR:C6A00020064 @%                             Converts %@AB@%unsigned long%@AE@% to string
  1647.  
  1648. %@NL@%
  1649. %@2@%%@CR:C6A00020065 @%%@AB@%2.4  Directory Control%@CR:C6A00020066 @%%@AE@%%@EH@%%@NL@%
  1650. %@NL@%
  1651. The directory-control routines let a program access, modify, and obtain
  1652. information about the directory structure. These routines are functions and
  1653. are declared in DIRECT.H.%@CR:C6A00020067 @%  %@NL@%
  1654. %@NL@%
  1655. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1656. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1657. %@AB@%chdir%@AE@%%@CR:C6A00020068 @%%@CR:C6A00020069 @%%@CR:C6A00020070 @%                             Changes current working directory
  1658.  
  1659. %@AB@%_chdrive%@AE@%                          Changes current drive
  1660.  
  1661. %@AB@%getcwd%@AE@%%@CR:C6A00020071 @%%@CR:C6A00020072 @%                            Gets current working directory
  1662.  
  1663. %@AB@%_getdcwd%@AE@%                          Gets current working directory for the 
  1664.                                   specified drive
  1665.  
  1666. %@AB@%_getdrive%@AE@%                         Gets the current disk drive
  1667.  
  1668. %@AB@%mkdir%@AE@%%@CR:C6A00020073 @%%@CR:C6A00020074 @%                             Makes a new directory
  1669.  
  1670. %@AB@%rmdir%@AE@%%@CR:C6A00020075 @%%@CR:C6A00020076 @%                             Removes a directory
  1671.  
  1672. %@AB@%_searchenv%@AE@%                        Searches for a given file on specified 
  1673.                                   paths
  1674.  
  1675. %@NL@%
  1676. %@2@%%@CR:C6A00020077 @%%@AB@%2.5  File Handling%@AE@%%@EH@%%@NL@%
  1677. %@NL@%
  1678. The file-handling routines let you create, manipulate, and delete files.
  1679. They also set and check file-access permissions.  %@NL@%
  1680. %@NL@%
  1681. File-handling routines work on a file designated by a path name or by a
  1682. "file handle," an integer assigned by the operating system that identifies
  1683. an open file. These routines modify or give information about the designated
  1684. file. Most of them are declared in the include file IO.H, with the
  1685. exceptions being the %@AB@%fstat%@AE@% and %@AB@%stat%@AE@% functions (declared in SYS\STAT.H), the
  1686. %@AB@%_fullpath%@AE@% routine (declared in DIRECT.H), and the %@AB@%remove%@AE@% and %@AB@%rename%@AE@%
  1687. functions (also declared in STDIO.H).%@CR:C6A00020078 @%%@CR:C6A00020079 @%%@CR:C6A00020080 @%%@CR:C6A00020081 @%  %@NL@%
  1688. %@NL@%
  1689. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1690. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1691. %@AB@%access%@AE@%%@CR:C6A00020082 @%                            Checks file-permission setting
  1692.  
  1693. %@AB@%chmod%@AE@%%@CR:C6A00020083 @%%@CR:C6A00020084 @%                             Changes file-permission setting
  1694.  
  1695. %@AB@%chsize%@AE@% %@CR:C6A00020085 @%%@CR:C6A00020086 @%                           Changes file size
  1696.  
  1697. %@AB@%filelength%@AE@%%@CR:C6A00020087 @%%@CR:C6A00020088 @%                        Gets file length
  1698.  
  1699. %@AB@%fstat%@AE@%%@CR:C6A00020089 @%%@CR:C6A00020090 @%                             Gets file-status information on handle
  1700.  
  1701. %@AB@%_fullpath%@AE@%                         Makes an absolute path name from a 
  1702.                                   relative path name
  1703.  
  1704. %@AB@%isatty%@AE@% %@CR:C6A00020091 @%%@CR:C6A00020092 @%                           Checks for character device
  1705.  
  1706. %@AB@%locking%@AE@%%@CR:C6A00020093 @%%@CR:C6A00020094 @%                           Locks areas of file (available with OS/2
  1707.                                   and
  1708.                                   DOS versions 3.0 and later)
  1709.  
  1710. %@AB@%_makepath%@AE@%                         Merges path-name components into a 
  1711.                                   single, full path name
  1712.  
  1713. %@AB@%mktemp%@AE@%%@CR:C6A00020095 @%%@CR:C6A00020096 @%                            Creates unique file name
  1714.  
  1715. %@AB@%remove%@AE@%%@CR:C6A00020097 @%%@CR:C6A00020098 @%                            Deletes file
  1716.  
  1717. %@AB@%rename%@AE@%%@CR:C6A00020099 @%%@CR:C6A00020100 @%                            Renames file
  1718.  
  1719. %@AB@%setmode%@AE@%%@CR:C6A00020101 @%%@CR:C6A00020102 @%                           Sets file-translation mode
  1720.  
  1721. %@AB@%_splitpath%@AE@%                        Splits a path name into component pieces
  1722.  
  1723. %@AB@%stat%@AE@%%@CR:C6A00020103 @%%@CR:C6A00020104 @%                              Gets file-status information on named 
  1724.                                   file
  1725.  
  1726. %@AB@%umask%@AE@%%@CR:C6A00020105 @%%@CR:C6A00020106 @%                             Sets default-permission mask
  1727.  
  1728. %@AB@%unlink%@AE@%%@CR:C6A00020107 @%%@CR:C6A00020108 @%                            Deletes file
  1729.  
  1730. The %@AB@%access%@AE@%, %@AB@%chmod%@AE@%, %@AB@%_fullpath%@AE@%, %@AB@%_makepath%@AE@%, %@AB@%remove%@AE@%, %@AB@%rename%@AE@%, %@AB@%_splitpath%@AE@%, %@AB@%stat%@AE@%,
  1731. and %@AB@%unlink%@AE@% routines operate on files specified by a path name or file name.%@CR:C6A00020109 @%
  1732. %@NL@%
  1733. %@NL@%
  1734. The %@AB@%chsize%@AE@%, %@AB@%filelength%@AE@%, %@AB@%fstat%@AE@%,%@AB@% isatty%@AE@%, %@AB@%locking%@AE@%, and %@AB@%setmode%@AE@% routines work
  1735. with files designated by a file handle.  %@NL@%
  1736. %@NL@%
  1737. The %@AB@%mktemp%@AE@% and %@AB@%umask%@AE@% routines have functions that are slightly different
  1738. from the other routines. The %@AB@%mktemp%@AE@% routine creates a unique file name, and
  1739. the programmer can use %@AB@%mktemp%@AE@% to create unique file names that do not
  1740. conflict with the names of existing files. The %@AB@%umask%@AE@% routine sets the
  1741. default permission mask for any new files created in a program. The mask can
  1742. override the permission setting given in the %@AB@%open%@AE@% or %@AB@%creat%@AE@% call for the new
  1743. file.  %@NL@%
  1744. %@NL@%
  1745. %@NL@%
  1746. %@2@%%@CR:C6A00020110 @%%@AB@%2.6  Graphics%@AE@%%@EH@%%@NL@%
  1747. %@NL@%
  1748. Microsoft C graphics routines offer a wide variety of graphics functions,
  1749. low-level graphics primitives, font functions, and presentation graphics
  1750. (displays such as graphs and pie charts).  %@NL@%
  1751. %@NL@%
  1752. Graphics functions are supplied in two libraries that must be explicitly
  1753. linked with your program. The GRAPHICS.LIB library provides support for
  1754. low-level graphics and character-font routines. The library PGCHART.LIB
  1755. supports presentation-graphics routines.  %@NL@%
  1756. %@NL@%
  1757. %@NL@%
  1758. %@3@%%@CR:C6A00020111 @%%@AB@%2.6.1  Low-Level Graphics and Character-Font Functions%@AE@%%@EH@%%@NL@%
  1759. %@NL@%
  1760. The low-level graphics and font functions are declared in the include file
  1761. GRAPH.H.  %@NL@%
  1762. %@NL@%
  1763. The library can be divided into the eight categories listed below, which
  1764. correspond to the different tasks involved in creating and manipulating
  1765. graphic objects.  %@NL@%
  1766. %@NL@%
  1767. Most graphics routines work only in DOS. Two categories of routines
  1768. ("configuring mode and environment" and "creating text output") work in OS/2
  1769. as well as DOS.  %@NL@%
  1770. %@NL@%
  1771. %@AB@%Category%@AE@%                          %@AB@%Task%@AE@%
  1772. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1773. Configuring mode and environment  Select the proper display mode for the 
  1774. (OS/2 and DOS)                    hardware and establish memory areas for 
  1775.                                   writing and displaying of images
  1776.  
  1777. Setting coordinates               Specify the logical origin and the 
  1778.                                   active display area within the screen
  1779.  
  1780. Setting low-level graphics        Specify a palette mapping for low-level 
  1781. palettes                          graphics routines
  1782.  
  1783. Setting attributes                Specify background and foreground 
  1784.                                   colors, fill masks, and line styles for 
  1785.                                   low-level graphics routines
  1786.  
  1787. Creating graphics                 Draw and fill figures
  1788. output                            
  1789.  
  1790. Creating text output (OS/2 and    Write text on the screen
  1791. DOS)                              
  1792.  
  1793. Transferring images               Store images in memory and retrieve them
  1794.  
  1795. Displaying fonts                  Display text in character fonts 
  1796.                                   compatible with Microsoft Windows(tm) %@CR:C6A00020112 @%
  1797.  
  1798. The following sections explain each of these categories.  %@NL@%
  1799. %@NL@%
  1800. %@NL@%
  1801. %@4@%%@AB@%2.6.1.1  Configuring Mode and Environment%@CR:C6A00020113 @% %@CR:C6A00020114 @%%@AE@%%@EH@%%@NL@%
  1802. %@NL@%
  1803. Routines that configure the mode and environment establish the graphics or
  1804. text mode of operation, determine the current graphics environment, and
  1805. control the display of the cursor.%@CR:C6A00020115 @%%@CR:C6A00020116 @%%@CR:C6A00020117 @%%@CR:C6A00020118 @%  %@NL@%
  1806. %@NL@%
  1807. All of the routines listed in this section are available in OS/2 as well as
  1808. DOS.%@CR:C6A00020119 @%%@CR:C6A00020120 @%  %@NL@%
  1809. %@NL@%
  1810. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1811. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1812. %@AB@%_clearscreen%@AE@%                      Erases the screen and fills it with the 
  1813.                                   current background color
  1814.  
  1815. %@AB@%_getactivepage%@AE@%                    Gets the current active page number
  1816.  
  1817. %@AB@%_getbkcolor%@AE@%                       Returns the current background color
  1818.  
  1819. %@AB@%_getvideoconfig%@AE@%                   Obtains status of current graphics 
  1820.                                   environment
  1821.  
  1822. %@AB@%_getvisualpage%@AE@%                    Gets the current visual page number
  1823.  
  1824. %@AB@%_grstatus%@AE@%                         Returns the status of the most recent 
  1825.                                   graphics function call
  1826.  
  1827. %@AB@%_setactivepage%@AE@%                    Sets memory area for the active page for
  1828.                                   writing
  1829.                                   images
  1830.  
  1831. %@AB@%_setbkcolor%@AE@%                       Sets the current background color
  1832.  
  1833. %@AB@%_settextrows%@AE@%                      Sets the number of text rows
  1834.  
  1835. %@AB@%_setvideomode%@AE@%                     Selects an operating mode for the 
  1836.                                   display screen
  1837.  
  1838. %@AB@%_setvideomoderows%@AE@%                 Sets the video mode and the number of 
  1839.                                   rows for text operations
  1840.  
  1841. %@AB@%_setvisualpage%@AE@%                    Sets memory area for the current visual 
  1842.                                   page
  1843.  
  1844. %@NL@%
  1845. %@4@%%@AB@%2.6.1.2  Setting Coordinates%@CR:C6A00020121 @%%@CR:C6A00020122 @%%@CR:C6A00020123 @%%@AE@%%@EH@%%@NL@%
  1846. %@NL@%
  1847. The "set coordinates" routines set the current text or graphics position and
  1848. convert pixel coordinates between the various graphic coordinate systems.%@CR:C6A00020124 @%%@CR:C6A00020125 @%%@CR:C6A00020126 @%%@CR:C6A00020127 @%%@CR:C6A00020128 @%  %@NL@%
  1849. %@NL@%
  1850. The Microsoft C graphics functions recognize three sets of coordinates:%@CR:C6A00020129 @%%@CR:C6A00020130 @%%@CR:C6A00020131 @%%@CR:C6A00020132 @%%@CR:C6A00020133 @%  %@NL@%
  1851. %@NL@%
  1852. %@NL@%
  1853.   1.  Fixed physical coordinates%@NL@%
  1854. %@NL@%
  1855.   2.  View coordinates defined by the application%@NL@%
  1856. %@NL@%
  1857.   3.  Window coordinates that can include floating-point values%@NL@%
  1858. %@NL@%
  1859. %@NL@%
  1860. The functions in this category establish window and view coordinate systems
  1861. and translate between physical, view, and window coordinate systems.  %@NL@%
  1862. %@NL@%
  1863. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1864. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1865. %@AB@%_getcurrentposition%@AE@%               Determines current position in view 
  1866.                                   coordinates
  1867.  
  1868. %@AB@%_getcurrentposition_w%@AE@%             Determines current position in window 
  1869.                                   coordinates
  1870.  
  1871. %@AB@%_getphyscoord%@AE@%                     Converts view coordinates to physical 
  1872.                                   coordinates
  1873.  
  1874. %@AB@%_getviewcoord%@AE@%                     Converts physical coordinates to view 
  1875.                                   coordinates
  1876.  
  1877. %@AB@%_getviewcoord_w%@AE@%                   Converts window coordinates to view 
  1878.                                   coordinates
  1879.  
  1880. %@AB@%_getviewcoord_wxy%@AE@%                 Converts window coordinates in %@AB@%_wxycoord%@AE@%
  1881.                                   structure to view coordinates
  1882.  
  1883. %@AB@%_getwindowcoord%@AE@%                   Converts view coordinates to window 
  1884.                                   coordinates
  1885.  
  1886. %@AB@%_setcliprgn%@AE@%                       Limits graphic output to a region of the
  1887.                                   screen
  1888.  
  1889. %@AB@%_setvieworg%@AE@%                       Positions the view-coordinate origin
  1890.  
  1891. %@AB@%_setviewport%@AE@%                      Limits graphics output to a region of 
  1892.                                   the screen and positions the 
  1893.                                   view-coordinate origin to the upper-left
  1894.                                   corner of that region
  1895.  
  1896. %@AB@%_setwindow%@AE@%                        Defines a floating-point window 
  1897.                                   coordinate system
  1898.  
  1899. The default view coordinate system is identical to the physical screen
  1900. coordinate system. The physical origin (0, 0) is always in the upper-left
  1901. corner of the display. The %@AI@%x%@AE@% axis extends in the positive direction left to
  1902. right, while the %@AI@%y%@AE@% axis extends in the positive direction top to bottom.  %@NL@%
  1903. %@NL@%
  1904. The physical horizontal and vertical dimensions depend on the hardware
  1905. display configuration and the selected mode. These values are accessible at
  1906. run time by examining the %@AB@%numxpixels%@AE@% and %@AB@%numypixels%@AE@% fields of the
  1907. %@AB@%videoconfig%@AE@% structure returned by %@AB@%_getvideoconfig%@AE@%. (The %@AB@%_getvideoconfig%@AE@%
  1908. routine is listed in the previous section.)  %@NL@%
  1909. %@NL@%
  1910. The %@AB@%_setvieworg%@AE@% function allows you to move the viewport origin to a new
  1911. position relative to the physical screen.  %@NL@%
  1912. %@NL@%
  1913. Routines that refer to coordinates on the physical screen or viewport
  1914. require integer values. However, in real-world graphing applications, you
  1915. might wish to use floating-point values, such as stock prices or average
  1916. rainfall. The window coordinate system allows you to display graphics using
  1917. floating-point values instead of integers.  %@NL@%
  1918. %@NL@%
  1919. The %@AB@%_getcurrentposition%@AE@% and %@AB@%_getcurrentposition_w%@AE@% routines allow you to
  1920. determine the location of the current graphics-output point.  %@NL@%
  1921. %@NL@%
  1922. The %@AB@%_setcliprgn%@AE@% function defines a restricted active display area on the
  1923. screen. The %@AB@%_setviewport%@AE@% function does the same thing and also resets the
  1924. viewport origin to the upper-left corner of the restricted active display
  1925. area.  %@NL@%
  1926. %@NL@%
  1927. The physical coordinates of any view-coordinate point can be determined with
  1928. the %@AB@%_getphyscoord%@AE@% function, and the view coordinates of any physical point
  1929. can be determined with the %@AB@%_getviewcoord%@AE@% function.  %@NL@%
  1930. %@NL@%
  1931. The view coordinates of any window coordinate can be determined with the
  1932. %@AB@%_getviewcoord_w%@AE@% and %@AB@%_getviewcoord_wxy%@AE@% functions. The window coordinates of
  1933. any view coordinate can be determined with the %@AB@%_getwindowcoord%@AE@% function.  %@NL@%
  1934. %@NL@%
  1935. The %@AB@%_setwindow%@AE@% function defines the current viewport as a real-coordinate
  1936. window bound by the specified floating-point values.  %@NL@%
  1937. %@NL@%
  1938. %@NL@%
  1939. %@4@%%@AB@%2.6.1.3  Setting Low-Level Graphics Palettes%@CR:C6A00020134 @%%@CR:C6A00020135 @%%@AE@%%@EH@%%@NL@%
  1940. %@NL@%
  1941. Use the low-level palette routines to select or remap color palettes.%@CR:C6A00020136 @%%@CR:C6A00020137 @%%@CR:C6A00020138 @%%@CR:C6A00020139 @%  %@NL@%
  1942. %@NL@%
  1943. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1944. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1945. %@AB@%_remapallpalette%@AE@%%@CR:C6A00020140 @%                  Changes all color indexes in the current
  1946.                                   palette
  1947.  
  1948. %@AB@%_remappalette%@AE@%                     Changes a single color index in the 
  1949.                                   current palette
  1950.  
  1951. %@AB@%_selectpalette%@AE@%                    Selects a predefined palette
  1952.  
  1953. Some video modes support a "color palette," which is a table of the color
  1954. values that can be displayed together on the screen at any given time. A
  1955. "color value" is a %@AB@%long%@AE@% integer representing a color that can be displayed
  1956. on your system.  %@NL@%
  1957. %@NL@%
  1958. In CGA color graphics modes, you can use the %@AB@%_selectpalette%@AE@% routine to
  1959. choose one of several predefined palettes.  %@NL@%
  1960. %@NL@%
  1961. On EGA and VGA video systems, you can "remap" (change) the palette using the
  1962. %@AB@%_remappalette%@AE@% or %@AB@%_remapallpalette%@AE@% routines. For instance, the EGA %@AB@%_ERESCOLOR%@AE@%
  1963. mode offers a total of 64 color values, of which 16 can be displayed at a
  1964. time. In this mode, the palette contains 16 "color indices," or slots to
  1965. which you can assign color values.  %@NL@%
  1966. %@NL@%
  1967. The %@AB@%_remappalette%@AE@% routine changes a single color index to a specified color
  1968. value. The %@AB@%_remapallpalette%@AE@% routine changes all of the available palette
  1969. entries simultaneously.  %@NL@%
  1970. %@NL@%
  1971. %@NL@%
  1972. %@4@%%@AB@%2.6.1.4  Setting Attributes%@CR:C6A00020141 @%%@CR:C6A00020142 @% %@CR:C6A00020143 @%%@CR:C6A00020144 @%%@CR:C6A00020145 @% %@CR:C6A00020146 @%%@AE@%%@EH@%%@NL@%
  1973. %@NL@%
  1974. The low-level output functions that draw lines, arcs, ellipses, and other
  1975. basic figures do not specify color or line-style information. Instead, the
  1976. low-level graphics functions rely on a set of attributes that are set
  1977. independently by the following functions:%@CR:C6A00020147 @%%@CR:C6A00020148 @%%@CR:C6A00020149 @%  %@NL@%
  1978. %@NL@%
  1979. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  1980. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  1981. %@AB@%_getarcinfo%@AE@%%@CR:C6A00020150 @%%@CR:C6A00020151 @%%@CR:C6A00020152 @%%@CR:C6A00020153 @%                       Determines the endpoints in viewport 
  1982.                                   coordinates of the most recently drawn 
  1983.                                   arc or pie
  1984.  
  1985. %@AB@%_getcolor%@AE@%                         Gets the current color
  1986.  
  1987. %@AB@%_getfillmask%@AE@%                      Gets the current fill mask
  1988.  
  1989. %@AB@%_getlinestyle%@AE@%                     Gets the current line-style mask
  1990.  
  1991. %@AB@%_getwritemode%@AE@%                     Gets the current logical write mode
  1992.  
  1993. %@AB@%_setcolor%@AE@%                         Sets the current color
  1994.  
  1995. %@AB@%_setfillmask%@AE@%                      Sets the current fill mask
  1996.  
  1997. %@AB@%_setlinestyle%@AE@%                     Sets the current line-style mask
  1998.  
  1999. %@AB@%_setwritemode%@AE@%                     Sets logical write mode for line drawing
  2000.  
  2001. The %@AB@%_getcolor%@AE@% and %@AB@%_setcolor%@AE@% functions get or set the current color index for
  2002. graphics and font output. The %@AB@%_getbkcolor%@AE@% and %@AB@%_setbkcolor%@AE@% functions get or
  2003. set the current background color.  %@NL@%
  2004. %@NL@%
  2005. The %@AB@%_getfillmask%@AE@% and %@AB@%_setfillmask%@AE@% functions get or set the current fill
  2006. mask. The mask is an 8-by-8-bit template array, with each bit representing a
  2007. pixel. If a bit is 0, the pixel in memory is left untouched, as the mask is
  2008. transparent to that pixel. If a bit is 1, the pixel is assigned the current
  2009. color value. The template is repeated as necessary over the entire fill
  2010. area.  %@NL@%
  2011. %@NL@%
  2012. The %@AB@%_getlinestyle%@AE@% and %@AB@%_setlinestyle%@AE@% functions get or set the current line
  2013. style. The line style is determined by a 16-bit template buffer with each
  2014. bit corresponding to a pixel. If a bit is 1, the pixel is set to the current
  2015. color. If a bit is 0, the pixel is not changed. The template is repeated for
  2016. the length of the line.  %@NL@%
  2017. %@NL@%
  2018. The %@AB@%_getwritemode%@AE@% and %@AB@%_setwritemode%@AE@% functions get or set the logical write
  2019. mode for straight line drawing. The default mode, %@AB@%_GPSET%@AE@%, causes lines to be
  2020. drawn in the current graphics color. Other modes combine the current
  2021. graphics color and the original screen image using various logical
  2022. operations.  %@NL@%
  2023. %@NL@%
  2024. %@NL@%
  2025. %@4@%%@AB@%2.6.1.5  Creating Graphics Output%@AE@%%@EH@%%@NL@%
  2026. %@NL@%
  2027. The graphics output functions use a set of specified coordinates and draw
  2028. various figures. They use the current or default attributes for line-style
  2029. mask, fill mask, write mode, background color, and foreground color.%@CR:C6A00020154 @%%@CR:C6A00020155 @%  %@NL@%
  2030. %@NL@%
  2031. The name of each function announces its task or the figure it draws, as the
  2032. following list indicates:%@CR:C6A00020156 @%  %@NL@%
  2033. %@NL@%
  2034. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2035. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2036. %@AB@%_arc%@AE@%,  %@AB@%_arc_w%@AE@%,  %@AB@%_arc_wxy%@AE@%%@CR:C6A00020157 @%%@CR:C6A00020158 @%          Draw an arc
  2037.  
  2038. %@AB@%_ellipse%@AE@%,  %@AB@%_ellipse_w%@AE@%,%@AB@%%@AE@%            Draw an ellipse or circle
  2039. %@AB@%_ellipse_wxy%@AE@%                      
  2040.  
  2041. %@AB@%_floodfill%@AE@%,  %@AB@%_floodfill_w%@AE@%%@CR:C6A00020159 @%         Flood-fill an area of the screen with 
  2042.                                   the current color
  2043.  
  2044. %@AB@%_getcurrentposition%@AE@%, %@AB@%%@AE@%             Obtain the current graphic-output 
  2045. %@AB@%_getcurrentposition_w%@AE@%%@CR:C6A00020160 @%             position used by %@AB@%_lineto%@AE@% and %@AB@%_outgtext%@AE@%
  2046.  
  2047. %@AB@%_getpixel%@AE@%, %@AB@%_getpixel_w%@AE@%%@CR:C6A00020161 @%            Obtain a pixel's color
  2048.  
  2049. %@AB@%_lineto%@AE@%,  %@AB@%_lineto_w%@AE@%%@CR:C6A00020162 @% %@CR:C6A00020163 @%%@CR:C6A00020164 @%              Draw a line from the current graphic 
  2050.                                   output position to a specified point
  2051.  
  2052. %@AB@%_moveto%@AE@%,  %@AB@%_moveto_w%@AE@%%@CR:C6A00020165 @% %@CR:C6A00020166 @%              Move the current graphic-output position
  2053.                                   to a specified point
  2054.  
  2055. %@AB@%_pie%@AE@%,  %@AB@%_pie_w%@AE@%,  %@AB@%_pie_wxy%@AE@%%@CR:C6A00020167 @%%@CR:C6A00020168 @%          Draw a pie-slice-shaped figure
  2056.  
  2057. %@AB@%_polygon%@AE@%,  %@AB@%_polygon_w%@AE@%, %@AB@%%@AE@%           Draw or scan-fill a polygon
  2058. %@AB@%_polygon_wxy%@AE@%                      
  2059.  
  2060. %@AB@%_rectangle%@AE@%,  %@AB@%_rectangle_w%@AE@%, %@AB@%%@AE@%       Draw or scan-fill a rectangle
  2061. %@AB@%_rectangle_wxy%@AE@%%@CR:C6A00020169 @%%@CR:C6A00020170 @%                    
  2062.  
  2063. %@AB@%_setpixel%@AE@%,  %@AB@%_setpixel_w%@AE@%%@CR:C6A00020171 @%           Set a pixel's color
  2064.  
  2065. Most of these routines are available in several forms, which are indicated
  2066. by their names. Output functions without a suffix use the view coordinate
  2067. system. Functions that end with %@AB@%_w%@AE@% take %@AB@%double%@AE@% values as arguments and use
  2068. the window coordinate system. Functions that end with %@AB@%_wxy%@AE@% use %@AB@%_wxycoord%@AE@%
  2069. structures to define the coordinates and use the window coordinate system.  %@NL@%
  2070. %@NL@%
  2071. Circular figures, such as arcs and ellipses, are centered within a "bounding
  2072. rectangle" specified by two points that define the diagonally opposed
  2073. corners of the rectangle. The center of the rectangle becomes the center of
  2074. the figure, and the rectangle's borders determine the size of the figure.  %@NL@%
  2075. %@NL@%
  2076. %@NL@%
  2077. %@4@%%@AB@%2.6.1.6  Creating Text Output%@AE@%%@EH@%%@NL@%
  2078. %@NL@%
  2079. The next group of routines provides text output in both graphics and text
  2080. modes. Unlike the standard console I/O library routines, these functions
  2081. recognize text-window boundaries and use the current text color.%@CR:C6A00020172 @%%@CR:C6A00020173 @%%@CR:C6A00020174 @%%@CR:C6A00020175 @%%@CR:C6A00020176 @%%@CR:C6A00020177 @%%@CR:C6A00020178 @%%@CR:C6A00020179 @%  %@NL@%
  2082. %@NL@%
  2083. All of the routines listed in this section work in OS/2 as well as DOS.  %@NL@%
  2084. %@NL@%
  2085. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2086. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2087. %@AB@%_displaycursor%@AE@%                    Sets the cursor on or off upon exit from
  2088.                                   a graphics routine
  2089.  
  2090. %@AB@%_gettextcolor%@AE@%                     Obtains the current text color
  2091.  
  2092. %@AB@%_gettextcursor%@AE@%                    Returns the current cursor attribute 
  2093.                                   (text modes only)
  2094.  
  2095. %@AB@%_gettextposition%@AE@%                  Obtains the current text-output position
  2096.  
  2097. %@AB@%_gettextwindow%@AE@%                    Gets the current text window boundaries
  2098.  
  2099. %@AB@%_outmem%@AE@%                           Prints text of a specified length from a
  2100.                                   memory
  2101.                                   buffer
  2102.  
  2103. %@AB@%_outtext%@AE@%                          Outputs a text string to the screen at 
  2104.                                   the current text position
  2105.  
  2106. %@AB@%_scrolltextwindow%@AE@%                 Scrolls the current text window up or 
  2107.                                   down
  2108.  
  2109. %@AB@%_settextcolor%@AE@%                     Sets the current text color
  2110.  
  2111. %@AB@%_settextcursor%@AE@%                    Sets the current cursor attribute (text 
  2112.                                   modes only)
  2113.  
  2114. %@AB@%_settextposition%@AE@%                  Relocates the current text position
  2115.  
  2116. %@AB@%_settextwindow%@AE@%                    Defines the current text-display window
  2117.  
  2118. %@AB@%_wrapon%@AE@%                           Enables or disables line wrap
  2119.  
  2120. The %@AB@%_outtext%@AE@% and %@AB@%_outmem%@AE@% routines provide no formatting. If you want to
  2121. output integer or floating-point values, you must convert the values into a
  2122. string variable (using the %@AB@%sprintf%@AE@% function) before calling these routines.
  2123. %@NL@%
  2124. %@NL@%
  2125. The %@AB@%_outtext%@AE@% routine recognizes the %@AB@%\n%@AE@% (newline character) and %@AB@%\r%@AE@% (carriage
  2126. return) sequences. The %@AB@%_outmem%@AE@% routine treats these sequences as printable
  2127. graphics characters.  %@NL@%
  2128. %@NL@%
  2129. %@NL@%
  2130. %@4@%%@AB@%2.6.1.7  Transferring Images%@AE@%%@EH@%%@NL@%
  2131. %@NL@%
  2132. The functions in this category transfer screen images between memory and the
  2133. display, using a buffer allocated by the application, or determine the size
  2134. in bytes of the buffer needed to store a given image.%@CR:C6A00020180 @%%@CR:C6A00020181 @%%@CR:C6A00020182 @%  %@NL@%
  2135. %@NL@%
  2136. The functions that end with %@AB@%_w%@AE@% or %@AB@%_wxy%@AE@% use window coordinates; the other
  2137. functions in this set use view coordinates.%@CR:C6A00020183 @%%@CR:C6A00020184 @%%@CR:C6A00020185 @%%@CR:C6A00020186 @%  %@NL@%
  2138. %@NL@%
  2139. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2140. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2141. %@AB@%_getimage%@AE@%,%@AB@%%@AE@%                        Store a screen image in memory
  2142. %@AB@%_getimage_w%@AE@%,%@AB@%%@AE@%                      
  2143. %@AB@%_getimage_wxy%@AE@%                     
  2144.  
  2145. %@AB@%_imagesize%@AE@%,%@AB@%%@AE@%                       Return the size (in bytes) of the buffer
  2146. %@AB@%_imagesize_w%@AE@%,%@AB@%%@AE@%                     needed to store the image
  2147. %@AB@%_imagesize_wxy%@AE@%                    
  2148.  
  2149. %@AB@%_putimage%@AE@%,%@AB@%%@AE@%                        Retrieve an image from memory and 
  2150. %@AB@%_putimage_w%@AE@%                       display it
  2151.  
  2152. In some cases, the buffer needed to store an image with the %@AB@%_getimage%@AE@%
  2153. functions must be larger than 64K (65,535) bytes. Use the %@AB@%halloc%@AE@% routine to
  2154. allocate a buffer larger than 64K.  %@NL@%
  2155. %@NL@%
  2156. %@NL@%
  2157. %@4@%%@AB@%2.6.1.8  Displaying Fonts%@AE@%%@EH@%%@NL@%
  2158. %@NL@%
  2159. The functions listed in this section control the display of font-based
  2160. characters on the screen.%@CR:C6A00020187 @%%@CR:C6A00020188 @%%@CR:C6A00020189 @%%@CR:C6A00020190 @%%@CR:C6A00020191 @%  %@NL@%
  2161. %@NL@%
  2162. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2163. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2164. %@AB@%_getfontinfo%@AE@%                      Obtains the current font characteristics
  2165.  
  2166. %@AB@%_getgtextextent%@AE@%                   Determines the width in pixels of 
  2167.                                   specified text in the current font
  2168.  
  2169. %@AB@%_getgtextvector%@AE@%                   Gets orientation of font text output
  2170.  
  2171. %@AB@%_outgtext%@AE@%                         Outputs text in the current font to the 
  2172.                                   screen at the specified pixel position
  2173.  
  2174. %@AB@%_registerfonts%@AE@%                    Initializes font library
  2175.  
  2176. %@AB@%_setfont%@AE@%                          Finds a single font that matches a 
  2177.                                   specified set of characteristics and 
  2178.                                   makes this font the current font for use
  2179.                                   by the %@AB@%_outgtext%@AE@% function
  2180.  
  2181. %@AB@%_setgtextvector%@AE@%                   Sets the current orientation for font 
  2182.                                   text output
  2183.  
  2184. %@AB@%_unregisterfonts%@AE@%                  Frees memory allocated by %@AB@%_registerfonts%@AE@%
  2185.  
  2186. %@NL@%
  2187. %@3@%%@CR:C6A00020192 @%%@AB@%2.6.2  Presentation-Graphics Functions%@AE@%%@EH@%%@NL@%
  2188. %@NL@%
  2189. The presentation-graphics functions are declared in the PGCHART.H include
  2190. file. The library can be divided into the three categories listed below,
  2191. corresponding to the different tasks involved in creating and manipulating
  2192. graphic objects:%@CR:C6A00020193 @%  %@NL@%
  2193. %@NL@%
  2194. %@AB@%Category%@AE@%                          %@AB@%Task%@AE@%
  2195. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2196. Displaying presentation graphics  Initialize video structures for 
  2197.                                   presentation graphics and establishes 
  2198.                                   the default chart type. Display
  2199.                                   presentation-graphics chart: bar, 
  2200.                                   column, pie, scatter, or line chart.
  2201.  
  2202. Analyzing                         Analyze data (does not display chart).
  2203. presentation-graphics data        
  2204.  
  2205. Manipulating                      Modify basic chart structures (e.g., 
  2206. presentation-graphics structures  palettes, cross-hatching styles). 
  2207.  
  2208. %@NL@%
  2209. %@4@%%@AB@%2.6.2.1  Displaying Presentation Graphics%@CR:C6A00020194 @% %@CR:C6A00020195 @%%@AE@%%@EH@%%@NL@%
  2210. %@NL@%
  2211. The functions listed in this section initialize the presentation-graphics
  2212. library and display the specified graph type.%@CR:C6A00020196 @%%@CR:C6A00020197 @%%@CR:C6A00020198 @%%@CR:C6A00020199 @%  %@NL@%
  2213. %@NL@%
  2214. Because the %@AB@%_pg_initchart%@AE@% routine initializes the presentation-graphics
  2215. library, it must be called before any other function in the
  2216. presentation-graphics library. The %@AB@%_pg_defaultchart%@AE@% function initializes the
  2217. variables in the chart environment.%@CR:C6A00020200 @%%@CR:C6A00020201 @%%@CR:C6A00020202 @%  %@NL@%
  2218. %@NL@%
  2219. The other routines in this category display the specified graph. The
  2220. single-series versions plot one set of data, and the multiseries versions
  2221. (those ending with an %@AB@%ms%@AE@% suffix) plot several sets of data in the same chart
  2222. style.  %@NL@%
  2223. %@NL@%
  2224. Presentation-graphics programs can display text in different font sizes by
  2225. taking advantage of font-based characters (see Section 2.6.1.8, "Displaying
  2226. Fonts.") Call the %@AB@%_registerfonts%@AE@% and %@AB@%_setfont%@AE@% routines to select a font
  2227. before calling the %@AB@%_pginitchart%@AE@% routine. Subsequent charts use the selected
  2228. font. You can later call the %@AB@%_unregisterfonts%@AE@% routine to restore the default
  2229. character font and free the memory previously allocated for fonts.  %@NL@%
  2230. %@NL@%
  2231. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2232. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2233. %@AB@%_pg_chart%@AE@%                         Displays a single-series bar, column, or
  2234.                                   line chart
  2235.  
  2236. %@AB@%_pg_chartms%@AE@%                       Displays a multiseries bar, column, or 
  2237.                                   line chart
  2238.  
  2239. %@AB@%_pg_chartpie%@AE@%                      Displays a pie chart
  2240.  
  2241. %@AB@%_pg_chartscatter%@AE@%                  Displays a scatter diagram for a single 
  2242.                                   series of data
  2243.  
  2244. %@AB@%_pg_chartscatterms%@AE@%                Displays a scatter diagram for more than
  2245.                                   one series of data
  2246.  
  2247. %@AB@%_pg_defaultchart%@AE@%                  Initializes all necessary variables in 
  2248.                                   the chart environment for a specified 
  2249.                                   chart type
  2250.  
  2251. %@AB@%_pg_initchart%@AE@%                     Initializes the presentation-graphics 
  2252.                                   library
  2253.  
  2254. %@NL@%
  2255. %@4@%%@AB@%2.6.2.2  Analyzing Presentation-Graphics Charts%@CR:C6A00020203 @%%@CR:C6A00020204 @% %@CR:C6A00020205 @%%@AE@%%@EH@%%@NL@%
  2256. %@NL@%
  2257. These routines calculate default values for the specified graph type but do
  2258. not display the chart. The single-series versions analyze one set of data,
  2259. and the multiseries versions analyze several sets of data in the same chart
  2260. style.%@CR:C6A00020206 @%%@CR:C6A00020207 @%  %@NL@%
  2261. %@NL@%
  2262. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2263. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2264. %@AB@%_pg_analyzechart%@AE@%%@CR:C6A00020208 @%%@CR:C6A00020209 @%                  Analyzes a single series of data for a 
  2265.                                   bar, column, or line chart
  2266.  
  2267. %@AB@%_pg_analyzechartms%@AE@%                Analyzes a multiseries of data for a 
  2268.                                   bar, column, or line chart
  2269.  
  2270. %@AB@%_pg_analyzepie%@AE@%                    Analyzes data for a pie chart
  2271.  
  2272. %@AB@%_pg_analyzescatter%@AE@%                Analyzes a single series of data for a 
  2273.                                   scatter diagram
  2274.  
  2275. %@AB@%_pg_analyzescatterms%@AE@%              Analyzes a multiseries of data for a 
  2276.                                   scatter diagram 
  2277.  
  2278. %@NL@%
  2279. %@4@%%@AB@%2.6.2.3  Manipulating Presentation-Graphics Structures%@AE@%%@EH@%%@NL@%
  2280. %@NL@%
  2281. These functions control low-level aspects of the presentation-graphics
  2282. package.%@CR:C6A00020210 @%%@CR:C6A00020211 @%%@CR:C6A00020212 @%%@CR:C6A00020213 @%%@CR:C6A00020214 @%%@CR:C6A00020215 @%  %@NL@%
  2283. %@NL@%
  2284. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2285. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2286. %@AB@%_pg_hlabelchart%@AE@%%@CR:C6A00020216 @%%@CR:C6A00020217 @%%@CR:C6A00020218 @%%@CR:C6A00020219 @% %@CR:C6A00020220 @%%@CR:C6A00020221 @%                  Writes text horizontally on the screen%@CR:C6A00020222 @%%@CR:C6A00020223 @%%@CR:C6A00020224 @%%@CR:C6A00020225 @% 
  2287.  
  2288. %@AB@%_pg_vlabelchart%@AE@%                   Writes text vertically on the screen
  2289.  
  2290. %@AB@%_pg_getpalette%@AE@%                    Retrieves current colors, line styles, 
  2291.                                   fill patterns, and plot characters for 
  2292.                                   all presentation-graphics palettes
  2293.  
  2294. %@AB@%_pg_setpalette%@AE@%                    Sets current colors, line styles, fill 
  2295.                                   patterns, and plot characters for all 
  2296.                                   presentation-graphics palettes
  2297.  
  2298. %@AB@%_pg_resetpalette%@AE@%                  Sets current colors, line styles, fill 
  2299.                                   patterns, and plot characters to the 
  2300.                                   default values for the current screen 
  2301.                                   mode
  2302.  
  2303. %@AB@%_pg_getstyleset%@AE@%                   Retrieves the contents of the current 
  2304.                                   styleset
  2305.  
  2306. %@AB@%_pg_setstyleset%@AE@%                   Sets the contents of the current 
  2307.                                   styleset
  2308.  
  2309. %@AB@%_pg_resetstyleset%@AE@%                 Resets the contents of the current 
  2310.                                   styleset to the default value for the 
  2311.                                   current screen mode
  2312.  
  2313. %@AB@%_pg_getchardef%@AE@% %@CR:C6A00020226 @%                   Retrieves the current 8-by-8-pixel bit 
  2314.                                   map for a specified character
  2315.  
  2316. %@AB@%_pg_setchardef%@AE@% %@CR:C6A00020227 @%                   Sets the 8-by-8-pixel bit map for a 
  2317.                                   specified
  2318.                                   character
  2319.  
  2320. %@NL@%
  2321. %@2@%%@CR:C6A00020228 @%%@AB@%2.7  Input and Output%@AE@%%@EH@%%@NL@%
  2322. %@NL@%
  2323. The input and output (I/O) routines of the standard C library allow you to
  2324. read and write data to and from files and devices. In C, there are no
  2325. predefined file structures; all data items are treated as sequences of
  2326. bytes. The following three types of I/O functions are available:  %@NL@%
  2327. %@NL@%
  2328. %@NL@%
  2329.   1.  Stream%@NL@%
  2330. %@NL@%
  2331.   2.  Low-level%@NL@%
  2332. %@NL@%
  2333.   3.  Console and port%@NL@%
  2334. %@NL@%
  2335. %@NL@%
  2336. The "stream" I/O functions treat data as a stream of individual characters.
  2337. By choosing among the many stream functions available, you can process data
  2338. in different sizes and formats, from single characters to large data
  2339. structures. Stream I/O also provides buffering, which can significantly
  2340. improve performance.%@CR:C6A00020229 @%%@CR:C6A00020230 @%  %@NL@%
  2341. %@NL@%
  2342. The "low-level" I/O routines do not perform buffering and formatting.
  2343. Instead, they invoke the operating system's input and output capabilities
  2344. directly. These routines let you access files and peripheral devices at a
  2345. more basic level than the stream functions.%@CR:C6A00020231 @%  %@NL@%
  2346. %@NL@%
  2347. The "console and port" I/O routines allow you to read or write directly to a
  2348. console (keyboard and screen) or an I/O port (such as a printer port). The
  2349. port I/O routines simply read and write data in bytes. With console I/O
  2350. routines, some additional options are available, such as detecting whether a
  2351. character has been typed at the console. You can also choose between echoing
  2352. characters to the screen as they are read or reading characters without
  2353. echoing.%@CR:C6A00020232 @%  %@NL@%
  2354. %@NL@%
  2355. The C library also provides a number of direct DOS I/O system call routines.
  2356. These are described in Section 2.14, "System Calls."  %@NL@%
  2357. %@NL@%
  2358. File I/O operations can be performed in two modes: text or binary. The
  2359. following section describes these modes and their use.  %@NL@%
  2360. %@NL@%
  2361. ────────────────────────────────────────────────────────────────────────────%@NL@%
  2362. %@AU@%WARNING%@AE@%%@NL@%
  2363. %@NL@%
  2364. Because stream routines are buffered and low-level routines are not, the two
  2365. types of routines are generally incompatible. You should use either stream
  2366. or low-level routines consistently for processing a given file.%@NL@%
  2367. ────────────────────────────────────────────────────────────────────────────%@NL@%
  2368. %@NL@%
  2369. %@NL@%
  2370. %@3@%%@CR:C6A00020233 @%%@AB@%2.7.1  Text and Binary Modes%@AE@%%@EH@%%@NL@%
  2371. %@NL@%
  2372. Many C programs use data files for input and output. Under DOS and OS/2,
  2373. data files are normally processed in text mode. In this mode, each
  2374. carriage-return-line-feed (CR-LF) combination is translated into a single
  2375. line-feed character during input. During output, each line-feed character is
  2376. translated into a CR-LF combination.  %@NL@%
  2377. %@NL@%
  2378. Sometimes you may want to process a file without making those translations.
  2379. In these cases you use binary mode, which suppresses CR-LF translations.%@CR:C6A00020234 @%%@CR:C6A00020235 @%  %@NL@%
  2380. %@NL@%
  2381. You can control the file translation mode in the following ways:  %@NL@%
  2382. %@NL@%
  2383. %@NL@%
  2384.   ■   To process a few selected files in binary mode, while retaining the
  2385.       default text mode for most files, you can specify binary mode when you
  2386.       open the selected files. The %@AB@%fopen%@AE@% routine opens a file in binary mode
  2387.       when you specify the letter %@AB@%b%@AE@% in the access-mode string for the file.
  2388.       The %@AB@%open%@AE@% routine opens a file in binary mode when you specify the
  2389.       %@AB@%O_BINARY%@AE@% flag in the %@AI@%oflag%@AE@% argument. For more information about %@AB@%fopen%@AE@%
  2390.       and %@AB@%open%@AE@%, see the reference description of each routine.%@NL@%
  2391. %@NL@%
  2392.   ■   To process most or all files in binary mode, you can change the
  2393.       default mode to binary. The global variable %@AB@%_fmode%@AE@% controls the
  2394.       default translation mode, which is normally text. If you set %@AB@%_fmode%@AE@% to
  2395.       %@AB@%O_BINARY%@AE@%, the default mode is binary except for %@AB@%stdaux%@AE@% and %@AB@%stdprn%@AE@%,
  2396.       which are opened in binary mode by default.%@NL@%
  2397. %@NL@%
  2398. %@NL@%
  2399. You can change the value of %@AB@%_fmode%@AE@% in two ways:  %@NL@%
  2400. %@NL@%
  2401. %@NL@%
  2402.   1.  Link with the file BINMODE.OBJ (supplied with Microsoft C). This
  2403.       changes the initial setting of %@AB@%_fmode%@AE@% to the %@AB@%O_BINARY %@AE@%flag, causing
  2404.       all files except%@AB@% stdin%@AE@%, %@AB@%stdout%@AE@%, and %@AB@%stderr%@AE@% to be opened in binary
  2405.       mode.%@NL@%
  2406. %@NL@%
  2407.   2.  Change the value of %@AB@%_fmode%@AE@% directly by setting it to the %@AB@%O_BINARY%@AE@% flag
  2408.       in your program. This has the same effect as linking with BINMODE.OBJ.%@NL@%
  2409. %@NL@%
  2410. %@NL@%
  2411. You can still override the default mode (now binary) for a particular file
  2412. by opening it in text mode. Specify the letter %@AB@%t%@AE@% when using %@AB@%fopen%@AE@%, or
  2413. specify the %@AB@%O_TEXT%@AE@% flag when using %@AB@%open%@AE@%.  %@NL@%
  2414. %@NL@%
  2415. By default, the %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, and %@AB@%stderr%@AE@% files are opened in text mode, and
  2416. the %@AB@%stdaux%@AE@% and %@AB@%stdprn%@AE@% files are opened in binary mode. The %@AB@%setmode%@AE@% routine
  2417. allows you to change these defaults or change the mode of a file after it
  2418. has been opened. See the reference description of %@AB@%setmode%@AE@% for details.  %@NL@%
  2419. %@NL@%
  2420. %@NL@%
  2421. %@3@%%@CR:C6A00020236 @%%@AB@%2.7.2  Stream Routines%@AE@%%@EH@%%@NL@%
  2422. %@NL@%
  2423. Stream I/O functions handle data as a continuous stream of characters. To
  2424. use the stream functions, you must include the file STDIO.H in your program.
  2425. This file defines constants, types, and structures used in the stream
  2426. functions, and contains function declarations and macro definitions for the
  2427. stream  routines.%@CR:C6A00020237 @%%@CR:C6A00020238 @%%@CR:C6A00020239 @%%@CR:C6A00020240 @%%@CR:C6A00020241 @%  %@NL@%
  2428. %@NL@%
  2429. When a file is opened for I/O using the stream functions, the opened file is
  2430. associated with a structure of type %@AB@%FILE%@AE@% (defined in STDIO.H) containing
  2431. basic information about the file. A pointer to the %@AB@%FILE%@AE@% structure is
  2432. returned when the stream is opened. Subsequent operations use this pointer
  2433. (also called the "stream pointer," or just "stream") to refer to the file.%@CR:C6A00020242 @%%@CR:C6A00020243 @%  %@NL@%
  2434. %@NL@%
  2435. The stream functions provide for buffered, formatted, or unformatted input
  2436. and output. When a stream is buffered, data that is read from or written to
  2437. the stream is collected in an intermediate storage location called a
  2438. "buffer". In write operations, the output buffer's contents are written to
  2439. the appropriate final location when the buffer is full, the stream is
  2440. closed, or the program terminates normally. The buffer is said to be
  2441. "flushed" when this occurs. In read operations, a block of data is placed in
  2442. the input buffer read from the buffer; when the input buffer is empty, the
  2443. next block of data is transferred into the buffer.%@CR:C6A00020244 @%%@CR:C6A00020245 @%  %@NL@%
  2444. %@NL@%
  2445. Buffering produces efficient I/O because the system can transfer a large
  2446. block of data in a single operation rather than performing an I/O operation
  2447. each time a data item is read from or written to a stream. However, if a
  2448. program terminates abnormally, output buffers may not be flushed, resulting
  2449. in loss of data.  %@NL@%
  2450. %@NL@%
  2451. Some of the constants defined in STDIO.H may be useful in your program. The
  2452. manifest constant %@AB@%EOF%@AE@% is defined to be the value returned at end-of-file.
  2453. %@AB@%NULL%@AE@% is the null pointer. %@AB@%FILE%@AE@% is the structure that maintains information
  2454. about a stream. %@AB@%BUFSIZ%@AE@% defines the default size of stream buffers, in bytes.%@CR:C6A00020246 @%%@CR:C6A00020247 @%%@CR:C6A00020248 @%%@CR:C6A00020249 @%
  2455. %@NL@%
  2456. %@NL@%
  2457. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2458. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2459. %@AB@%clearerr%@AE@%                          Clears the error indicator for a stream %@CR:C6A00020250 @%
  2460.  
  2461. %@AB@%fclose%@AE@%                            Closes a stream %@CR:C6A00020251 @%
  2462.  
  2463. %@AB@%fcloseall%@AE@%                         Closes all open streams
  2464.  
  2465. %@AB@%fdopen%@AE@%                            Associates a stream with an open file 
  2466.                                   handle %@CR:C6A00020252 @%
  2467.  
  2468. %@AB@%feof%@AE@%                              Tests for end-of-file on a stream %@CR:C6A00020253 @%
  2469.  
  2470. %@AB@%ferror%@AE@%                            Tests for error on a stream %@CR:C6A00020254 @%
  2471.  
  2472. %@AB@%fflush%@AE@%                            Flushes a stream %@CR:C6A00020255 @%
  2473.  
  2474. %@AB@%fgetc%@AE@%                             Reads a character from a stream 
  2475.                                   (function version) %@CR:C6A00020256 @%
  2476.  
  2477. %@AB@%fgetchar %@AE@%                         Reads a character from %@AB@%stdin%@AE@% (function 
  2478.                                   version)
  2479.  
  2480. %@AB@%fgetpos%@AE@%                           Gets the position indicator of a stream %@CR:C6A00020257 @%
  2481.  
  2482. %@AB@%fgets%@AE@%                             Reads a string from a stream %@CR:C6A00020258 @%
  2483.  
  2484. %@AB@%fileno%@AE@%                            Gets the file handle associated with a 
  2485.                                   stream %@CR:C6A00020259 @%
  2486.  
  2487. %@AB@%flushall%@AE@%                          Flushes all streams %@CR:C6A00020260 @%
  2488.  
  2489. %@AB@%fopen%@AE@%                             Opens a stream %@CR:C6A00020261 @%
  2490.  
  2491. %@AB@%fprintf%@AE@%                           Writes formatted data to a stream %@CR:C6A00020262 @%
  2492.  
  2493. %@AB@%fputc%@AE@%                             Writes a character to a stream (function
  2494.                                   version) %@CR:C6A00020263 @%
  2495.  
  2496. %@AB@%fputchar%@AE@%                          Writes a character to %@AB@%stdout%@AE@% (function 
  2497.                                   version)
  2498.  
  2499. %@AB@%fputs%@AE@%                             Writes a string to a stream %@CR:C6A00020264 @%
  2500.  
  2501. %@AB@%fread%@AE@%                             Reads unformatted data from a stream %@CR:C6A00020265 @%
  2502.  
  2503. %@AB@%freopen%@AE@%                           Reassigns a %@AB@%FILE%@AE@% pointer to a new file%@CR:C6A00020266 @%
  2504.  
  2505. %@AB@%fscanf%@AE@%                            Reads formatted data from a stream %@CR:C6A00020267 @%
  2506.  
  2507. %@AB@%fseek%@AE@%                             Moves file position to a given location %@CR:C6A00020268 @%
  2508.  
  2509. %@AB@%fsetpos%@AE@%                           Sets the position indicator of a stream %@CR:C6A00020269 @%
  2510.  
  2511. %@AB@%_fsopen%@AE@%                           Opens a stream with file sharing %@CR:C6A00020270 @%
  2512.  
  2513. %@AB@%ftell%@AE@%                             Gets current file position %@CR:C6A00020271 @%
  2514.  
  2515. %@AB@%fwrite%@AE@%                            Writes unformatted data items to a 
  2516.                                   stream %@CR:C6A00020272 @%
  2517.  
  2518. %@AB@%getc%@AE@%                              Reads a character from a stream %@CR:C6A00020273 @%
  2519.  
  2520. %@AB@%getchar%@AE@%                           Reads a character from %@AB@%stdin%@AE@%
  2521.  
  2522. %@AB@%gets%@AE@%                              Reads a line from %@AB@%stdin%@AE@% %@CR:C6A00020274 @%
  2523.  
  2524. %@AB@%getw%@AE@%                              Reads a binary %@AB@%int%@AE@% item from a stream %@CR:C6A00020275 @%
  2525.  
  2526. %@AB@%printf%@AE@%                            Writes formatted data to %@AB@%stdout%@AE@% %@CR:C6A00020276 @%
  2527.  
  2528. %@AB@%putc%@AE@%                              Writes a character to a stream
  2529.  
  2530. %@AB@%putchar%@AE@%                           Writes a character to %@AB@%stdout%@AE@% %@CR:C6A00020277 @%
  2531.  
  2532. %@AB@%puts%@AE@%                              Writes a line to a stream %@CR:C6A00020278 @%
  2533.  
  2534. %@AB@%putw%@AE@%                              Writes a binary %@AB@%int%@AE@% item to a stream %@CR:C6A00020279 @%
  2535.  
  2536. %@AB@%rewind%@AE@%                            Moves file position to beginning of a 
  2537.                                   stream %@CR:C6A00020280 @%
  2538.  
  2539. %@AB@%rmtmp%@AE@%                             Removes temporary files created by %@AB@%%@AE@%
  2540.                                   %@AB@%tmpfile%@AE@% %@CR:C6A00020281 @%
  2541.  
  2542. %@AB@%scanf%@AE@%                             Reads formatted data from %@AB@%stdin%@AE@% %@CR:C6A00020282 @%
  2543.  
  2544. %@AB@%setbuf%@AE@%                            Controls stream buffering %@CR:C6A00020283 @%
  2545.  
  2546. %@AB@%setvbuf%@AE@%                           Controls stream buffering and buffer 
  2547.                                   size %@CR:C6A00020284 @%
  2548.  
  2549. %@AB@%sprintf%@AE@%                           Writes formatted data to a string
  2550.  
  2551. %@AB@%sscanf%@AE@%                            Reads formatted data from a string %@CR:C6A00020285 @%
  2552.  
  2553. %@AB@%tempnam%@AE@%                           Generates a temporary file name in given
  2554.                                   directory %@CR:C6A00020286 @%
  2555.  
  2556. %@AB@%tmpfile%@AE@%                           Creates a temporary file %@CR:C6A00020287 @%
  2557.  
  2558. %@AB@%tmpnam%@AE@%                            Generates a temporary file name
  2559.  
  2560. %@AB@%ungetc%@AE@%                            Places a character in the buffer %@CR:C6A00020288 @%
  2561.  
  2562. %@AB@%vfprintf%@AE@%                          Writes formatted data to a stream %@CR:C6A00020289 @%
  2563.  
  2564. %@AB@%vprintf%@AE@%                           Writes formatted data to %@AB@%stdout%@AE@%
  2565.  
  2566. %@AB@%vsprintf%@AE@%                          Writes formatted data to a string
  2567.  
  2568. %@NL@%
  2569. %@4@%%@AB@%2.7.2.1  Opening a Stream%@AE@%%@EH@%%@NL@%
  2570. %@NL@%
  2571. A stream must be opened using the %@AB@%fdopen%@AE@%, %@AB@%fopen%@AE@%, %@AB@%freopen%@AE@%, or %@AB@%_fsopen%@AE@%
  2572. function before input and output can be performed on that stream. When
  2573. opening a stream, the named stream can be opened for reading, writing, or
  2574. both, and can be opened in either text or binary mode.%@CR:C6A00020290 @%  %@NL@%
  2575. %@NL@%
  2576. The %@AB@%fdopen%@AE@%, %@AB@%fopen%@AE@%, %@AB@%freopen%@AE@%, and %@AB@%_fsopen%@AE@% functions return a %@AB@%FILE%@AE@% pointer. You
  2577. normally assign the pointer value to a variable and use the variable to
  2578. refer to the opened stream. For instance, if your program contains the lines
  2579. %@NL@%
  2580. %@NL@%
  2581. %@AS@%  FILE *infile
  2582. %@AS@%  infile = fopen ("test.dat", "r");%@AE@%%@NL@%
  2583. %@NL@%
  2584. you can use the %@AB@%FILE%@AE@% pointer variable %@AS@% infile %@AE@% to refer to the stream.  %@NL@%
  2585. %@NL@%
  2586. %@NL@%
  2587. %@4@%%@AB@%2.7.2.2  Using Predefined Stream Pointers%@AE@%%@EH@%%@NL@%
  2588. %@NL@%
  2589. When a program begins execution, the C start-up code automatically opens
  2590. several streams: standard input, standard output, and standard error. By
  2591. default, the standard input, standard output, and standard error streams are
  2592. directed to the console (keyboard and screen). This means that when a
  2593. program expects input from the "standard input," it receives that input from
  2594. the console. Similarly, a program that writes to the "standard output"
  2595. prints its data to the console. Error messages generated by the library
  2596. routines are sent to the "standard error," meaning that error messages
  2597. appear on the user's console.%@CR:C6A00020291 @%%@CR:C6A00020292 @%%@CR:C6A00020293 @%  %@NL@%
  2598. %@NL@%
  2599. Under DOS, two additional streams are opened: standard auxiliary and
  2600. standard print. (These streams are not available in OS/2.) The assignment of
  2601. standard auxiliary and standard print depends on the machine configuration.
  2602. These streams usually refer to the first serial port and a printer port, but
  2603. those ports may not be available on some systems. Be sure to check your
  2604. machine configuration before using these streams.%@CR:C6A00020294 @%%@CR:C6A00020295 @%  %@NL@%
  2605. %@NL@%
  2606. You can refer to the standard streams with the following predefined stream
  2607. pointers:  %@NL@%
  2608. %@NL@%
  2609. %@AB@%Pointer%@AE@%                           %@AB@%Stream%@AE@%
  2610. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2611. %@AB@%stdin%@AE@%                             Standard input
  2612.  
  2613. %@AB@%stdout%@AE@%                            Standard output
  2614.  
  2615. %@AB@%stderr%@AE@%                            Standard error
  2616.  
  2617. %@AB@%stdaux%@AE@%                            Standard auxiliary (DOS only)
  2618.  
  2619. %@AB@%stdprn%@AE@%                            Standard print (DOS only)
  2620.  
  2621. You can use these pointers in any function that requires a stream pointer as
  2622. an argument. Some functions, such as %@AB@%getchar%@AE@% and %@AB@%putchar%@AE@%, are designed to
  2623. use %@AB@%stdin%@AE@% or %@AB@%stdout%@AE@% automatically. The pointers %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, %@AB@%stderr%@AE@%,
  2624. %@AB@%stdaux%@AE@%, and %@AB@%stdprn%@AE@% are constants, not variables; do not try to assign them a
  2625. new stream pointer value.  %@NL@%
  2626. %@NL@%
  2627. DOS and OS/2 allow you to redirect a program's standard input and standard
  2628. output at the operating-system command level. OS/2 also allows you to
  2629. redirect a program's standard error. See your operating system user's manual
  2630. for a complete discussion of redirection.%@CR:C6A00020296 @%  %@NL@%
  2631. %@NL@%
  2632. Within your program, you can use %@AB@%freopen%@AE@% to redirect %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, %@AB@%stderr%@AE@%,
  2633. %@AB@%stdaux%@AE@%, or %@AB@%stdprn%@AE@% so that it refers to a disk file or to a device. See the
  2634. reference description of %@AB@%freopen%@AE@% for more details.  %@NL@%
  2635. %@NL@%
  2636. %@NL@%
  2637. %@4@%%@AB@%2.7.2.3  Controlling Stream Buffering%@AE@%%@EH@%%@NL@%
  2638. %@NL@%
  2639. As mentioned earlier, stream routines can use in-memory buffers to speed I/O
  2640. operations. Files opened using the stream routines are buffered by default,
  2641. except for %@AB@%stdaux%@AE@% and %@AB@%stdprn%@AE@%, which are normally unbuffered. The %@AB@%stdout%@AE@% and
  2642. %@AB@%stderr%@AE@% streams are flushed whenever they are full or (if you are writing to
  2643. a character device) after each library call.%@CR:C6A00020297 @%%@CR:C6A00020298 @%%@CR:C6A00020299 @%%@CR:C6A00020300 @%%@CR:C6A00020301 @%  %@NL@%
  2644. %@NL@%
  2645. By using the %@AB@%setbuf%@AE@% or %@AB@%setvbuf%@AE@% function, you can cause a stream to be
  2646. unbuffered, or you can associate a buffer with an unbuffered stream. Buffers
  2647. allocated by the system are not accessible to you, but buffers allocated
  2648. with %@AB@%setbuf%@AE@% or %@AB@% setvbuf%@AE@% refer to arrays in your program and can be
  2649. manipulated. Buffers can be any size up to 32,767 bytes. This size is set by
  2650. the manifest constant %@AB@%BUFSIZ%@AE@% in STDIO.H if you use%@AB@% seftbuf%@AE@%; if you use
  2651. %@AB@%setvbuf%@AE@%, you can set the size of the buffer yourself. (See the descriptions
  2652. of %@AB@%setbuf%@AE@% and %@AB@%setvbuf%@AE@% in the reference section for more details.)%@CR:C6A00020302 @%%@CR:C6A00020303 @%  %@NL@%
  2653. %@NL@%
  2654. ────────────────────────────────────────────────────────────────────────────%@NL@%
  2655. NOTE
  2656.  
  2657. %@AI@%These routines affect only buffers created by C library routines. They have
  2658. %@AI@%no effect on buffers created by the operating system.%@AE@%%@NL@%
  2659. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  2660. %@NL@%
  2661. %@NL@%
  2662. %@4@%%@AB@%2.7.2.4  Closing Streams%@AE@%%@EH@%%@NL@%
  2663. %@NL@%
  2664. The %@AB@%fclose%@AE@% and %@AB@%fcloseall%@AE@% functions close a stream or streams. The %@AB@%fclose%@AE@%
  2665. routine closes a single specified stream; %@AB@%fcloseall%@AE@% closes all open streams
  2666. except %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, %@AB@%stderr%@AE@%, %@AB@%stdaux%@AE@%, and %@AB@%stdprn%@AE@%. If your program does not
  2667. explicitly close a stream, the stream is automatically closed when the
  2668. program terminates. How-ever, it is a good practice to close a stream when
  2669. your program is finished with it, as the number of streams that can be open
  2670. at a given time is limited.%@CR:C6A00020304 @%  %@NL@%
  2671. %@NL@%
  2672. %@NL@%
  2673. %@4@%%@AB@%2.7.2.5  Reading and Writing Data%@AE@%%@EH@%%@NL@%
  2674. %@NL@%
  2675. The stream functions allow you to transfer data in a variety of ways. You
  2676. can read and write binary data (a sequence of bytes), or specify reading and
  2677. writing by characters, lines, or more complicated formats.  %@NL@%
  2678. %@NL@%
  2679. Reading and writing operations on streams always begin at the current
  2680. position of the stream, known as the "file pointer" for the stream. The file
  2681. pointer is changed to reflect the new position after a read or write
  2682. operation takes place. For example, if you read a single character from a
  2683. stream, the file pointer is increased by one byte so that the next operation
  2684. begins with the first unread character. If a stream is opened for appending,
  2685. the file pointer is automatically positioned at the end of the file before
  2686. each write operation.%@CR:C6A00020305 @%  %@NL@%
  2687. %@NL@%
  2688. The %@AB@%fseek%@AE@% and %@AB@%fsetpos%@AE@% functions allow you to position the file pointer
  2689. anywhere in a file. The next operation occurs at the position you specified.
  2690. The %@AB@%rewind%@AE@% routine positions the file pointer at the beginning of the file.
  2691. Use the %@AB@%ftell%@AE@% or %@AB@%fgetpos%@AE@% routine to determine the current position of the
  2692. file pointer.  %@NL@%
  2693. %@NL@%
  2694. The %@AB@%feof%@AE@% macro detects an end-of-file condition on a stream. Once the
  2695. end-of-file indicator is set, it remains set until the file is closed, or
  2696. until %@AB@%clearerr%@AE@%, %@AB@%fseek%@AE@%, %@AB@%fsetpos%@AE@%, or %@AB@%rewind%@AE@% is called.  %@NL@%
  2697. %@NL@%
  2698. Streams associated with a character-oriented device (such as a console) do
  2699. not have file pointers. Data coming from or going to a console cannot be
  2700. accessed randomly. Routines that set or get the file-pointer position (such
  2701. as %@AB@%fseek%@AE@%, %@AB@%fgetpos%@AE@%, %@AB@%fsetpos%@AE@%, %@AB@%ftell%@AE@%, or %@AB@%rewind%@AE@%) have undefined results if used
  2702. on a stream associated with a character-oriented device.  %@NL@%
  2703. %@NL@%
  2704. %@NL@%
  2705. %@4@%%@AB@%2.7.2.6  Detecting Errors%@AE@%%@EH@%%@NL@%
  2706. %@NL@%
  2707. When an error occurs in a stream operation, an error indicator for the
  2708. stream is set. You can use the %@AB@%ferror%@AE@% macro to test the error indicator and
  2709. determine whether an error has occurred. Once an error has occurred, the
  2710. error indicator for the stream remains set until the stream is closed, or
  2711. until you explicitly clear the error indicator by calling %@AB@%clearerr%@AE@% or
  2712. %@AB@%rewind%@AE@%.%@CR:C6A00020306 @%%@CR:C6A00020307 @%  %@NL@%
  2713. %@NL@%
  2714. %@NL@%
  2715. %@3@%%@CR:C6A00020308 @%%@AB@%2.7.3  Low-Level Routines%@CR:C6A00020309 @%%@CR:C6A00020310 @%%@AE@%%@EH@%%@NL@%
  2716. %@NL@%
  2717. Low-level input and output calls do not buffer or format data. Declarations
  2718. for the low-level functions are given in the include files IO.H, FCNTL.H,
  2719. SYS\TYPES.H, and SYS\STAT.H. Unlike the stream functions, low-level
  2720. functions do not require the include file STDIO.H. However, some common
  2721. constants are defined in STDIO.H; for example, the end-of-file indicator
  2722. (%@AB@%EOF%@AE@%) may be useful. If your program requires these constants, you must
  2723. include STDIO.H.%@CR:C6A00020311 @%%@CR:C6A00020312 @%%@CR:C6A00020313 @%%@CR:C6A00020314 @%%@CR:C6A00020315 @%%@CR:C6A00020316 @%%@CR:C6A00020317 @%  %@NL@%
  2724. %@NL@%
  2725. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2726. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2727. %@AB@%close%@AE@%%@CR:C6A00020318 @%%@CR:C6A00020319 @% %@CR:C6A00020320 @%%@CR:C6A00020321 @%%@CR:C6A00020322 @%%@CR:C6A00020323 @%%@CR:C6A00020324 @%                            Closes a file
  2728.  
  2729. %@AB@%creat%@AE@%%@CR:C6A00020325 @%                             Creates a file
  2730.  
  2731. %@AB@%dup%@AE@%%@CR:C6A00020326 @%                               Creates a second handle for a file
  2732.  
  2733. %@AB@%dup2%@AE@%                              Reassigns a handle to a file
  2734.  
  2735. %@AB@%eof%@AE@%%@CR:C6A00020327 @%                               Tests for end-of-file
  2736.  
  2737. %@AB@%lseek%@AE@%%@CR:C6A00020328 @%                             Repositions file pointer to a given 
  2738.                                   location
  2739.  
  2740. %@AB@%open%@AE@%%@CR:C6A00020329 @%                              Opens a file
  2741.  
  2742. %@AB@%read%@AE@%%@CR:C6A00020330 @%                              Reads data from a file
  2743.  
  2744. %@AB@%sopen%@AE@%%@CR:C6A00020331 @%                             Opens a file for file sharing
  2745.  
  2746. %@AB@%tell%@AE@%                              Gets current file-pointer position
  2747.  
  2748. %@AB@%umask%@AE@%                             Sets default file-permission mask
  2749.  
  2750. %@AB@%write%@AE@%                             Writes data to a file
  2751.  
  2752. %@NL@%
  2753. %@4@%%@AB@%2.7.3.1  Opening a File%@AE@%%@EH@%%@NL@%
  2754. %@NL@%
  2755. You must open a file before performing I/O functions on it. The %@AB@%open%@AE@%
  2756. function opens a file; it can also create the file when opening it. In OS/2
  2757. and DOS versions 3.0 and later, you can use %@AB@%sopen%@AE@% to open a file with
  2758. file-sharing attributes. The %@AB@%creat%@AE@% function can create and open a file.  %@NL@%
  2759. %@NL@%
  2760. The file can be opened for reading, writing, or both, and opened in either
  2761. text or binary mode (see Section 2.7.1, "Text and Binary Modes"). The
  2762. include file FCNTL.H must be included when opening a file, as it contains
  2763. definitions for flags used in %@AB@%open%@AE@%. In some cases, the files SYS\TYPES.H and
  2764. SYS\STAT.H must also be included; for more information, see the reference
  2765. description for the %@AB@%open%@AE@% function.%@CR:C6A00020332 @%  %@NL@%
  2766. %@NL@%
  2767. These functions return a file handle, which is normally assigned to an
  2768. integer variable. You use the variable to refer to the opened file.%@CR:C6A00020333 @%  %@NL@%
  2769. %@NL@%
  2770. %@NL@%
  2771. %@4@%%@AB@%2.7.3.2  Reading and Writing Data%@AE@%%@EH@%%@NL@%
  2772. %@NL@%
  2773. Use the %@AB@%read%@AE@% and %@AB@%write%@AE@% routines to read and write to files. These operations
  2774. begin at the current position in the file. The current position is updated
  2775. each time a read or write operation occurs.%@CR:C6A00020334 @%  %@NL@%
  2776. %@NL@%
  2777. The %@AB@%lseek%@AE@% function allows you to place the file pointer anywhere in the
  2778. file. The next operation occurs at the position you specified. The %@AB@%tell%@AE@%
  2779. function indicates the current position of the file pointer. The %@AB@%eof%@AE@% routine
  2780. tests for the end of the file.  %@NL@%
  2781. %@NL@%
  2782. Low-level I/O routines set the %@AB@%errno%@AE@% variable when an error occurs. Chapter
  2783. 3, "Global Variables and Standard Types," describes %@AB@%errno%@AE@%.%@CR:C6A00020335 @%%@CR:C6A00020336 @%  %@NL@%
  2784. %@NL@%
  2785. Character-oriented devices, such as the console, do not have file pointers.
  2786. The %@AB@%lseek%@AE@% and %@AB@%tell%@AE@% routines have undefined results if used on a handle
  2787. associated with a device.  %@NL@%
  2788. %@NL@%
  2789. %@NL@%
  2790. %@4@%%@AB@%2.7.3.3  Closing Files%@AE@%%@EH@%%@NL@%
  2791. %@NL@%
  2792. The %@AB@%close%@AE@% function closes an open file. Open files are automatically closed
  2793. when a program terminates. However, it is a good practice to close a file
  2794. when your program is finished with it, as there is a limit to the number of
  2795. files that can be open at one time.%@CR:C6A00020337 @%  %@NL@%
  2796. %@NL@%
  2797. %@NL@%
  2798. %@4@%%@AB@%2.7.3.4  Using Predefined Handles%@AE@%%@EH@%%@NL@%
  2799. %@NL@%
  2800. When a program begins execution, three files are automatically opened:
  2801. standard input, standard output, and standard error. In DOS, two additional
  2802. files are opened: standard auxiliary and standard print. (These files are
  2803. not available in OS/2.)%@CR:C6A00020338 @%%@CR:C6A00020339 @%  %@NL@%
  2804. %@NL@%
  2805. Low-level routines can access these files using the following predefined
  2806. handles:%@CR:C6A00020340 @%%@CR:C6A00020341 @%  %@NL@%
  2807. %@NL@%
  2808. %@AB@%Stream%@AE@%                            %@AB@%Handle%@AE@%
  2809. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2810. %@AB@%stdin%@AE@%                             0
  2811.  
  2812. %@AB@%stdout%@AE@%                            1
  2813.  
  2814. %@AB@%stderr%@AE@%                            2
  2815.  
  2816. %@AB@%stdaux%@AE@% (DOS only)                 3
  2817.  
  2818. %@AB@%stdprn%@AE@% (DOS only)                 4
  2819.  
  2820. You can use these file handles without previously opening the files. The
  2821. files are opened and the handles are assigned when the program starts.  %@NL@%
  2822. %@NL@%
  2823. The %@AB@%dup%@AE@% and %@AB@%dup2%@AE@% functions allow you to assign multiple handles for the same
  2824. file. These functions are typically used to associate the predefined file
  2825. handles with different files.%@CR:C6A00020342 @%  %@NL@%
  2826. %@NL@%
  2827. In DOS and OS/2, you can redirect the standard input and standard output at
  2828. the operating-system command level. OS/2 also allows you to redirect the
  2829. standard error. See your operating system user's manual for a complete
  2830. discussion of redirection.%@CR:C6A00020343 @%  %@NL@%
  2831. %@NL@%
  2832. %@NL@%
  2833. %@3@%%@CR:C6A00020344 @%%@AB@%2.7.4  Console and Port I/O%@AE@%%@EH@%%@NL@%
  2834. %@NL@%
  2835. The console and port I/O routines are implemented as functions and are
  2836. declared in the include file CONIO.H. These functions perform reading and
  2837. writing operations on your console or on the specified port. The %@AB@%cgets%@AE@%,
  2838. %@AB@%cscanf%@AE@%, %@AB@%getch%@AE@%, %@AB@%getche%@AE@%, and %@AB@%kbhit%@AE@% routines take input from the console, while
  2839. %@AB@%cprintf%@AE@%, %@AB@%cputs%@AE@%, %@AB@%putch%@AE@%, and %@AB@%ungetch%@AE@% write to the console. The input or output
  2840. of these functions can be redirected.%@CR:C6A00020345 @%%@CR:C6A00020346 @%%@CR:C6A00020347 @%%@CR:C6A00020348 @%  %@NL@%
  2841. %@NL@%
  2842. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2843. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2844. %@AB@%cgets%@AE@%%@CR:C6A00020349 @%%@CR:C6A00020350 @%                             Reads a string from the console
  2845.  
  2846. %@AB@%cprintf%@AE@%%@CR:C6A00020351 @%%@CR:C6A00020352 @%                           Writes formatted data to the console
  2847.  
  2848. %@AB@%cputs%@AE@%%@CR:C6A00020353 @%                             Writes a string to the console
  2849.  
  2850. %@AB@%cscanf%@AE@%%@CR:C6A00020354 @%%@CR:C6A00020355 @%                            Reads formatted data from the console
  2851.  
  2852. %@AB@%getch%@AE@%%@CR:C6A00020356 @%%@CR:C6A00020357 @%                             Reads a character from the console
  2853.  
  2854. %@AB@%getche%@AE@%                            Reads a character from the console and 
  2855.                                   echoes it
  2856.  
  2857. %@AB@%inp%@AE@%%@CR:C6A00020358 @%%@CR:C6A00020359 @%                               Reads one byte from the specified I/O 
  2858.                                   port
  2859.  
  2860. %@AB@%inpw%@AE@%                              Reads a two-byte word from the specified
  2861.                                   I/O port
  2862.  
  2863. %@AB@%kbhit%@AE@%%@CR:C6A00020360 @%%@CR:C6A00020361 @%                             Checks for a keystroke at the console
  2864.  
  2865. %@AB@%outp%@AE@%%@CR:C6A00020362 @%%@CR:C6A00020363 @%                              Writes one byte to the specified I/O 
  2866.                                   port
  2867.  
  2868. %@AB@%outpw%@AE@%                             Writes a two-byte word to the specified 
  2869.                                   I/O port
  2870.  
  2871. %@AB@%putch%@AE@%%@CR:C6A00020364 @%%@CR:C6A00020365 @%                             Writes a character to the console
  2872.  
  2873. %@AB@%ungetch%@AE@%%@CR:C6A00020366 @%%@CR:C6A00020367 @%                           "Ungets" the last character read from 
  2874.                                   the console so that it becomes the next 
  2875.                                   character read
  2876.  
  2877. ────────────────────────────────────────────────────────────────────────────%@NL@%
  2878. NOTE
  2879.  
  2880. %@AI@%Programs that need only run under DOS can also use a number of direct DOS
  2881. %@AI@%I/O system calls (%@AB@% %@AE@%%@AI@%_dos_open, _dos_read, _dos_close,%@AE@%%@AI@% etc.) These are
  2882. %@AI@%described in detail in Section 2.14, "System Calls."%@AE@%%@AE@%%@NL@%
  2883. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  2884. %@NL@%
  2885. The console or port does not have to be opened or closed before I/O is
  2886. performed, so there are no open or close routines in this category. The port
  2887. I/O routines %@AB@%inp%@AE@% and %@AB@%outp%@AE@% read or write one byte at a time from the
  2888. specified port. The %@AB@%inpw%@AE@% and %@AB@%outpw%@AE@% routines read and write two-byte words,
  2889. respectively.%@CR:C6A00020368 @%%@CR:C6A00020369 @%  %@NL@%
  2890. %@NL@%
  2891. The console I/O routines allow reading and writing of strings (%@AB@%cgets %@AE@%and
  2892. %@AB@%cputs%@AE@%), formatted data (%@AB@%cscanf %@AE@%and %@AB@%cprintf%@AE@%), and characters. Several options
  2893. are available when reading and writing characters.  %@NL@%
  2894. %@NL@%
  2895. The %@AB@%putch%@AE@% routine writes a single character to the console. The %@AB@%getch%@AE@% and
  2896. %@AB@%getche%@AE@% routines read a single character from the console; %@AB@%getche%@AE@% echoes the
  2897. character back to the console, while %@AB@%getch%@AE@% does not. The %@AB@%ungetch%@AE@% routine
  2898. "ungets" the last character read; the next read operation on the console
  2899. begins with the "ungotten" character.  %@NL@%
  2900. %@NL@%
  2901. The %@AB@%kbhit%@AE@% routine determines whether a key has been struck at the console.
  2902. This routine allows you to test for keyboard input before you attempt to
  2903. read from the console.  %@NL@%
  2904. %@NL@%
  2905. ────────────────────────────────────────────────────────────────────────────%@NL@%
  2906. NOTE
  2907.  
  2908. %@AI@%The console I/O routines are not compatible with stream or low-level library
  2909. %@AI@%routines and should not be used with them.%@AE@%%@NL@%
  2910. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  2911. %@NL@%
  2912. %@NL@%
  2913. %@2@%%@CR:C6A00020370 @%%@AB@%2.8  Internationalization%@AE@%%@EH@%%@NL@%
  2914. %@NL@%
  2915. Internationalization routines are useful for creating different versions of
  2916. a program for international markets. These routines are declared in the
  2917. header file LOCALE.H, except for %@AB@%strftime%@AE@%, which is declared in TIME.H.  %@NL@%
  2918. %@NL@%
  2919. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2920. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2921. %@AB@%localeconv%@AE@%                        Sets a structure with appropriate values
  2922.                                   for formatting numeric quantities
  2923.  
  2924. %@AB@%setlocale%@AE@%                         Selects the appropriate locale for the 
  2925.                                   program
  2926.  
  2927. %@AB@%strcoll%@AE@%                           Compares strings using locale-specific 
  2928.                                   information
  2929.  
  2930. %@AB@%strftime%@AE@%                          Formats a date and time string
  2931.  
  2932. %@AB@%strxfrm%@AE@%                           Transforms a string based on 
  2933.                                   locale-specific
  2934.                                   information
  2935.  
  2936. %@NL@%
  2937. %@2@%%@CR:C6A00020371 @%%@AB@%2.9  Math%@AE@%%@EH@%%@NL@%
  2938. %@NL@%
  2939. The math routines allow you to perform common mathematical calculations. All
  2940. math routines work with floating-point values and therefore require
  2941. floating-point support (see Section 1.8, "Floating-Point Support").%@CR:C6A00020372 @%%@CR:C6A00020373 @%%@CR:C6A00020374 @%%@CR:C6A00020375 @%%@CR:C6A00020376 @%%@CR:C6A00020377 @%%@CR:C6A00020378 @%%@CR:C6A00020379 @%%@CR:C6A00020380 @%
  2942. %@CR:C6A00020381 @%%@CR:C6A00020382 @%  %@NL@%
  2943. %@NL@%
  2944. The math library provides two versions of some routines. The first version
  2945. of the routine supports %@AB@%double%@AE@% arguments and return values. The second
  2946. version supports an 80-bit data type, allowing the routine to take %@AB@%long
  2947. %@AB@%double%@AE@% arguments and return a %@AB@%long double%@AE@% value. The second version usually
  2948. has the same name with the suffix %@AB@%l%@AE@%. For instance, the %@AB@%acos%@AE@% routine supports
  2949. %@AB@%double%@AE@% arguments and return values, while %@AB@%acosl%@AE@% supports %@AB@%long double%@AE@%
  2950. arguments and return values.%@CR:C6A00020383 @%%@CR:C6A00020384 @%%@CR:C6A00020385 @%%@CR:C6A00020386 @%%@CR:C6A00020387 @%%@CR:C6A00020388 @%%@CR:C6A00020389 @%%@CR:C6A00020390 @%%@CR:C6A00020391 @%  %@NL@%
  2951. %@NL@%
  2952. Routines which support %@AB@%long double%@AE@% values are not available when you compile
  2953. with the /Fpa (alternate math) compiler option. The same is true of the
  2954. %@AB@%_clear 87%@AE@%,%@AB@% _control87%@AE@%, and %@AB@%_status87%@AE@% routines.%@CR:C6A00020392 @%%@CR:C6A00020393 @%%@CR:C6A00020394 @%%@CR:C6A00020395 @%%@CR:C6A00020396 @%%@CR:C6A00020397 @%%@CR:C6A00020398 @%%@CR:C6A00020399 @%%@CR:C6A00020400 @%
  2955. %@CR:C6A00020401 @%%@CR:C6A00020402 @%%@CR:C6A00020403 @%  %@NL@%
  2956. %@NL@%
  2957. Most math declarations are in the include file MATH.H. However, the
  2958. %@AB@%_clear87%@AE@%, %@AB@%_control87%@AE@%, %@AB@%_fpreset%@AE@%, and %@AB@%_status87%@AE@% routines are defined in
  2959. FLOAT.H, the%@AB@% abs%@AE@% and %@AB@%labs%@AE@% functions are defined in MATH.H and STDLIB.H, and
  2960. the %@AB@%div%@AE@% and %@AB@%ldiv%@AE@% routines are declared in STDLIB.H.%@CR:C6A00020404 @%%@CR:C6A00020405 @%%@CR:C6A00020406 @%%@CR:C6A00020407 @%%@CR:C6A00020408 @%%@CR:C6A00020409 @%%@CR:C6A00020410 @%%@CR:C6A00020411 @%%@CR:C6A00020412 @%
  2961. %@CR:C6A00020413 @%%@CR:C6A00020414 @%%@CR:C6A00020415 @%%@CR:C6A00020416 @%%@CR:C6A00020417 @%  %@NL@%
  2962. %@NL@%
  2963. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  2964. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  2965. %@AB@%acos%@AE@%, %@AB@%acosl%@AE@%                       Calculate the arccosine
  2966.  
  2967. %@AB@%asin%@AE@%, %@AB@%asinl%@AE@%                       Calculate the arcsine
  2968.  
  2969. %@AB@%atan%@AE@%, %@AB@%atanl%@AE@%                       Calculate the arctangent
  2970.  
  2971. %@AB@%atan2%@AE@%, %@AB@%atan2l%@AE@%                     Calculate the arctangent
  2972.  
  2973. %@AB@%bessel%@AE@%                            Calculates Bessel functions
  2974.  
  2975. %@AB@%cabs%@AE@%, %@AB@%cabsl%@AE@%                       Find the absolute value of a complex 
  2976.                                   number
  2977.  
  2978. %@AB@%ceil%@AE@%, %@AB@%ceill%@AE@%                       Find the integer ceiling
  2979.  
  2980. %@AB@%_clear87%@AE@%                          Gets and clears the floating-point 
  2981.                                   status word
  2982.  
  2983. %@AB@%_control87%@AE@%                        Gets the old floating-point control word
  2984.                                   and sets a new control-word value
  2985.  
  2986. %@AB@%cos%@AE@%, %@AB@%cosl%@AE@%                         Calculate the cosine
  2987.  
  2988. %@AB@%cosh%@AE@%, %@AB@%coshl%@AE@%                       Calculate the hyperbolic cosine
  2989.  
  2990. %@AB@%dieeetomsbin%@AE@%                      Converts IEEE double-precision number to
  2991.                                   Microsoft (MS) binary format %@CR:C6A00020418 @%
  2992.  
  2993. %@AB@%div%@AE@%                               Divides one integer by another, 
  2994.                                   returning the quotient and remainder
  2995.  
  2996. %@AB@%dmsbintoieee%@AE@%                      Converts Microsoft binary 
  2997.                                   double-precision number to IEEE format
  2998.  
  2999. %@AB@%exp%@AE@%, %@AB@%expl%@AE@%                         Calculate the exponential function
  3000.  
  3001. %@AB@%fabs%@AE@%, %@AB@%fabsl%@AE@%                       Find the absolute value
  3002.  
  3003. %@AB@%fieeetomsbin%@AE@%                      Converts IEEE single-precision number to
  3004.                                   Microsoft binary format %@CR:C6A00020419 @%
  3005.  
  3006. %@AB@%floor%@AE@%, %@AB@%floorl%@AE@%                     Find the largest integer less than or 
  3007.                                   equal to the
  3008.                                   argument
  3009.  
  3010. %@AB@%fmod%@AE@%, %@AB@%fmodl%@AE@%                       Find the floating-point remainder
  3011.  
  3012. %@AB@%fmsbintoieee%@AE@%                      Converts Microsoft binary 
  3013.                                   single-precision number to IEEE format
  3014.  
  3015. %@AB@%_fpreset%@AE@%                          Reinitializes the floating-point-math 
  3016.                                   package
  3017.  
  3018. %@AB@%frexp%@AE@%, %@AB@%frexpl%@AE@%                     Calculate an exponential value
  3019.  
  3020. %@AB@%hypot%@AE@%, %@AB@%hypotl%@AE@%                     Calculate the hypotenuse of right 
  3021.                                   triangle
  3022.  
  3023. %@AB@%ldexp%@AE@%, %@AB@%ldexpl%@AE@%                     Calculate the product of the argument 
  3024.                                   and 2exp
  3025.  
  3026. %@AB@%ldiv%@AE@%                              Divides one %@AB@%long%@AE@% integer by another, 
  3027.                                   returning the quotient and remainder
  3028.  
  3029. %@AB@%log%@AE@%, %@AB@%logl%@AE@%                         Calculate the natural logarithm
  3030.  
  3031. %@AB@%log10%@AE@%, %@AB@%log10l%@AE@%                     Calculate the base-10 logarithm
  3032.  
  3033. %@AB@%_lrotl%@AE@%,  %@AB@%_lrotr%@AE@%                   Shift an %@AB@%unsigned long int%@AE@% item left ( 
  3034.                                   _lrotl) or right ( _lrotr)
  3035.  
  3036. %@AB@%matherr%@AE@%,  %@AB@%_matherrl%@AE@%               Handle math errors
  3037.  
  3038. %@AB@%max%@AE@%, %@AB@%min%@AE@%                          Return the larger or smaller of two 
  3039.                                   values
  3040.  
  3041. %@AB@%modf%@AE@%, %@AB@%modfl%@AE@%                       Break down the argument into integer and
  3042.                                   fractional parts
  3043.  
  3044. %@AB@%pow%@AE@%, %@AB@%powl%@AE@%                         Calculate a value raised to a power
  3045.  
  3046. %@AB@%rand%@AE@%                              Gets a pseudorandom number
  3047.  
  3048. %@AB@%_rotl%@AE@%,  %@AB@%_rotr%@AE@%                     Shift an %@AB@%unsigned int%@AE@% item left ( _rotl)
  3049.                                   or right
  3050.                                   ( _rotr)
  3051.  
  3052. %@AB@%sin%@AE@%, %@AB@%sinl%@AE@%                         Calculate the sine
  3053.  
  3054. %@AB@%sinh%@AE@%, %@AB@%sinhl%@AE@%                       Calculate the hyperbolic sine
  3055.  
  3056. %@AB@%sqrt%@AE@%, %@AB@%sqrtl%@AE@%                       Find the square root
  3057.  
  3058. %@AB@%srand%@AE@%                             Initializes a pseudorandom series
  3059.  
  3060. %@AB@%_status87%@AE@%                         Gets the floating-point status word
  3061.  
  3062. %@AB@%tan%@AE@%, %@AB@%tanl%@AE@%                         Calculate the tangent
  3063.  
  3064. %@AB@%tanh%@AE@%, %@AB@%tanhl%@AE@%                       Calculate the hyperbolic tangent
  3065.  
  3066. The %@AB@%bessel%@AE@% routine does not correspond to a single function, but to twelve
  3067. functions named %@AB@%j0%@AE@%, %@AB@%j1%@AE@%, %@AB@%jn%@AE@%, %@AB@%y0%@AE@%, %@AB@%y1%@AE@%, %@AB@%yn%@AE@%,  %@AB@%_j0l%@AE@%,  %@AB@%_j1l%@AE@%,  %@AB@%_jnl%@AE@%,  %@AB@%_y0l%@AE@%,  %@AB@%_y1l%@AE@%,
  3068. and  %@AB@%_ynl%@AE@%.  %@NL@%
  3069. %@NL@%
  3070. The %@AB@%matherr%@AE@% and %@AB@%_matherrl%@AE@% routines are invoked by the math functions when
  3071. errors occur. The %@AB@%matherr%@AE@% routine handles functions that return a %@AB@%double%@AE@%
  3072. value and %@AB@%_matherrl%@AE@% handles routines that return a %@AB@%long double%@AE@%.  %@NL@%
  3073. %@NL@%
  3074. These routines are defined in the library, but you can redefine them for
  3075. different error-handling. The user-defined function, if given, must follow
  3076. the rules given in the reference description of %@AB@%matherr%@AE@% and %@AB@%_matherrl%@AE@%.  %@NL@%
  3077. %@NL@%
  3078. You are not required to supply a definition for the %@AB@%matherr%@AE@% routines. If no
  3079. definition is present, the default error returns for each routine are used.
  3080. The reference description of each routine describes that routine's error
  3081. returns.%@CR:C6A00020420 @%%@CR:C6A00020421 @%  %@NL@%
  3082. %@NL@%
  3083. %@NL@%
  3084. %@2@%%@CR:C6A00020422 @%%@AB@%2.10  Memory Allocation%@CR:C6A00020423 @% %@CR:C6A00020424 @%%@CR:C6A00020425 @%%@CR:C6A00020426 @%%@CR:C6A00020427 @%%@AE@%%@EH@%%@NL@%
  3085. %@NL@%
  3086. The memory-allocation routines allow you to allocate, free, and reallocate
  3087. blocks of memory. Memory-allocation routines are declared in the include
  3088. file MALLOC.H.%@CR:C6A00020428 @%%@CR:C6A00020429 @%%@CR:C6A00020430 @%%@CR:C6A00020431 @%%@CR:C6A00020432 @%%@CR:C6A00020433 @%%@CR:C6A00020434 @%%@CR:C6A00020435 @%  %@NL@%
  3089. %@NL@%
  3090. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3091. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3092. %@AB@%alloca%@AE@%                            Allocates a block of memory from the 
  3093.                                   program's stack
  3094.  
  3095. %@AB@%_bfreeseg%@AE@%                         Frees a based heap
  3096.  
  3097. %@AB@%_bheapseg%@AE@%                         Allocates a based heap
  3098.  
  3099. %@AB@%calloc%@AE@%, %@AB@% _bcalloc%@AE@%,  %@AB@%_fcalloc%@AE@%,  %@AB@%%@AE@%   Allocate storage for an array
  3100. %@AB@%_ncalloc%@AE@%                          
  3101.  
  3102. %@AB@%_expand%@AE@%,  %@AB@%_bexpand%@AE@%,  %@AB@%_fexpand%@AE@%, %@AB@%%@AE@%   Expand or shrink a block of memory 
  3103. %@AB@%_nexpand%@AE@%                          without moving its location
  3104.  
  3105. %@AB@%free%@AE@%,  %@AB@%_bfree%@AE@%,  %@AB@%_ffree%@AE@%,  %@AB@%_nfree%@AE@%%@CR:C6A00020436 @%   Free an allocated block
  3106.  
  3107. %@AB@%_freect%@AE@%                           Returns approximate number of items of 
  3108.                                   given size that could be allocated in 
  3109.                                   the near heap
  3110.  
  3111. %@AB@%halloc%@AE@%%@CR:C6A00020437 @%                            Allocates storage for huge array
  3112.  
  3113. %@AB@%_heapadd%@AE@%,  %@AB@%_bheapadd%@AE@%              Add memory to a heap
  3114.  
  3115. %@AB@%_heapchk%@AE@%,  %@AB@%_bheapchk%@AE@%,  %@AB@%_fheapchk%@AE@%  Check a heap for consistency
  3116. , %@AB@%_nheapchk%@AE@%                       
  3117.  
  3118. %@AB@%_heapmin%@AE@%,  %@AB@%_bheapmin%@AE@%,%@AB@%%@AE@%             Release unused memory in a heap
  3119. %@AB@%_fheapmin%@AE@%,  %@AB@%_nheapmin%@AE@%             
  3120.  
  3121. %@AB@%_heapset%@AE@%,  %@AB@%_bheapset%@AE@%,  %@AB@%_fheapset%@AE@%  Fill free heap entries with a specified 
  3122. , %@AB@%_nheapset%@AE@%%@CR:C6A00020438 @%%@CR:C6A00020439 @%%@CR:C6A00020440 @%                       value
  3123.  
  3124. %@AB@%_heapwalk%@AE@%,  %@AB@%_bheapwalk%@AE@%, %@AB@%%@AE@%          Return information about each entry in a
  3125. %@AB@%_fheapwalk%@AE@%, %@AB@%_nheapwalk%@AE@%            heap
  3126.  
  3127. %@AB@%hfree%@AE@%%@CR:C6A00020441 @%                             Frees a block allocated by %@AB@%halloc%@AE@%
  3128.  
  3129. %@AB@%malloc%@AE@%,  %@AB@%_bmalloc%@AE@%,  %@AB@%_fmalloc%@AE@%, %@AB@%%@AE@%    Allocate a block of memory
  3130. %@AB@%_nmalloc%@AE@%%@CR:C6A00020442 @%%@CR:C6A00020443 @%                          
  3131.  
  3132. %@AB@%_memavl%@AE@%%@CR:C6A00020444 @%                           Returns approximate number of bytes 
  3133.                                   available for allocation in the near 
  3134.                                   heap
  3135.  
  3136. %@AB@%_memmax%@AE@%%@CR:C6A00020445 @%                           Returns size of largest contiguous free 
  3137.                                   block in the near heap
  3138.  
  3139. %@AB@%_msize%@AE@%,  %@AB@%_bmsize%@AE@%,  %@AB@%_fmsize%@AE@%, %@AB@%%@AE@%      Return size of an allocated block
  3140. %@AB@%_nmsize%@AE@%%@CR:C6A00020446 @%                           
  3141.  
  3142. %@AB@%realloc%@AE@%,  %@AB@%_brealloc%@AE@%,  %@AB@%_frealloc%@AE@%,  Reallocate a block to a new size%@CR:C6A00020448 @%
  3143. %@AB@%_nrealloc%@AE@%%@CR:C6A00020447 @%                         
  3144.  
  3145. %@AB@%stackavail%@AE@%%@CR:C6A00020449 @%                        Returns size of stack space available 
  3146.                                   for allocation with %@AB@%alloca%@AE@%
  3147.  
  3148. Some memory-management routines, such as %@AB@%malloc%@AE@%, are available in different
  3149. versions that begin with %@AB@%_b%@AE@%, %@AB@%_f%@AE@%, or %@AB@%_n%@AE@%. These variations are described in
  3150. the following section.  %@NL@%
  3151. %@NL@%
  3152. The %@AB@%malloc%@AE@% and %@AB@%free%@AE@% routines allocate and free memory space, respectively,
  3153. while a program runs. The %@AB@%malloc%@AE@% routine allocates memory from the "heap,"
  3154. which is a pool of memory not otherwise used by your program. In tiny-,
  3155. small-, and medium-model programs, the heap consists of unused memory in
  3156. your program's default data segment. In compact-, large-, and huge-model
  3157. programs, it is unused memory outside the default data segment.  %@NL@%
  3158. %@NL@%
  3159. The %@AB@%malloc%@AE@% and %@AB@%free%@AE@% routines satisfy the memory-allocation requirements of
  3160. most programs. More specialized memory-management routines are discussed
  3161. below.  %@NL@%
  3162. %@NL@%
  3163. The %@AB@%realloc%@AE@% and %@AB@%_expand%@AE@% routines can expand or shrink an allocated memory
  3164. block. They behave differently in cases in which there is not enough room to
  3165. expand the block in its current location. In this case, %@AB@%realloc%@AE@% moves the
  3166. block as needed, but %@AB@%_expand%@AE@% does not.  %@NL@%
  3167. %@NL@%
  3168. The %@AB@%calloc%@AE@% routine allocates memory for an array and initializes every byte
  3169. in the allocated block to 0.  %@NL@%
  3170. %@NL@%
  3171. The %@AB@%halloc%@AE@% routine is similar to %@AB@%calloc%@AE@%, except that it can allocate memory
  3172. for a huge array (one that exceeds 64K in size). This routine is useful when
  3173. you need a very large data object, or if you need to return allocated memory
  3174. to the operating system for subsequent calls to the %@AB@%spawn%@AE@% family of
  3175. functions.  %@NL@%
  3176. %@NL@%
  3177. %@NL@%
  3178. %@3@%%@CR:C6A00020450 @%%@AB@%2.10.1  Near and Far Heaps%@AE@%%@EH@%%@NL@%
  3179. %@NL@%
  3180. As mentioned in the previous section, heap memory can reside inside or
  3181. outside your program's default data segment, depending on what memory model
  3182. your program uses. When it lies inside the default data segment, the heap is
  3183. called the "near heap," since it can be accessed with near pointers. The
  3184. "far heap" is memory that spans one or more segments outside the default
  3185. data segment. The far heap can be accessed only with far pointers.  %@NL@%
  3186. %@NL@%
  3187. In various memory models, %@AB@%malloc%@AE@% automatically allocates memory from the
  3188. near heap or far heap, as appropriate. The C library also includes near and
  3189. far versions of %@AB@%malloc%@AE@%, %@AB@%free%@AE@%, and other memory-management routines, which
  3190. allow you to specify the near and far heaps explicitly. These have the same
  3191. names as standard memory routines, but are preceded by %@AB@%_n%@AE@% (for %@AB@%near%@AE@%) or %@AB@%_f%@AE@%
  3192. (for %@AB@%far%@AE@%).  %@NL@%
  3193. %@NL@%
  3194. For instance, the %@AB@%_nmalloc%@AE@% routine always allocates memory from the near
  3195. heap and returns a near pointer, no matter which memory model your program
  3196. uses. Use %@AB@%_nfree%@AE@% to release memory allocated with %@AB@%_nmalloc%@AE@%.  %@NL@%
  3197. %@NL@%
  3198. Similarly, %@AB@%_fmalloc%@AE@% always allocates memory from the far heap and returns a
  3199. far pointer, regardless of memory model. Use the %@AB@%_ffree%@AE@% routine to release
  3200. memory allocated with %@AB@%_fmalloc%@AE@%.  %@NL@%
  3201. %@NL@%
  3202. %@NL@%
  3203. %@3@%%@CR:C6A00020451 @%%@AB@%2.10.2  Based Heaps%@AE@%%@EH@%%@NL@%
  3204. %@NL@%
  3205. You can also allocate memory from a "based heap," which is a single segment
  3206. that lies outside the default data segment. Based-heap routines generally
  3207. use the same names as standard memory routines, but begin with %@AB@%_b%@AE@%. For
  3208. instance, %@AB@%_bmalloc%@AE@% allocates a memory block from the based heap and %@AB@%_bfree%@AE@%
  3209. frees the block.  %@NL@%
  3210. %@NL@%
  3211. Based heaps offer the following advantages:  %@NL@%
  3212. %@NL@%
  3213. %@NL@%
  3214.   ■   Localized data. Based heaps allow you to group related data in a
  3215.       single segment. This can simplify the management of related data. In
  3216.       OS/2, based heaps can also minimize the risk of general protection
  3217.       faults and improve performance.%@NL@%
  3218. %@NL@%
  3219.   ■   Faster pointer arithmetic. Although the based heap lies in the far
  3220.       data segment, pointers to its data items are the same size as near
  3221.       pointers. Thus, pointer arithmetic on items in a based heap is faster
  3222.       than pointer arithmetic on items in the far heap.%@NL@%
  3223. %@NL@%
  3224. %@NL@%
  3225. The %@AB@%_bheapseg%@AE@% routine allocates a based heap segment, from which you can
  3226. then allocate blocks of memory. You can call %@AB@%_bheapseg%@AE@% more than once to
  3227. allocate as many based-heap segments as needed (within the confines of
  3228. available memory).  %@NL@%
  3229. %@NL@%
  3230. The %@AB@%_bfreeseg%@AE@% routine frees a based-heap segment. This routine frees every
  3231. block in the based-heap segment, whether or not you previously freed the
  3232. blocks individually.  %@NL@%
  3233. %@NL@%
  3234. ────────────────────────────────────────────────────────────────────────────%@NL@%
  3235. NOTE
  3236. %@AI@%Near- , far- , and based-heap calls are not ANSI compatible and will make
  3237. %@AI@%your program less portable.%@AE@%%@NL@%
  3238. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  3239. %@NL@%
  3240. %@NL@%
  3241. %@2@%%@CR:C6A00020452 @%%@AB@%2.11  Process and Environment Control%@CR:C6A00020453 @% %@CR:C6A00020454 @%%@CR:C6A00020455 @%%@AE@%%@EH@%%@NL@%
  3242. %@NL@%
  3243. The process-control routines allow you to start, stop, and manage processes
  3244. from within a program. Environment-control routines allow you to get and
  3245. change information about the operating-system environment.%@CR:C6A00020456 @%%@CR:C6A00020457 @%%@CR:C6A00020458 @%%@CR:C6A00020459 @%%@CR:C6A00020460 @%%@CR:C6A00020461 @%%@CR:C6A00020462 @%  %@NL@%
  3246. %@NL@%
  3247. A "process" is a program being executed by the operating system. It consists
  3248. of the program's code and data, plus information about the process, such as
  3249. the number of open files. Whenever you execute a program at the
  3250. operating-system level, you start a process.%@CR:C6A00020463 @%%@CR:C6A00020464 @%%@CR:C6A00020465 @%%@CR:C6A00020466 @%%@CR:C6A00020467 @%%@CR:C6A00020468 @%%@CR:C6A00020469 @%%@CR:C6A00020470 @%%@CR:C6A00020471 @%%@CR:C6A00020472 @%  %@NL@%
  3251. %@NL@%
  3252. All process-control functions except %@AB@%signal%@AE@% are declared in the include file
  3253. PROCESS.H. The %@AB@%signal%@AE@% function is declared in SIGNAL.H. The %@AB@%abort%@AE@%, %@AB@%exit%@AE@%, and
  3254. %@AB@%system%@AE@% functions are also declared in the STDLIB.H include file. The
  3255. environment-control routines (%@AB@%getenv%@AE@% and %@AB@%putenv%@AE@%) are declared in STDLIB.H.%@CR:C6A00020473 @%%@CR:C6A00020474 @%%@CR:C6A00020475 @%%@CR:C6A00020476 @%  %@NL@%
  3256. %@NL@%
  3257. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3258. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3259. %@AB@%abort%@AE@%                             Aborts a process without flushing 
  3260.                                   buffers or calling functions registered 
  3261.                                   by %@AB@%atexit%@AE@% and %@AB@%onexit%@AE@%
  3262.  
  3263. %@AB@%assert%@AE@%                            Tests for logic error
  3264.  
  3265. %@AB@%atexit%@AE@%                            Schedules routines for execution at 
  3266.                                   program
  3267.                                   termination
  3268.  
  3269. %@AB@%_beginthread%@AE@%                      Creates an execution thread (OS/2 only)
  3270.  
  3271. %@AB@%_cexit%@AE@%                            Performs the %@AB@%exit%@AE@% termination procedures
  3272.                                   (such as flushing buffers) and returns 
  3273.                                   control to the calling program
  3274.  
  3275. %@AB@%_c_exit%@AE@%                           Performs the %@AB@%_exit%@AE@% termination 
  3276.                                   procedures and returns control to the 
  3277.                                   calling program
  3278.  
  3279. %@AB@%cwait%@AE@%                             Suspends the calling process until a 
  3280.                                   specified child process terminates (OS/2
  3281.                                   only)
  3282.  
  3283. %@AB@%_endthread%@AE@%                        Terminates an execution thread (OS/2 
  3284.                                   only)
  3285.  
  3286. %@AB@%execl%@AE@%                             Executes child process with argument 
  3287.                                   list
  3288.  
  3289. %@AB@%execle%@AE@%                            Executes child process with argument 
  3290.                                   list and given environment
  3291.  
  3292. %@AB@%execlp%@AE@%                            Executes child process using PATH 
  3293.                                   variable and argument list
  3294.  
  3295. %@AB@%execlpe%@AE@%                           Executes child process using PATH 
  3296.                                   variable, given environment, and 
  3297.                                   argument list
  3298.  
  3299. %@AB@%execv%@AE@%                             Executes child process with argument 
  3300.                                   array
  3301.  
  3302. %@AB@%execve%@AE@%                            Executes child process with argument 
  3303.                                   array and given environment
  3304.  
  3305. %@AB@%execvp%@AE@%                            Executes child process using PATH 
  3306.                                   variable and argument array
  3307.  
  3308. %@AB@%execvpe%@AE@%                           Executes child process using PATH 
  3309.                                   variable, given environment, and 
  3310.                                   argument array
  3311.  
  3312. %@AB@%exit%@AE@%                              Calls functions registered by %@AB@%atexit%@AE@% and
  3313.                                   %@AB@%onexit%@AE@%, then flushes all buffers and 
  3314.                                   closes all open files before terminating
  3315.                                   the process
  3316.  
  3317. %@AB@%_exit%@AE@%                             Terminates process without processing %@AB@%%@AE@%
  3318.                                   %@AB@%atexit%@AE@% or %@AB@%onexit%@AE@% functions or flushing 
  3319.                                   buffers
  3320.  
  3321. %@AB@%getenv%@AE@%                            Gets the value of an environment 
  3322.                                   variable
  3323.  
  3324. %@AB@%getpid%@AE@%                            Gets process ID number
  3325.  
  3326. %@AB@%longjmp%@AE@%                           Restores a saved stack environment
  3327.  
  3328. %@AB@%onexit%@AE@%                            Schedules routines for execution at 
  3329.                                   program
  3330.                                   termination
  3331.  
  3332. %@AB@%_pclose%@AE@%                           Waits for a child command and closes a 
  3333.                                   pipe on the associated stream
  3334.  
  3335. %@AB@%perror%@AE@%                            Prints error message
  3336.  
  3337. %@AB@%_pipe%@AE@%                             Creates a pipe
  3338.  
  3339. %@AB@%_popen%@AE@%                            Creates a pipe and asynchronously 
  3340.                                   executes a child copy of the command 
  3341.                                   processor
  3342.  
  3343. %@AB@%putenv%@AE@%                            Adds or changes the value of an 
  3344.                                   environment
  3345.                                   variable
  3346.  
  3347. %@AB@%raise%@AE@%                             Sends a signal to the calling process
  3348.  
  3349. %@AB@%setjmp%@AE@%                            Saves a stack environment
  3350.  
  3351. %@AB@%signal%@AE@%                            Handles an interrupt signal
  3352.  
  3353. %@AB@%spawnl%@AE@%                            Executes child process with argument 
  3354.                                   list
  3355.  
  3356. %@AB@%spawnle%@AE@%                           Executes child process with argument 
  3357.                                   list and given environment
  3358.  
  3359. %@AB@%spawnlp%@AE@%                           Executes child process using PATH 
  3360.                                   variable and argument list
  3361.  
  3362. %@AB@%spawnlpe%@AE@%                          Executes child process using PATH 
  3363.                                   variable, given environment, and 
  3364.                                   argument list
  3365.  
  3366. %@AB@%spawnv%@AE@%                            Executes child process with argument 
  3367.                                   array
  3368.  
  3369. %@AB@%spawnve%@AE@%                           Executes child process with argument 
  3370.                                   array and given environment
  3371.  
  3372. %@AB@%spawnvp%@AE@%                           Executes child process using PATH 
  3373.                                   variable and argument array
  3374.  
  3375. %@AB@%spawnvpe%@AE@%                          Executes child process using PATH 
  3376.                                   variable, given environment, and 
  3377.                                   argument array
  3378.  
  3379. %@AB@%system%@AE@%                            Executes an operating system command
  3380.  
  3381. %@AB@%wait%@AE@%                              Suspends the calling process until any 
  3382.                                   of the caller's immediate child 
  3383.                                   processes terminate (OS/2 only)
  3384.  
  3385. The %@AB@%atexit%@AE@% and %@AB@%onexit%@AE@% routines create a list of functions to be executed
  3386. when the calling program terminates. The only difference between the two is
  3387. that %@AB@%atexit%@AE@% is part of the ANSI standard. The %@AB@%onexit%@AE@% function is offered for
  3388. compatibility with previous versions of Microsoft C.  %@NL@%
  3389. %@NL@%
  3390. The %@AB@%_exit%@AE@% routine terminates a process immediately, whereas %@AB@%exit%@AE@% terminates
  3391. the process only after flushing buffers and calling any functions previously
  3392. registered by %@AB@%atexit%@AE@% and %@AB@%onexit%@AE@%. The %@AB@%_cexit%@AE@% and %@AB@%_c_exit%@AE@% routines are
  3393. identical to %@AB@%exit%@AE@% and %@AB@%_exit%@AE@%, respectively, except that they return control
  3394. to the calling program without terminating the process.  %@NL@%
  3395. %@NL@%
  3396. The %@AB@%setjmp%@AE@% and %@AB@%longjmp%@AE@% routines save and restore a stack environment. These
  3397. allow you to execute a nonlocal %@AB@%goto%@AE@%.  %@NL@%
  3398. %@NL@%
  3399. The %@AB@%exec%@AE@% and %@AB@%spawn%@AE@% routines start a new process called the "child" process.
  3400. The difference between the %@AB@%exec%@AE@% and %@AB@%spawn%@AE@% routines is that the %@AB@%spawn%@AE@%
  3401. routines are capable of returning control from the child process to its
  3402. caller (the "parent" process). Both the parent process and the child process
  3403. are present in memory (unless %@AB@%P_OVERLAY%@AE@% is specified). In the %@AB@%exec%@AE@% routines,
  3404. the child process overlays the parent process, so returning control to the
  3405. parent process is impossible (unless an error occurs when attempting to
  3406. start execution of the child process).  %@NL@%
  3407. %@NL@%
  3408. There are eight forms each of the %@AB@%spawn%@AE@% and %@AB@%exec%@AE@% routines (see Table 2.1).
  3409. The differences among the forms involve the method of locating the file to
  3410. be executed as the child process, the method for passing arguments to the
  3411. child process, and the method of setting the environment.  %@NL@%
  3412. %@NL@%
  3413. Passing an argument list means that the arguments to the child process are
  3414. listed separately in the %@AB@%exec%@AE@% or %@AB@%spawn%@AE@% call. Passing an argument array means
  3415. that the arguments are stored in an array, and a pointer to the array is
  3416. passed to the child process. The argument-list method is typically used when
  3417. the number of arguments is constant or is known at compile time. The
  3418. argument-array method is useful when the number of arguments must be
  3419. determined at run time.  %@NL@%
  3420. %@NL@%
  3421. Several process-control routines take advantage of the multitasking
  3422. capability of OS/2. The %@AB@%_beginthread%@AE@% and %@AB@%_endthread%@AE@% routines create and
  3423. terminate execution threads. The %@AB@%cwait%@AE@% and %@AB@%wait%@AE@% routines suspend the calling
  3424. process until one child process terminates. The %@AB@%_pipe%@AE@%, %@AB@%_popen%@AE@%, and %@AB@%_pclose%@AE@%
  3425. routines create and manipulate pipes, which link processes for sequential
  3426. execution.  %@NL@%
  3427. %@NL@%
  3428. %@AB@%Table 2.1  Forms of the spawn and exec Routines%@AE@%
  3429.  
  3430. %@TH:  42  2708 03 20 19 21 21 @%
  3431.                                        Argument-Passing     
  3432. Routines            Locating the File  Convention           Environment 
  3433.                                                             Settings
  3434. %@AB@%─────────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3435. %@AB@%execl%@AE@%, %@AB@%spawnl%@AE@%       Do not use PATH    Argument list        Inherited from 
  3436.                                                             parent
  3437.  
  3438. %@AB@%execle%@AE@%, %@AB@%spawnle%@AE@%     Do not use PATH    Argument list        Pointer to 
  3439.                                                             environment table 
  3440.                                                             for child process 
  3441.                                                             passed as last 
  3442.                                                             argument
  3443.  
  3444. %@AB@%execlp%@AE@%, %@AB@%spawnlp%@AE@%     Use PATH           Argument list        Inherited from 
  3445.                                                             parent
  3446.  
  3447. %@AB@%execlpe%@AE@%, %@AB@%spawnlpe%@AE@%   Use PATH           Argument list        Pointer to 
  3448.                                                             environment table 
  3449.                                                             for child process 
  3450.                                                             passed as last
  3451.                                                             argument
  3452.  
  3453. %@AB@%execv%@AE@%, %@AB@%spawnv%@AE@%       Do not use PATH    Argument array       Inherited from 
  3454.                                                             parent
  3455.  
  3456. %@AB@%execve%@AE@%, %@AB@%spawnve%@AE@%     Do not use PATH    Argument array       Pointer to 
  3457.                                                             environment table 
  3458.                                                             for child process 
  3459.                                                             passed as last
  3460.                                                             argument
  3461.  
  3462. %@AB@%execvp%@AE@%, %@AB@%spawnvp%@AE@%     Use PATH           Argument array       Inherited from 
  3463.                                                             parent
  3464.  
  3465. %@AB@%execvpe%@AE@%, %@AB@%spawnvpe%@AE@%   Use PATH           Argument array       Pointer to 
  3466.                                                             environment table 
  3467.                                                             for child process 
  3468.                                                             passed as last 
  3469.                                                             argument
  3470.  
  3471. %@AB@%─────────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3472.  
  3473. %@TE:  42  2708 03 20 19 21 21 @%
  3474.  
  3475. The %@AB@%assert%@AE@% macro is typically used to test for logic errors. It prints a
  3476. message when a given "assertion" fails to hold true. Defining the identifier
  3477. %@AB@%NDEBUG%@AE@% to any value causes occurrences of %@AB@%assert%@AE@% to be removed from the
  3478. source file, thus allowing you to turn off assertion checking without
  3479. modifying the source file.  %@NL@%
  3480. %@NL@%
  3481. %@NL@%
  3482. %@2@%%@CR:C6A00020477 @%%@AB@%2.12  Searching and Sorting%@CR:C6A00020478 @% %@CR:C6A00020479 @%%@AE@%%@EH@%%@NL@%
  3483. %@NL@%
  3484. Search and sort routines provide binary-search, linear-search, and
  3485. quick-sort capabilities. They are all declared in SEARCH.H.%@CR:C6A00020480 @%  %@NL@%
  3486. %@NL@%
  3487. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3488. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3489. %@AB@%bsearch%@AE@%%@CR:C6A00020481 @%%@CR:C6A00020482 @%                           Performs binary search
  3490.  
  3491. %@AB@%lfind%@AE@%%@CR:C6A00020483 @%%@CR:C6A00020484 @%                             Performs linear search for given value
  3492.  
  3493. %@AB@%lsearch%@AE@%%@CR:C6A00020485 @%                           Performs linear search for given value, 
  3494.                                   which is added to array if not found
  3495.  
  3496. %@AB@%qsort%@AE@%%@CR:C6A00020486 @%  %@CR:C6A00020487 @%                           Performs quick sort
  3497.  
  3498. %@NL@%
  3499. %@2@%%@CR:C6A00020488 @%%@AB@%2.13  String Manipulation%@CR:C6A00020489 @%%@AE@%%@EH@%%@NL@%
  3500. %@NL@%
  3501. The string functions are declared in the include file STRING.H. They allow
  3502. you to compare strings, copy them, search for strings and characters, and
  3503. perform various other operations.%@CR:C6A00020490 @%%@CR:C6A00020491 @%%@CR:C6A00020492 @%%@CR:C6A00020493 @%%@CR:C6A00020494 @%%@CR:C6A00020495 @%%@CR:C6A00020496 @%%@CR:C6A00020497 @%%@CR:C6A00020498 @%%@CR:C6A00020499 @%%@CR:C6A00020500 @%
  3504. %@CR:C6A00020501 @%%@CR:C6A00020502 @%  %@NL@%
  3505. %@NL@%
  3506. Routines beginning with %@AB@%_f%@AE@% are model-independent versions of the
  3507. corresponding routines and are useful in mixed-model programs. These
  3508. routines can be called from any point in the program, regardless of which
  3509. model is being used.%@CR:C6A00020503 @%%@CR:C6A00020504 @%%@CR:C6A00020505 @%%@CR:C6A00020506 @%%@CR:C6A00020507 @%%@CR:C6A00020508 @%%@CR:C6A00020509 @%%@CR:C6A00020510 @%  %@NL@%
  3510. %@NL@%
  3511. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3512. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3513. %@AB@%strcat%@AE@%,   %@AB@%_fstrcat%@AE@%%@CR:C6A00020511 @%                Append one string to another
  3514.  
  3515. %@AB@%strchr%@AE@%,  %@AB@%_fstrchr%@AE@%%@CR:C6A00020512 @%                 Find first occurrence of a given 
  3516.                                   character in a string
  3517.  
  3518. %@AB@%strcmp%@AE@%,  %@AB@%_fstrcmp%@AE@%%@CR:C6A00020513 @%                 Compare two strings
  3519.  
  3520. %@AB@%strcpy%@AE@%,  %@AB@%_fstrcpy%@AE@%%@CR:C6A00020514 @%                 Copy one string to another
  3521.  
  3522. %@AB@%strcspn%@AE@%,  %@AB@%_fstrcspn%@AE@%               Find first occurrence of a character 
  3523.                                   from a given character set in a string
  3524.  
  3525. %@AB@%strdup%@AE@%,  %@AB@%_fstrdup%@AE@%, %@AB@%_nstrdup%@AE@%       Duplicate a string
  3526.  
  3527. %@AB@%strerror%@AE@%                          Maps an error number to a message string
  3528.  
  3529. %@AB@%_strerror%@AE@%                         Maps a user-defined error message to a 
  3530.                                   string
  3531.  
  3532. %@AB@%stricmp%@AE@%,  %@AB@%_fstricmp%@AE@%               Compare two strings without regard to 
  3533.                                   case
  3534.  
  3535. %@AB@%strlen%@AE@%,  %@AB@%_fstrlen%@AE@%                 Find length of string
  3536.  
  3537. %@AB@%strlwr%@AE@%,  %@AB@%_fstrlwr%@AE@%                 Convert string to lowercase
  3538.  
  3539. %@AB@%strncat%@AE@%,  %@AB@%_fstrncat%@AE@%               Append characters of a string
  3540.  
  3541. %@AB@%strncmp%@AE@%,  %@AB@%_fstrncmp%@AE@%               Compare characters of two strings
  3542.  
  3543. %@AB@%strncpy%@AE@%,  %@AB@%_fstrncpy%@AE@%               Copy characters of one string to another
  3544.  
  3545. %@AB@%strnicmp%@AE@%,  %@AB@%_fstrnicmp%@AE@%             Compare characters of two strings 
  3546.                                   without regard
  3547.                                   to case 
  3548.  
  3549. %@AB@%strnset%@AE@%,  %@AB@%_fstrnset%@AE@%               Set characters of a string to a given 
  3550.                                   character
  3551.  
  3552. %@AB@%strpbrk%@AE@%,  %@AB@%_fstrpbrk%@AE@%               Find first occurrence of a character 
  3553.                                   from one string in another
  3554.  
  3555. %@AB@%strrchr%@AE@%,  %@AB@%_fstrrchr%@AE@%               Find last occurrence of a given 
  3556.                                   character in string
  3557.  
  3558. %@AB@%strrev%@AE@%,  %@AB@%_fstrrev%@AE@%                 Reverse string
  3559.  
  3560. %@AB@%strset%@AE@%,  %@AB@%_fstrset%@AE@%                 Set all characters of a string to a 
  3561.                                   given character
  3562.  
  3563. %@AB@%strspn%@AE@%,  %@AB@%_fstrspn%@AE@%                 Find first substring from a given 
  3564.                                   character set in a string
  3565.  
  3566. %@AB@%strstr%@AE@%,  %@AB@%_fstrstr%@AE@%                 Find first occurrence of a given string 
  3567.                                   in another string
  3568.  
  3569. %@AB@%strtok%@AE@%,  %@AB@%_fstrtok%@AE@%                 Find next token in a string
  3570.  
  3571. %@AB@%strupr%@AE@%,  %@AB@%_fstrupr%@AE@%                 Convert a string to uppercase
  3572.  
  3573. All string functions work on null-terminated character strings. When working
  3574. with character arrays that do not end with a null character, you can use the
  3575. buffer-manipulation routines, described in Section 2.1.  %@NL@%
  3576. %@NL@%
  3577. %@NL@%
  3578. %@2@%%@CR:C6A00020515 @%%@AB@%2.14  System Calls%@AE@%%@EH@%%@NL@%
  3579. %@NL@%
  3580. The following routines give access to IBM-PC BIOS interrupts and DOS system
  3581. calls. Except for the %@AB@%FP_OFF%@AE@%, %@AB@%FP_SEG%@AE@%, and %@AB@%segread%@AE@% routines, these routines
  3582. are for DOS application programs only; they do not work under OS/2.%@CR:C6A00020516 @%%@CR:C6A00020517 @%%@CR:C6A00020518 @%  %@NL@%
  3583. %@NL@%
  3584. %@NL@%
  3585. %@3@%%@CR:C6A00020519 @%%@AB@%2.14.1  BIOS Interface%@CR:C6A00020520 @% %@CR:C6A00020521 @%%@CR:C6A00020522 @%%@CR:C6A00020523 @%%@AE@%%@EH@%%@NL@%
  3586. %@NL@%
  3587. The functions in this category provide direct access to the BIOS interrupt
  3588. services. They are all declared in BIOS.H.  %@NL@%
  3589. %@NL@%
  3590. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3591. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3592. %@AB@%_bios_disk%@AE@%                        Issues service requests for both hard 
  3593.                                   and floppy disks, using INT 0x13
  3594.  
  3595. %@AB@%_bios_equiplist%@AE@%                   Performs an equipment check, using INT 
  3596.                                   0x11
  3597.  
  3598. %@AB@%_bios_keybrd%@AE@%                      Provides access to keyboard services, 
  3599.                                   using
  3600.                                   INT 0x16
  3601.  
  3602. %@AB@%_bios_memsize%@AE@%                     Obtains information about available 
  3603.                                   memory, using INT 0x12
  3604.  
  3605. %@AB@%_bios_printer%@AE@%                     Performs printer output services, using 
  3606.                                   INT 0x17
  3607.  
  3608. %@AB@%_bios_serialcom%@AE@%                   Performs serial communications tasks, 
  3609.                                   using
  3610.                                   INT 0x14
  3611.  
  3612. %@AB@%_bios_timeofday%@AE@%                   Provides access to system clock, using 
  3613.                                   INT 0x1A
  3614.  
  3615. ────────────────────────────────────────────────────────────────────────────%@NL@%
  3616. NOTE
  3617. %@AI@%BIOS routines are hardware dependent. Some of them may not work as expected
  3618. %@AI@%on machines whose hardware differs from the IBM PC.%@AE@%%@NL@%
  3619. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  3620. %@NL@%
  3621. %@NL@%
  3622. %@3@%%@CR:C6A00020524 @%%@AB@%2.14.2  DOS Interface%@CR:C6A00020525 @%%@CR:C6A00020526 @%%@CR:C6A00020527 @%%@AE@%%@EH@%%@NL@%
  3623. %@NL@%
  3624. These routines are implemented as functions and declared in DOS.H.%@CR:C6A00020528 @%%@CR:C6A00020529 @%%@CR:C6A00020530 @%%@CR:C6A00020531 @%%@CR:C6A00020532 @%  %@NL@%
  3625. %@NL@%
  3626. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3627. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3628. %@AB@%bdos%@AE@%                              Invokes DOS system call; uses only DX 
  3629.                                   and AL registers %@CR:C6A00020533 @%
  3630.  
  3631. %@AB@%_chain_intr%@AE@%                       Chains one interrupt handler to another %@CR:C6A00020534 @%
  3632.  
  3633. %@AB@%_disable%@AE@%                          Disables interrupts %@CR:C6A00020535 @%
  3634.  
  3635. %@AB@%_dos_allocmem%@AE@%                     Allocates a block of memory, using DOS 
  3636.                                   system call 0x48 %@CR:C6A00020536 @%
  3637.  
  3638. %@AB@%_dos_close%@AE@%                        Closes a file, using DOS system call 
  3639.                                   0x3E %@CR:C6A00020537 @%
  3640.  
  3641. %@AB@%_dos_creat%@AE@%                        Creates a new file and erases any 
  3642.                                   existing file having the same name, 
  3643.                                   using DOS system call 0x3C %@CR:C6A00020538 @%
  3644.  
  3645. %@AB@%_dos_creatnew%@AE@%                     Creates a new file and returns an error 
  3646.                                   if a file having the same name exists, 
  3647.                                   using DOS system
  3648.                                   call 0x5B %@CR:C6A00020539 @%
  3649.  
  3650. %@AB@%_dos_findfirst%@AE@%                    Finds first occurrence of a given file, 
  3651.                                   using DOS system call 0x4E %@CR:C6A00020540 @%
  3652.  
  3653. %@AB@%_dos_findnext%@AE@%                     Finds subsequent occurrences of a given 
  3654.                                   file, using DOS system call 0x4F %@CR:C6A00020541 @%
  3655.  
  3656. %@AB@%_dos_freemem%@AE@%                      Frees a block of memory, using DOS 
  3657.                                   system
  3658.                                   call 0x49 %@CR:C6A00020542 @%
  3659.  
  3660. %@AB@%_dos_getdate%@AE@%                      Gets the system date, using DOS system 
  3661.                                   call 0x2A %@CR:C6A00020543 @%
  3662.  
  3663. %@AB@%_dos_getdiskfree%@AE@%                  Gets information on a disk volume, using
  3664.                                   DOS system call 0x36 %@CR:C6A00020544 @%
  3665.  
  3666. %@AB@%_dos_getdrive%@AE@%                     Gets the current default drive, using 
  3667.                                   DOS system call 0x19 %@CR:C6A00020545 @%
  3668.  
  3669. %@AB@%_dos_getfileattr%@AE@%                  Gets current attributes of a file or 
  3670.                                   directory, using DOS system call 0x43 %@CR:C6A00020546 @%
  3671.  
  3672. %@AB@%_dos_getftime%@AE@%                     Gets the date and time a file was last 
  3673.                                   written, using DOS system call 0x57 %@CR:C6A00020547 @%
  3674.  
  3675. %@AB@%_dos_gettime%@AE@%                      Gets the current system time, using DOS 
  3676.                                   system
  3677.                                   call 0x2C %@CR:C6A00020548 @%
  3678.  
  3679. %@AB@%_dos_getvect%@AE@%                      Gets the current value of a specified 
  3680.                                   interrupt vector, using DOS system call 
  3681.                                   0x35 %@CR:C6A00020549 @%
  3682.  
  3683. %@AB@%_dos_keep%@AE@%                         Installs terminate-and-stay-resident 
  3684.                                   (TSR) programs using DOS system call 
  3685.                                   0x31 %@CR:C6A00020550 @%
  3686.  
  3687. %@AB@%_dos_open%@AE@%                         Opens an existing file, using DOS system
  3688.                                   call 0x3D %@CR:C6A00020551 @%
  3689.  
  3690. %@AB@%_dos_read%@AE@%                         Reads a file, using DOS system call 0x3F
  3691.                                   %@CR:C6A00020552 @%
  3692.  
  3693. %@AB@%_dos_setblock%@AE@%                     Changes the size of a previously 
  3694.                                   allocated block, using DOS system call 
  3695.                                   0x4A %@CR:C6A00020553 @%
  3696.  
  3697. %@AB@%_dos_setdate%@AE@%                      Sets the current system date, using DOS 
  3698.                                   system
  3699.                                   call 0x2B %@CR:C6A00020554 @%
  3700.  
  3701. %@AB@%_dos_setdrive%@AE@%                     Sets the default disk drive, using DOS 
  3702.                                   system
  3703.                                   call 0x0E %@CR:C6A00020555 @%
  3704.  
  3705. %@AB@%_dos_setfileattr%@AE@%                  Sets the current attributes of a file, 
  3706.                                   using DOS system call 0x43 %@CR:C6A00020556 @%
  3707.  
  3708. %@AB@%_dos_setftime%@AE@%                     Sets the date and time that the 
  3709.                                   specified file was last written, using 
  3710.                                   DOS system call 0x57 %@CR:C6A00020557 @%
  3711.  
  3712. %@AB@%_dos_settime%@AE@%                      Sets the system time, using DOS system 
  3713.                                   call 0x2D %@CR:C6A00020558 @%
  3714.  
  3715. %@AB@%_dos_setvect%@AE@%                      Sets a new value for the specified 
  3716.                                   interrupt vector, using DOS system call 
  3717.                                   0x25 %@CR:C6A00020559 @%
  3718.  
  3719. %@AB@%_dos_write%@AE@%                        Sends output to a file, using DOS system
  3720.                                   call 0x40 %@CR:C6A00020560 @%
  3721.  
  3722. %@AB@%dosexterr%@AE@%                         Obtains in-depth error information from 
  3723.                                   DOS system call 0x59 %@CR:C6A00020561 @%
  3724.  
  3725. %@AB@%_enable%@AE@% %@CR:C6A00020562 @%                          Enables interrupts 
  3726.  
  3727. %@AB@%FP_OFF%@AE@%                            Returns offset portion of a far pointer 
  3728.                                   (OS/2
  3729.                                   and DOS) %@CR:C6A00020563 @%
  3730.  
  3731. %@AB@%FP_SEG%@AE@%                            Returns segment portion of a far pointer
  3732.                                   (OS/2
  3733.                                   and DOS)
  3734.  
  3735. %@AB@%_harderr%@AE@%                          Establishes a hardware error handler %@CR:C6A00020564 @%
  3736.  
  3737. %@AB@%_hardresume%@AE@%                       Returns to DOS after a hardware error %@CR:C6A00020565 @%
  3738.  
  3739. %@AB@%_hardretn%@AE@%                         Returns to the application after a 
  3740.                                   hardware error %@CR:C6A00020566 @%
  3741.  
  3742. %@AB@%int86%@AE@%                             Invokes DOS interrupts %@CR:C6A00020567 @%
  3743.  
  3744. %@AB@%int86x%@AE@%                            Invokes DOS interrupts with segment 
  3745.                                   register values %@CR:C6A00020568 @%
  3746.  
  3747. %@AB@%intdos%@AE@%                            Invokes DOS system call using registers 
  3748.                                   other than DX and AL %@CR:C6A00020569 @%
  3749.  
  3750. %@AB@%intdosx%@AE@%                           Invokes DOS system call using registers 
  3751.                                   other than DX and AL with segment 
  3752.                                   register values %@CR:C6A00020570 @%
  3753.  
  3754. %@AB@%segread%@AE@%                           Returns current values of segment 
  3755.                                   registers (OS/2 and DOS) %@CR:C6A00020571 @%
  3756.  
  3757. The %@AB@%_harderr%@AE@% routine is used to define a hardware-error interrupt handler.
  3758. The %@AB@%_hardresume%@AE@% and %@AB@%_hardretn%@AE@% routines are used within a hardware error
  3759. handler to define the return from the error.  %@NL@%
  3760. %@NL@%
  3761. The %@AB@%dosexterr%@AE@% function obtains and stores the error information returned by
  3762. DOS system call 0x59 (extended error handling). This function is provided
  3763. for use with DOS versions 3.0 and later.%@CR:C6A00020572 @%%@CR:C6A00020573 @%%@CR:C6A00020574 @%  %@NL@%
  3764. %@NL@%
  3765. The %@AB@%bdos%@AE@% routine is useful for invoking DOS calls that use either or both of
  3766. the DX (DH/DL) and AL registers for arguments. However, %@AB@%bdos%@AE@% should not be
  3767. used to invoke system calls that return an error code in AX if the carry
  3768. flag is set; since your program cannot detect whether the carry flag is set,
  3769. it cannot determine whether the value in AX is a legitimate value or an
  3770. error value. In this case, the %@AB@%intdos%@AE@% routine should be used instead, since
  3771. it allows the program to detect whether the carry flag is set. The %@AB@%intdos%@AE@%
  3772. routine can also be used to invoke DOS calls that use registers other than
  3773. DX and AL.  %@NL@%
  3774. %@NL@%
  3775. The %@AB@%intdosx%@AE@% routine is similar to the %@AB@%intdos%@AE@% routine, but is used when ES is
  3776. required by the system call, when DS must contain a value other than the
  3777. default data segment (for instance, when a far pointer is used), or when
  3778. making the system call in a large-model program. When calling %@AB@%intdosx%@AE@%, give
  3779. an argument that specifies the segment values to be used in the call.  %@NL@%
  3780. %@NL@%
  3781. The %@AB@%int86%@AE@% routine can be used to invoke any interrupt. The %@AB@%int86x%@AE@% routine is
  3782. similar; however, like the %@AB@%intdosx%@AE@% routine, it is designed to work with
  3783. large-model programs and far items, as described in the preceding paragraph.
  3784. %@NL@%
  3785. %@NL@%
  3786. The %@AB@%FP_OFF%@AE@% and %@AB@%FP_SEG%@AE@% routines allow easy access to the segment and offset
  3787. portions of a far pointer value. %@AB@%FP_OFF%@AE@% and %@AB@%FP_SEG%@AE@% are implemented as macros
  3788. and defined in DOS.H. You can use these macros in OS/2 as well as DOS.%@CR:C6A00020575 @%%@CR:C6A00020576 @%  %@NL@%
  3789. %@NL@%
  3790. The %@AB@%segread%@AE@% routine returns the current values of the segment registers.
  3791. This routine is typically used with the %@AB@%intdosx%@AE@% and %@AB@%int86x%@AE@% routines to
  3792. obtain the correct segment values.  %@NL@%
  3793. %@NL@%
  3794. The %@AB@%_chain_intr%@AE@% routine is useful for chaining interrupt handlers together.
  3795. The %@AB@%_enable%@AE@% routine enables interrupts, while the %@AB@%_disable%@AE@% routine disables
  3796. interrupts.  %@NL@%
  3797. %@NL@%
  3798. %@CR:C6A00020577 @%%@CR:C6A00020578 @%The routines prefixed with  %@AB@%_dos_%@AE@%  are all direct system interfaces that use
  3799. the system calls noted above. More detailed information on these system
  3800. calls can be found in the %@AI@%MS-DOS Encyclopedia %@AE@%(Duncan, ed.; Redmond, WA:
  3801. Microsoft Press, 1988)or the%@AI@% Programmer's PC Sourcebook %@AE@%(Hogan; Redmond, WA:
  3802. Microsoft Press, 1988)%@AI@%.  %@AE@%%@NL@%
  3803. %@NL@%
  3804. ────────────────────────────────────────────────────────────────────────────%@NL@%
  3805. NOTE
  3806.  
  3807. %@AI@%The DOS interface I/O routines are generally incompatible with console,
  3808. %@AI@%low-level, and stream I/O routines. Do not mix different types of I/O
  3809. %@AI@%routines in the same source file.%@AE@%%@NL@%
  3810. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  3811. %@NL@%
  3812. %@NL@%
  3813. %@2@%%@CR:C6A00020579 @%%@AB@%2.15  Time%@CR:C6A00020580 @%%@CR:C6A00020581 @%%@CR:C6A00020582 @%%@CR:C6A00020583 @%%@AE@%%@EH@%%@NL@%
  3814. %@NL@%
  3815. The time functions allow you to obtain the current time, then convert and
  3816. store it according to your particular needs. The current time is always
  3817. taken from the system time.%@CR:C6A00020584 @%%@CR:C6A00020585 @%%@CR:C6A00020586 @%%@CR:C6A00020587 @%%@CR:C6A00020588 @%%@CR:C6A00020589 @%%@CR:C6A00020590 @%%@CR:C6A00020591 @%  %@NL@%
  3818. %@NL@%
  3819. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3820. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3821. %@AB@%asctime%@AE@%                           Converts time from type %@AB@%struct tm%@AE@% to a 
  3822.                                   character string
  3823.  
  3824. %@AB@%clock%@AE@%                             Returns the elapsed CPU time for a 
  3825.                                   process
  3826.  
  3827. %@AB@%ctime%@AE@%                             Converts time from a long integer to a 
  3828.                                   character string
  3829.  
  3830. %@AB@%difftime%@AE@%                          Computes the difference between two 
  3831.                                   times
  3832.  
  3833. %@AB@%ftime%@AE@%                             Puts current system time in variable of 
  3834.                                   type%@AB@%%@AE@%
  3835.                                   %@AB@%struct tm%@AE@%
  3836.  
  3837. %@AB@%gmtime%@AE@%                            Converts time from integer to %@AB@%struct tm%@AE@%
  3838.  
  3839. %@AB@%localtime%@AE@%                         Converts time from integer to %@AB@%struct tm%@AE@% 
  3840.                                   with local correction
  3841.  
  3842. %@AB@%mktime%@AE@%                            Converts time to a calendar value
  3843.  
  3844. %@AB@%_strdate%@AE@%                          Returns the current system date as a 
  3845.                                   string
  3846.  
  3847. %@AB@%strftime%@AE@%                          Formats a date and time string
  3848.  
  3849. %@AB@%_strtime%@AE@%                          Returns the current system time as a 
  3850.                                   string
  3851.  
  3852. %@AB@%time%@AE@%                              Gets current system time as a long 
  3853.                                   integer
  3854.  
  3855. %@AB@%tzset%@AE@%                             Sets external time variables from the 
  3856.                                   environment time variable
  3857.  
  3858. %@AB@%utime%@AE@%                             Sets file-modification time
  3859.  
  3860. The %@AB@%time%@AE@% and %@AB@%ftime%@AE@% functions return the current time as the number of
  3861. seconds elapsed since midnight Universal Coordinated Time (UTC) on January
  3862. 1, 1970. This value can be converted, adjusted, and stored in a variety of
  3863. ways by using the %@AB@%asctime%@AE@%, %@AB@%ctime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, and %@AB@%mktime%@AE@% functions.
  3864. The %@AB@%utime%@AE@% function sets the modification time for a specified file, using
  3865. either the current time or a time value stored in a structure.%@CR:C6A00020592 @%%@CR:C6A00020593 @%%@CR:C6A00020594 @%  %@NL@%
  3866. %@NL@%
  3867. The %@AB@%clock%@AE@% function returns the elapsed CPU time for the calling process.  %@NL@%
  3868. %@NL@%
  3869. The %@AB@%ftime%@AE@% function requires two files: SYS\TYPES.H and SYS\TIMEB.H. It is
  3870. declared in SYS\TIMEB.H. The %@AB@%utime%@AE@% function also requires two include files:
  3871. SYS\TYPES.H and SYS\UTIME.H. It is declared in SYS\UTIME.H. The remainder of
  3872. the time functions are declared in the include file TIME.H.%@CR:C6A00020595 @%%@CR:C6A00020596 @%%@CR:C6A00020597 @%%@CR:C6A00020598 @%%@CR:C6A00020599 @%  %@NL@%
  3873. %@NL@%
  3874. When you want to use %@AB@%ftime%@AE@% or %@AB@%localtime%@AE@% to make adjustments for local time,
  3875. you must define an environment variable named TZ. Section 3.2, which
  3876. describes the global variables %@AB@%daylight%@AE@%, %@AB@%timezone%@AE@%, and %@AB@%tzname%@AE@%, includes a
  3877. discussion of the TZ variable. TZ is also described on the %@AB@%tzset%@AE@% reference
  3878. page in Part 2 of this book.%@CR:C6A00020600 @%%@CR:C6A00020601 @%  %@NL@%
  3879. %@NL@%
  3880. The %@AB@%_strdate%@AE@% and %@AB@%_strtime%@AE@% routines return strings containing the current
  3881. date and time, respectively, in the DOS and OS/2 date and time format rather
  3882. than in the XENIX-style formats.  %@NL@%
  3883. %@NL@%
  3884. The %@AB@%stfrtime%@AE@% function is useful for creating international versions of a
  3885. program. See Section 2.8, "Internationalization."  %@NL@%
  3886. %@NL@%
  3887. %@NL@%
  3888. %@2@%%@CR:C6A00020602 @%%@AB@%2.16  Variable-Length Argument Lists%@AE@%%@EH@%%@NL@%
  3889. %@NL@%
  3890. The %@AB@%va_arg%@AE@%, %@AB@%va_end%@AE@%, and %@AB@%va_start%@AE@% routines are macros that provide a portable
  3891. way to access the arguments to a function when the function takes a variable
  3892. number of arguments. Two versions of the macros are available: the macros
  3893. defined in the VARARG.H include file, which are compatible with the UNIX
  3894. System V definition, and the macros defined in STDARG.H, which conform to
  3895. the ANSI C standard.%@CR:C6A00020603 @%%@CR:C6A00020604 @%%@CR:C6A00020605 @%  %@NL@%
  3896. %@NL@%
  3897. %@AB@%Routine%@AE@%                           %@AB@%Use%@AE@%
  3898. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3899. %@AB@%va_arg%@AE@%                            Retrieves argument from list
  3900.  
  3901. %@AB@%va_end%@AE@%                            Resets pointer
  3902.  
  3903. %@AB@%va_start%@AE@%                          Sets pointer to beginning of argument 
  3904.                                   list
  3905.  
  3906. For more information on the differences between the two versions and for an
  3907. explanation of how to use the macros, see their descriptions in Part 2 of
  3908. this book.  %@NL@%
  3909. %@NL@%
  3910. %@NL@%
  3911. %@NL@%
  3912. %@NL@%
  3913. %@NL@%
  3914. %@NL@%
  3915. %@CR:C6A00030001 @%%@1@%%@AB@%Chapter 3  Global Variables and Standard Types%@AE@%%@EH@%%@NL@%
  3916. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3917. %@NL@%
  3918. The Microsoft C Run-Time Library contains definitions for a number of
  3919. variables and standard types used by library routines. You can access these
  3920. variables and types by including in your program the files in which they are
  3921. declared, or by giving appropriate declarations in your program, as shown in
  3922. the following sections.%@CR:C6A00030002 @%%@CR:C6A00030003 @%  %@NL@%
  3923. %@NL@%
  3924. %@NL@%
  3925. %@2@%%@CR:C6A00030004 @%%@AB@%3.1  _amblksiz%@AE@%%@EH@%%@NL@%
  3926. %@NL@%
  3927. The %@AB@%_amblksiz%@AE@% variable controls memory heap granularity.%@CR:C6A00030005 @%%@CR:C6A00030006 @%  %@NL@%
  3928. %@NL@%
  3929. It is declared in the MALLOC.H include file as follows:  %@NL@%
  3930. %@NL@%
  3931. %@AS@%  extern unsigned int _amblksiz;%@AE@%%@NL@%
  3932. %@NL@%
  3933. The %@AB@%_amblksiz%@AE@% variable controls the amount of memory used in the heap for
  3934. dynamic memory allocation.%@CR:C6A00030007 @%  %@NL@%
  3935. %@NL@%
  3936. Memory space is always requested from the operating system in blocks
  3937. containing %@AB@%_amblksiz%@AE@% bytes. The first time a program calls a
  3938. memory-allocation function such as %@AB@%malloc%@AE@%, the operating system allocates a
  3939. block of heap memory. The size of this block is defined by %@AB@%_amblksiz%@AE@%, which
  3940. has a default value of 8K (8,192 bytes).  %@NL@%
  3941. %@NL@%
  3942. Later memory requests are satisfied from the original block. When that block
  3943. is exhausted, another block of %@AB@%_amblksiz%@AE@% bytes is allocated. If your C
  3944. program allocates a block larger than %@AB@%_amblksiz%@AE@%, multiple blocks that are
  3945. each of size %@AB@%_amblksiz%@AE@% are allocated until the request is satisfied.  %@NL@%
  3946. %@NL@%
  3947. To change the size of the default memory block, assign the desired size to
  3948. the %@AB@%_amblksiz%@AE@% variable, as in the following example:  %@NL@%
  3949. %@NL@%
  3950. %@AS@%  _amblksiz = 2048;%@AE@%%@NL@%
  3951. %@NL@%
  3952. The heap allocator always rounds the operating-system request to the nearest
  3953. power of 2 greater than or equal to %@AB@%_amblksiz%@AE@%. The above statement allocates
  3954. memory in multiples of 2K (2,048 bytes).  %@NL@%
  3955. %@NL@%
  3956. Fewer system calls are required if you set %@AB@%_amblksiz%@AE@% to a large value, but
  3957. your program may use more memory than needed. If program speed is important,
  3958. set %@AB@%_amblksiz%@AE@% to a large value. If size is important, set %@AB@%_amblksiz%@AE@% to a
  3959. smaller value.  %@NL@%
  3960. %@NL@%
  3961. Note that adjusting the value of %@AB@%_amblksiz%@AE@% affects allocation in the near,
  3962. far, and based heaps. The value of %@AB@%_amblksiz%@AE@% has no effect on huge memory
  3963. blocks (those allocated with %@AB@%halloc%@AE@% and similar functions).  %@NL@%
  3964. %@NL@%
  3965. %@NL@%
  3966. %@2@%%@CR:C6A00030008 @%%@AB@%3.2  daylight, timezone, tzname%@AE@%%@EH@%%@NL@%
  3967. %@NL@%
  3968. The %@AB@%daylight%@AE@%, %@AB@%timezone%@AE@%, and %@AB@%tzname%@AE@% variables are global timezone variables
  3969. used in time functions.%@CR:C6A00030009 @%%@CR:C6A00030010 @%%@CR:C6A00030011 @%%@CR:C6A00030012 @%%@CR:C6A00030013 @%%@CR:C6A00030014 @%  %@NL@%
  3970. %@NL@%
  3971. They are declared in the TIME.H include files as follows:  %@NL@%
  3972. %@NL@%
  3973. %@AS@%  extern int daylight;%@AE@%%@NL@%
  3974. %@NL@%
  3975. %@AS@%  extern long timezone;%@AE@%%@NL@%
  3976. %@NL@%
  3977. %@AS@%  extern char *tzname [2];%@AE@%%@NL@%
  3978. %@NL@%
  3979. Some time and date routines use the %@AB@%daylight%@AE@%, %@AB@%timezone%@AE@%, and %@AB@%tzname%@AE@% variables
  3980. to make local-time adjustments. Whenever a program calls the %@AB@%ftime%@AE@%,
  3981. %@AB@%localtime%@AE@%, or %@AB@%tzset%@AE@% function, the value of %@AB@%daylight%@AE@%, %@AB@%timezone%@AE@%, and %@AB@%tzname%@AE@% is
  3982. determined from the value of the %@AB@%TZ%@AE@% environment variable. If you do not
  3983. explicitly set the value of %@AB@%TZ%@AE@%, the default value of PST8PDT is used. The
  3984. following list shows each variable and its value:%@CR:C6A00030015 @%%@CR:C6A00030016 @%  %@NL@%
  3985. %@NL@%
  3986. %@AB@%Variable%@AE@%                          %@AB@%Value%@AE@%
  3987. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  3988. %@AB@%daylight%@AE@%                          Nonzero if a daylight-saving-time zone 
  3989.                                   (DST) is specified in %@AB@%TZ%@AE@%; otherwise 
  3990.                                   zero. Default value is one.
  3991.  
  3992. %@AB@%timezone%@AE@%                          Difference in seconds between Greenwich 
  3993.                                   mean time and the local time. Default 
  3994.                                   value is 28,800.
  3995.  
  3996. %@AB@%tzname[0]%@AE@%                         Three-letter time zone name derived from
  3997.                                   the %@AB@%TZ%@AE@% environment variable. Default 
  3998.                                   value is "PST" (Pacific standard time).
  3999.  
  4000. %@AB@%tzname[1]%@AE@%                         Three-letter daylight-saving-time zone 
  4001.                                   name derived from the %@AB@%TZ%@AE@% environment 
  4002.                                   variable. Default value is PDT. If the 
  4003.                                   DST zone is omitted from %@AB@%TZ%@AE@%, %@AB@%tzname[1]%@AE@% 
  4004.                                   is an empty string.
  4005.  
  4006. %@NL@%
  4007. %@2@%%@CR:C6A00030017 @%%@AB@%3.3  _doserrno, errno, sys_errlist, sys_nerr%@CR:C6A00030018 @% %@CR:C6A00030019 @%%@CR:C6A00030020 @%%@CR:C6A00030021 @% %@CR:C6A00030022 @% %@CR:C6A00030023 @%%@CR:C6A00030024 @% %@CR:C6A00030025 @%%@AE@%%@EH@%%@NL@%
  4008. %@NL@%
  4009. The %@AB@%_doserrno%@AE@%, %@AB@%errno%@AE@%, %@AB@%sys_errlist%@AE@%, and %@AB@%sys_nerr%@AE@% variables contain error
  4010. codes, and are used by the %@AB@%perror%@AE@% and %@AB@%_strerror%@AE@% routines to print error
  4011. information.  %@NL@%
  4012. %@NL@%
  4013. These variables are declared in the STDLIB.H include file. Manifest
  4014. constants for the %@AB@%errno%@AE@% variables are declared in the ERRNO.H include file.
  4015. The declarations are as follows:  %@NL@%
  4016. %@NL@%
  4017. %@AS@%  extern int _doserrno;%@AE@%%@NL@%
  4018. %@NL@%
  4019. %@AS@%  extern int errno;%@AE@%%@NL@%
  4020. %@NL@%
  4021. %@AS@%  extern char *sys_errlist[ ];%@AE@%%@NL@%
  4022. %@NL@%
  4023. %@AS@%  extern int sys_nerr;%@AE@%%@NL@%
  4024. %@NL@%
  4025. The %@AB@%errno%@AE@% variable is set to an integer value to reflect the type of error
  4026. that has occurred in a system-level call. Each %@AB@%errno%@AE@% value is associated
  4027. with an error message, which can be printed with the %@AB@%perror%@AE@% routine or
  4028. stored in a string with the %@AB@%strerror%@AE@% routine.  %@NL@%
  4029. %@NL@%
  4030. Note that only some routines set the %@AB@%errno%@AE@% variable. If a routine sets
  4031. %@AB@%errno%@AE@%, the description of the routine in the reference section says so
  4032. explicitly.  %@NL@%
  4033. %@NL@%
  4034. The value of %@AB@%errno%@AE@% reflects the error value for the last call that set
  4035. %@AB@%errno%@AE@%. However, this value is not necessarily reset by later successful
  4036. calls. To avoid confusion, test for errors immediately after a call.  %@NL@%
  4037. %@NL@%
  4038. The include file ERRNO.H contains the definitions of the %@AB@%errno%@AE@% values.
  4039. However, not all of the definitions given in ERRNO.H are used in DOS and
  4040. OS/2. Some of the values in ERRNO.H are present to maintain compatibility
  4041. with XENIX and UNIX operating systems.  %@NL@%
  4042. %@NL@%
  4043. The %@AB@%errno%@AE@% values in DOS and OS/2 are a subset of the values for %@AB@%errno%@AE@% in
  4044. XENIX systems. Thus, the %@AB@%errno%@AE@% value is not necessarily the same as the
  4045. actual error code returned by a DOS or OS/2 system call. To access the
  4046. actual DOS and OS/2 error code, use the %@AB@%_doserrno%@AE@% variable, which contains
  4047. this value.%@CR:C6A00030026 @%%@CR:C6A00030027 @%  %@NL@%
  4048. %@NL@%
  4049. In general, you should use %@AB@%_doserrno%@AE@% only for error detection in operations
  4050. involving input and output, since the %@AB@%errno%@AE@% values for input and output
  4051. errors have DOS and OS/2 error-code equivalents. In other cases, the value
  4052. of %@AB@%_doserrno%@AE@% is undefined.  %@NL@%
  4053. %@NL@%
  4054. The %@AB@%syserrlist%@AE@% variable is an array; the %@AB@%perror%@AE@% and %@AB@%strerror%@AE@% routines use it
  4055. to process error information. The %@AB@%sys_nerr%@AE@% variable tells how many elements
  4056. the %@AB@%sys_errlist%@AE@% array contains.  %@NL@%
  4057. %@NL@%
  4058. Table 3.1 gives the %@AB@%errno%@AE@% values for DOS and OS/2, the system error message
  4059. for each value, and the value of each constant. Note that only the %@AB@%ERANGE%@AE@%
  4060. and %@AB@%EDOM%@AE@% constants are specified in the ANSI standard.  %@NL@%
  4061. %@NL@%
  4062. %@AB@%Table   3.1 errno Values and Their Meanings%@AE@%
  4063.  
  4064. %@TH:  32  1783 02 12 59 07 @%
  4065. Constant    Meaning                                                    Value
  4066. %@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4067. %@AB@%E2BIG%@AE@%       Argument list too long %@CR:C6A00030028 @%                                    7
  4068.  
  4069. %@AB@%EACCES%@AE@%      Permission denied %@CR:C6A00030029 @%                                         13
  4070.  
  4071. %@AB@%EBADF%@AE@%       Bad file number %@CR:C6A00030030 @%                                           9
  4072.  
  4073. %@AB@%EDEADLOCK%@AE@%   Resource deadlock would occur %@CR:C6A00030031 @%                             36
  4074.  
  4075. %@AB@%EDOM%@AE@%        Math argument %@CR:C6A00030032 @%                                             33
  4076.  
  4077. %@AB@%EEXIST%@AE@%      File exists %@CR:C6A00030033 @%                                               17
  4078.  
  4079. %@AB@%EINVAL%@AE@%      Invalid argument %@CR:C6A00030034 @%                                          22
  4080.  
  4081. %@AB@%EMFILE%@AE@%      Too many open files %@CR:C6A00030035 @%                                       24
  4082.  
  4083. %@AB@%ENOENT%@AE@%      No such file or directory %@CR:C6A00030036 @%                                 2
  4084.  
  4085. %@AB@%ENOEXEC%@AE@%     Exec format error %@CR:C6A00030037 @%                                         8
  4086.  
  4087. %@AB@%ENOMEM%@AE@%      Not enough memory %@CR:C6A00030038 @%                                         12
  4088.  
  4089. %@AB@%ENOSPC%@AE@%      No space left on device %@CR:C6A00030039 @%                                   28
  4090.  
  4091. %@AB@%ERANGE%@AE@%      Result too large %@CR:C6A00030040 @%                                          34
  4092.  
  4093. %@AB@%EXDEV%@AE@%       Cross-device link %@CR:C6A00030041 @%                                         18
  4094.  
  4095. %@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4096.  
  4097. %@TE:  32  1783 02 12 59 07 @%
  4098.  
  4099. %@NL@%
  4100. %@2@%%@CR:C6A00030042 @%%@AB@%3.4  _fmode%@CR:C6A00030043 @%%@CR:C6A00030044 @% %@CR:C6A00030045 @%%@CR:C6A00030046 @% %@CR:C6A00030047 @%%@CR:C6A00030048 @%%@CR:C6A00030049 @%%@AE@%%@EH@%%@NL@%
  4101. %@NL@%
  4102. The %@AB@%_fmode%@AE@% variable controls the default file-translation mode.  %@NL@%
  4103. %@NL@%
  4104. It is declared in the STDLIB.H include file as follows:  %@NL@%
  4105. %@NL@%
  4106. %@AS@%  extern int _fmode;%@AE@%%@NL@%
  4107. %@NL@%
  4108. By default, the value of %@AB@%_fmode%@AE@% is %@AB@%O_TEXT%@AE@%, causing files to be translated in
  4109. text mode (unless specifically opened or set to binary mode). When %@AB@%_fmode%@AE@% is
  4110. set to %@AB@%O_BINARY%@AE@%, the default mode is binary. You can set %@AB@%_fmode%@AE@% to the flag
  4111. %@AB@%O_BINARY%@AE@% by linking with BINMODE.OBJ or by assigning it the %@AB@%O_BINARY %@AE@%value.
  4112. %@NL@%
  4113. %@NL@%
  4114. %@NL@%
  4115. %@2@%%@CR:C6A00030050 @%%@AB@%3.5  _osmajor, _osminor, _osmode, _osversion%@CR:C6A00030051 @% %@CR:C6A00030052 @%%@CR:C6A00030053 @% %@CR:C6A00030054 @% %@CR:C6A00030055 @%%@CR:C6A00030056 @% %@CR:C6A00030057 @%%@AE@%%@EH@%%@NL@%
  4116. %@NL@%
  4117. The %@AB@%_osmajor%@AE@%, %@AB@%_osminor%@AE@%, %@AB@%_osmode%@AE@%, and %@AB@%_osversion%@AE@% variables specify the
  4118. version number of the operating system or the current mode of operation.  %@NL@%
  4119. %@NL@%
  4120. They are declared in the STDLIB.H include file as follows:  %@NL@%
  4121. %@NL@%
  4122. %@AS@%  extern unsigned char _osmajor;%@AE@%%@NL@%
  4123. %@NL@%
  4124. %@AS@%  extern unsigned char _osminor;%@AE@%%@NL@%
  4125. %@NL@%
  4126. %@AS@%  extern unsigned char _osmode;%@AE@%%@NL@%
  4127. %@NL@%
  4128. %@AS@%  extern unsigned char _osversion;%@AE@%%@NL@%
  4129. %@NL@%
  4130. The %@AB@%_osmajor%@AE@%, %@AB@%_osminor%@AE@%, and %@AB@%_osversion%@AE@% variables specify the version number
  4131. of DOS or OS/2 currently in use. The %@AB@%_osmajor%@AE@% variable holds the "major"
  4132. version number and the %@AB@%_osminor%@AE@% variable stores the "minor" version number.
  4133. Thus, under DOS version 3.20, %@AB@%_osmajor%@AE@% is 3 and %@AB@%_osminor%@AE@% is 20. The %@AB@%
  4134. %@AB@%_osversion%@AE@% variable holds both values; its low byte contains the major
  4135. version number and its high byte the minor version number.  %@NL@%
  4136. %@NL@%
  4137. These variables are useful for creating programs that run in different
  4138. versions of DOS and OS/2. For example, you can test the %@AB@%_osmajor%@AE@% variable
  4139. before making a call to %@AB@%sopen%@AE@%; if the major version number is earlier (less)
  4140. than 3, %@AB@%open%@AE@% should be used instead of %@AB@%sopen%@AE@%.  %@NL@%
  4141. %@NL@%
  4142. The %@AB@%_osmode%@AE@% variable indicates whether the program is in OS/2 protected mode
  4143. or in real mode (DOS or OS/2 real mode). An %@AB@%_osmode%@AE@% value of %@AB@%DOS_MODE%@AE@%
  4144. indicates real mode operation and a value of %@AB@%OS2_MODE%@AE@% indicates protected
  4145. operation.  %@NL@%
  4146. %@NL@%
  4147. %@NL@%
  4148. %@2@%%@CR:C6A00030058 @%%@AB@%3.6  environ%@CR:C6A00030059 @%%@CR:C6A00030060 @%%@AE@%%@EH@%%@NL@%
  4149. %@NL@%
  4150. The %@AB@%environ%@AE@% variable is a pointer to the strings in the process environment.
  4151. %@NL@%
  4152. %@NL@%
  4153. It is declared in the STDLIB.H include file as follows:  %@NL@%
  4154. %@NL@%
  4155. %@AS@%  extern char *environ [ ];%@AE@%%@NL@%
  4156. %@NL@%
  4157. The %@AB@%environ%@AE@% variable provides access to memory areas containing
  4158. process-specific information.  %@NL@%
  4159. %@NL@%
  4160. The %@AB@%environ%@AE@% variable is an array of pointers to the strings that constitute
  4161. the process environment. The environment consists of one or more entries of
  4162. the form%@CR:C6A00030061 @%  %@NL@%
  4163. %@NL@%
  4164. %@AB@%NAME%@AE@%=%@AI@%string%@AE@%  %@NL@%
  4165. %@NL@%
  4166. where %@AB@%NAME %@AE@%is the name of an environment variable and %@AI@%string %@AE@%is the value of
  4167. that variable. The string may be empty. The initial environment settings are
  4168. taken from the operating-system environment at the time of program
  4169. execution.  %@NL@%
  4170. %@NL@%
  4171. The %@AB@%getenv%@AE@% and %@AB@%putenv%@AE@% routines use the %@AB@%environ%@AE@% variable to access and modify
  4172. the environment table. When %@AB@%putenv%@AE@% is called to add or delete environment
  4173. settings, the environment table changes size; its location in memory may
  4174. also change, depending on the program's memory requirements. The %@AB@%environ%@AE@%
  4175. variable is adjusted in these cases and always points to the correct table
  4176. location.  %@NL@%
  4177. %@NL@%
  4178. %@NL@%
  4179. %@2@%%@CR:C6A00030062 @%%@AB@%3.7  _psp%@CR:C6A00030063 @%%@CR:C6A00030064 @%%@CR:C6A00030065 @%%@AE@%%@EH@%%@NL@%
  4180. %@NL@%
  4181. The %@AB@%_psp%@AE@% variable contains the segment address of the program segment prefix
  4182. (PSP) for the process.  %@NL@%
  4183. %@NL@%
  4184. It is declared in the STDLIB.H include file as follows:  %@NL@%
  4185. %@NL@%
  4186. %@AS@%  extern unsigned int _psp;%@AE@%%@NL@%
  4187. %@NL@%
  4188. The PSP contains execution information about the process, such as a copy of
  4189. the command line that invoked the process and the return address on process
  4190. termination or interrupt. The %@AB@%_psp%@AE@% variable can be used to form a long
  4191. pointer to the PSP, where %@AB@%_psp%@AE@% is the segment value and 0 is the offset
  4192. value.%@CR:C6A00030066 @%  %@NL@%
  4193. %@NL@%
  4194. Note that the %@AB@%_psp%@AE@% variable is supported only in DOS.  %@NL@%
  4195. %@NL@%
  4196. %@NL@%
  4197. %@2@%%@CR:C6A00030067 @%%@AB@%3.8  Standard Types%@AE@%%@EH@%%@NL@%
  4198. %@NL@%
  4199. A number of library routines use values whose types are defined in include
  4200. files. In the following list, these types are described, and the include
  4201. file defining each type is given.%@CR:C6A00030068 @%  %@NL@%
  4202. %@NL@%
  4203. %@AB@%Standard Type%@AE@%                     %@AB@%Description%@AE@%
  4204. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4205. %@AB@%clock_t%@AE@%                           The %@AB@%clock_t%@AE@% type, defined in TIME.H, 
  4206.                                   stores time values. It is used by the %@AB@%%@AE@%
  4207.                                   %@AB@%clock%@AE@% function. %@CR:C6A00030069 @%%@CR:C6A00030070 @%
  4208.  
  4209. %@AB@%complex%@AE@%                           The %@AB@%complex%@AE@% structure, defined in 
  4210.                                   MATH.H, stores the real and imaginary 
  4211.                                   parts of complex numbers. It is used by 
  4212.                                   the %@AB@%cabs%@AE@% function. %@CR:C6A00030071 @%%@CR:C6A00030072 @%
  4213.  
  4214. %@AB@%diskfree_t%@AE@%                        The %@AB@%diskfree_t%@AE@% structure, defined in 
  4215.                                   DOS.H, stores disk information used by 
  4216.                                   the %@AB@%_dos_getdiskfree%@AE@% routine. %@CR:C6A00030073 @%%@CR:C6A00030074 @%
  4217.  
  4218. %@AB@%diskinfo_t%@AE@%                        The %@AB@%diskinfo_t%@AE@% structure, defined in 
  4219.                                   BIOS.H, records information about disk 
  4220.                                   drives returned by the %@AB@%_bios_disk%@AE@% 
  4221.                                   routine. %@CR:C6A00030075 @%%@CR:C6A00030076 @%
  4222.  
  4223. %@AB@%div_t%@AE@%, %@AB@%ldiv_t%@AE@%                     The %@AB@%div_t%@AE@% and %@AB@%ldiv_t%@AE@% structures, defined
  4224.                                   in STDLIB.H, store the values returned 
  4225.                                   by the %@AB@%div%@AE@% and %@AB@%ldiv%@AE@% functions, 
  4226.                                   respectively. %@CR:C6A00030077 @%%@CR:C6A00030078 @%%@CR:C6A00030079 @%%@CR:C6A00030080 @%
  4227.  
  4228. %@AB@%dosdate_t%@AE@%                         The %@AB@%dosdate_t%@AE@% structure, defined in 
  4229.                                   DOS.H, records the current system date 
  4230.                                   used in the %@AB@%_dos_getdate%@AE@% and %@AB@%%@AE@%
  4231.                                   %@AB@%_dos_setdate%@AE@% routines. %@CR:C6A00030081 @%
  4232.  
  4233. %@AB@%dostime_t%@AE@%                         The %@AB@%dostime_t%@AE@% structure, defined in 
  4234.                                   DOS.H, records the current system time 
  4235.                                   used in the %@AB@%_dos_gettime%@AE@% and %@AB@%%@AE@%
  4236.                                   %@AB@%_dos_settime%@AE@% routines. %@CR:C6A00030082 @%%@CR:C6A00030083 @%
  4237.  
  4238. %@AB@%DOSERROR%@AE@%                          The %@AB@%DOSERROR%@AE@% structure, defined in 
  4239.                                   DOS.H, stores values returned by DOS 
  4240.                                   system call 59H (available under DOS 
  4241.                                   versions 3.0 and later). %@CR:C6A00030084 @%%@CR:C6A00030085 @%
  4242.  
  4243. %@AB@%exception%@AE@%                         The %@AB@%exception%@AE@% structure, defined in 
  4244.                                   MATH.H, stores error information for 
  4245.                                   math routines. It is used by the %@AB@%matherr%@AE@%
  4246.                                   routine. %@CR:C6A00030086 @%%@CR:C6A00030087 @%
  4247.  
  4248. %@AB@%FILE%@AE@%                              The %@AB@%FILE%@AE@% structure, defined in STDIO.H, 
  4249.                                   is the structure used in all stream 
  4250.                                   input and output operations. The fields 
  4251.                                   of the %@AB@%FILE%@AE@% structure store information 
  4252.                                   about the current state of the stream. %@CR:C6A00030088 @%%@CR:C6A00030089 @%
  4253.  
  4254. %@AB@%find_t%@AE@%                            The %@AB@%find_t%@AE@% structure, defined in DOS.H, 
  4255.                                   stores file-attribute information 
  4256.                                   returned by the %@AB@%_dos_findfirst%@AE@% and %@AB@%%@AE@%
  4257.                                   %@AB@%_dos_findnext%@AE@% routines. %@CR:C6A00030090 @%%@CR:C6A00030091 @%
  4258.  
  4259. %@AB@%fpos_t%@AE@%                            The %@AB@%fgetpos%@AE@% and %@AB@%fsetpos%@AE@% functions use 
  4260.                                   the %@AB@%fpos_t%@AE@% object type, defined in 
  4261.                                   STDIO.H, to record all the information 
  4262.                                   necessary to uniquely specify every 
  4263.                                   position within the file. %@CR:C6A00030092 @%%@CR:C6A00030093 @%
  4264.  
  4265. %@AB@%jmp_buf%@AE@%                           The %@AB@%jmp_buf%@AE@% type, defined in SETJMP.H, 
  4266.                                   is an array type rather than a structure
  4267.                                   type. A buffer of this type is used by 
  4268.                                   the %@AB@%setjmp%@AE@% and %@AB@%longjmp%@AE@% routines to save 
  4269.                                   and restore the program 
  4270.                                   environment. %@CR:C6A00030094 @%%@CR:C6A00030095 @%
  4271.  
  4272. %@AB@%lconv%@AE@%                             The %@AB@%lconv%@AE@% type is a structure containing
  4273.                                   formatting rules for numeric values in 
  4274.                                   different countries. It is defined in 
  4275.                                   LOCALE.H.
  4276.  
  4277. %@AB@%onexit_t%@AE@%                          The %@AB@%onexit%@AE@% routine is declared as an %@AB@%%@AE@%
  4278.                                   %@AB@%onexit_t%@AE@% pointer type, which is defined 
  4279.                                   in STDLIB.H.
  4280.  
  4281. %@AB@%ptrdiff_t%@AE@%                         The %@AB@%ptrdiff_t%@AE@% type is used for the 
  4282.                                   signed integral result of the 
  4283.                                   subtraction of two pointers.
  4284.  
  4285. %@AB@%REGS%@AE@%                              The %@AB@%REGS %@AE@%union, defined in DOS.H, stores
  4286.                                   byte and word register values to be 
  4287.                                   passed to and returned from calls to the
  4288.                                   DOS interface functions. %@CR:C6A00030096 @%%@CR:C6A00030097 @%
  4289.  
  4290. %@AB@%sig_atomic_t%@AE@%                      The %@AB@%sig_atomic_t%@AE@% type, defined in 
  4291.                                   SIGNAL.H, is the integral type of an 
  4292.                                   object that can be modified as an atomic
  4293.                                   entity, even in the presence of 
  4294.                                   asynchronous interrupts. It is used in 
  4295.                                   conjunction with the %@AB@%signal%@AE@% routine.
  4296.  
  4297. %@AB@%size_t%@AE@%                            The %@AB@%size_t%@AE@% type, defined in STDDEF.H and
  4298.                                   several other include files, is the 
  4299.                                   unsigned integral result of the %@AB@%sizeof%@AE@% 
  4300.                                   operator. %@CR:C6A00030098 @%%@CR:C6A00030099 @%
  4301.  
  4302. %@AB@%SREGS%@AE@%                             The %@AB@%SREGS%@AE@% structure, defined in DOS.H, 
  4303.                                   stores the values of the ES, CS, SS, and
  4304.                                   DS registers. This structure is used by 
  4305.                                   the DOS interface functions that require
  4306.                                   segment register values (%@AB@%int86x%@AE@%, %@AB@%intdosx%@AE@%
  4307.                                   , and %@AB@%segread%@AE@%). %@CR:C6A00030100 @%%@CR:C6A00030101 @%
  4308.  
  4309. %@AB@%stat%@AE@%                              The %@AB@%stat%@AE@% structure, defined in 
  4310.                                   SYS\STAT.H, contains file-status 
  4311.                                   information returned by the %@AB@%stat%@AE@% and %@AB@%%@AE@%
  4312.                                   %@AB@%fstat%@AE@% routines. %@CR:C6A00030102 @%
  4313.  
  4314. %@AB@%time_t%@AE@%                            The %@AB@%time_t%@AE@% type, defined in TIME.H, 
  4315.                                   represents time values in the %@AB@%mktime%@AE@% and
  4316.                                   %@AB@%time%@AE@% routines. %@CR:C6A00030103 @%%@CR:C6A00030104 @%
  4317.  
  4318. %@AB@%timeb%@AE@%                             The %@AB@%timeb%@AE@% structure, defined in 
  4319.                                   SYS\TIMEB.H, is used by the %@AB@%ftime%@AE@% 
  4320.                                   routine to store the current system 
  4321.                                   time. %@CR:C6A00030105 @%%@CR:C6A00030106 @%
  4322.  
  4323. %@AB@%tm%@AE@%                                The %@AB@%tm%@AE@% structure, defined in TIME.H, is 
  4324.                                   used by the %@AB@%asctime%@AE@%, %@AB@%gmtime%@AE@%, and %@AB@%%@AE@%
  4325.                                   %@AB@%localtime%@AE@% functions to store and 
  4326.                                   retrieve time information. %@CR:C6A00030107 @%%@CR:C6A00030108 @%
  4327.  
  4328. %@AB@%utimbuf%@AE@%                           The %@AB@%utimbuf%@AE@% structure, defined in 
  4329.                                   SYS\UTIME.H, stores file access and 
  4330.                                   modification times used by the %@AB@%utime%@AE@% 
  4331.                                   function to change file-modification 
  4332.                                   dates. %@CR:C6A00030109 @%%@CR:C6A00030110 @%
  4333.  
  4334. %@AB@%va_list%@AE@%                           The %@AB@%va_list%@AE@% array type, defined in 
  4335.                                   STDARG.H, is used to hold information 
  4336.                                   needed by the %@AB@%va_arg%@AE@% macro and the %@AB@%%@AE@%
  4337.                                   %@AB@%va_end%@AE@% routine. The called function 
  4338.                                   declares a variable of type %@AB@%va_list%@AE@%, 
  4339.                                   which may be passed as an argument to 
  4340.                                   another function. %@CR:C6A00030111 @%%@CR:C6A00030112 @% 
  4341.  
  4342. %@NL@%
  4343. %@NL@%
  4344. %@NL@%
  4345. %@NL@%
  4346. %@NL@%
  4347. %@CR:C6A-Part 02 @%%@1@%%@AB@%PART II  Run-Time Functions%@AE@%%@EH@%%@NL@%
  4348. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4349. %@NL@%
  4350. The second part of this book is the reference section. It describes, in
  4351. alphabetical order, each function of the run-time library provided with the
  4352. Microsoft C Professional Development System.  %@NL@%
  4353. %@NL@%
  4354. Each reference entry gives syntax, return values, and other useful
  4355. information about the library functions. Information on compatibility is
  4356. supplied to assist you in writing portable programs.  %@NL@%
  4357. %@NL@%
  4358. %@NL@%
  4359. %@2@%%@CR:C6A00030113 @%%@AB@%About the Run-Time Reference%@AE@%%@EH@%%@NL@%
  4360. %@NL@%
  4361. The following pages describe, in alphabetical order, the more than 400
  4362. functions in the Microsoft run-time library. In some cases, related routines
  4363. are clustered in the same description. For example, the based, near, and far
  4364. versions of %@AB@%_heapwalk %@AE@%are in the same discussion, as are the regular and
  4365. long double versions of the math functions, such as %@AB@%acos%@AE@% and %@AB@%atan%@AE@%.
  4366. Differences are noted where appropriate. Refer to Chapter 2, "Run-Time
  4367. Routines by Category," or to the index to locate any function that does not
  4368. appear in the expected position within the alphabetical reference.  %@NL@%
  4369. %@NL@%
  4370. The discussion of each function (or group of functions) is divided into the
  4371. following sections:  %@NL@%
  4372. %@NL@%
  4373. %@NL@%
  4374.   ■   %@AB@%%@AE@%%@AI@%Description%@AE@%. Summarizes the routine's effect, names the include
  4375.       file(s) containing its declaration, illustrates the syntax, and
  4376.       briefly describes the arguments.%@NL@%
  4377. %@NL@%
  4378.   ■   %@AB@%%@AE@%%@AI@%Remarks%@AE@%. Gives a more detailed description of the routine and how it
  4379.       is used.%@NL@%
  4380. %@NL@%
  4381.   ■   %@AB@%%@AE@%%@AI@%Return Value%@AE@%. Describes the value returned by the routine.%@NL@%
  4382. %@NL@%
  4383.   ■   %@AB@%%@AE@%%@AI@%Compatibility.%@AE@% Tells whether the routine is compatible with ANSI C,
  4384.       MS-DOS, OS/2, UNIX, and XENIX.%@NL@%
  4385. %@NL@%
  4386.   ■   %@AB@%%@AE@%%@AI@%See Also%@AE@%. Names related routines.%@NL@%
  4387. %@NL@%
  4388.   ■   %@AB@%%@AE@%%@AI@%Example%@AE@%. Gives a complete program showing the use of the routine. %@NL@%
  4389. %@NL@%
  4390. %@NL@%
  4391. %@NL@%
  4392. %@NL@%
  4393. %@NL@%
  4394. %@QR:abort@%%@NL@%
  4395. %@2@%%@CR:C6A00050114 @%%@AB@%abort%@AE@%%@EH@%%@NL@%
  4396. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4397. %@NL@%
  4398. %@NL@%
  4399. %@3@%%@AB@%Description%@CR:C6A00050115 @%%@CR:C6A00050116 @%%@AE@%%@EH@%%@NL@%
  4400. %@NL@%
  4401. Aborts the current process and returns an error code.  %@NL@%
  4402. %@NL@%
  4403. %@AB@%#include <process.h>%@AE@%              Required only for function declarations;
  4404. %@AB@%#include <stdlib.h>%@AE@%               use either PROCESS.H or STDLIB.H
  4405.  
  4406. %@AS@%  void abort( void );%@AE@%%@NL@%
  4407. %@NL@%
  4408. %@NL@%
  4409. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4410. %@NL@%
  4411. The %@AB@%abort%@AE@% function prints the message  %@NL@%
  4412. %@NL@%
  4413. %@AS@%  abnormal program termination%@AE@%%@NL@%
  4414. %@NL@%
  4415. to %@AB@%stderr%@AE@%, then calls %@AB@%raise(SIGABRT)%@AE@%. The action taken in response to the
  4416. %@AB@%SIGABRT%@AE@% signal depends on what action has been defined for that signal in a
  4417. prior call to the %@AB@%signal%@AE@% function. The default %@AB@%SIGABRT%@AE@% action is for the
  4418. calling process to terminate with exit code 3, returning control to the
  4419. parent process or operating system.  %@NL@%
  4420. %@NL@%
  4421. The %@AB@%abort%@AE@% function does not flush stream buffers or do %@AB@%atexit%@AE@%/%@AB@%onexit%@AE@%
  4422. processing.  %@NL@%
  4423. %@NL@%
  4424. %@NL@%
  4425. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  4426. %@NL@%
  4427. The %@AB@%abort%@AE@% function does not return control to the caller. Rather, it
  4428. terminates the process and, by default, returns an exit code of 3 to the
  4429. parent process.  %@NL@%
  4430. %@NL@%
  4431. %@NL@%
  4432. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  4433. %@NL@%
  4434. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  4435. %@NL@%
  4436. %@NL@%
  4437. In multithread libraries, the %@AB@%abort %@AE@%function does not call %@AB@%raise%@AE@%(%@AB@%SIGABRT)%@AE@%.
  4438. Instead, it simply terminates the process with exit code 3.  %@NL@%
  4439. %@NL@%
  4440. %@NL@%
  4441. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  4442. %@NL@%
  4443. %@AB@%exec%@AE@% functions, %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, %@AB@%raise%@AE@%, %@AB@%signal%@AE@%, %@AB@%spawn%@AE@% functions  %@NL@%
  4444. %@NL@%
  4445. %@NL@%
  4446. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  4447. %@NL@%
  4448. %@AS@%  /* ABORT.C:  This tries to open a file and aborts if the attempt fails. */
  4449. %@AS@%  
  4450. %@AS@%  #include <stdio.h>
  4451. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  4452. %@NL@%
  4453. %@AS@%  void main()
  4454. %@AS@%  {
  4455. %@AS@%  
  4456. %@AS@%     FILE *stream;
  4457. %@AS@%  
  4458. %@AS@%     if( (stream = fopen( "NOSUCHF.ILE", "r" )) == NULL )
  4459. %@AS@%     {
  4460. %@AS@%        perror( "Couldn't open file" );
  4461. %@AS@%        abort();
  4462. %@AS@%     }
  4463. %@AS@%     else
  4464. %@AS@%        fclose( stream );
  4465. %@AS@%  }%@AE@%%@NL@%
  4466. %@NL@%
  4467. %@NL@%
  4468. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  4469. %@NL@%
  4470. %@AS@%  
  4471. %@AS@%  
  4472. %@AS@%  Couldn't open file: No such file or directory
  4473. %@AS@%  
  4474. %@AS@%  abnormal program termination
  4475. %@AS@%  %@AE@%%@NL@%
  4476. %@NL@%
  4477. %@NL@%
  4478. %@NL@%
  4479. %@NL@%
  4480. %@QR:abs@%%@NL@%
  4481. %@2@%%@CR:C6A00060117 @%%@AB@%abs%@AE@%%@EH@%%@NL@%
  4482. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4483. %@NL@%
  4484. %@NL@%
  4485. %@3@%%@AB@%Description%@CR:C6A00060118 @%%@CR:C6A00060119 @%%@AE@%%@EH@%%@NL@%
  4486. %@NL@%
  4487. Calculates the absolute value.  %@NL@%
  4488. %@NL@%
  4489. %@AB@%#include <stdlib.h>%@AE@%%@AB@%%@AE@%               Required only for function declarations;
  4490. %@AB@%#include <math.h>%@AE@%                 use either STDLIB.H or MATH.H
  4491.  
  4492. %@AS@%  int abs( int n );%@AE@%%@NL@%
  4493. %@NL@%
  4494. %@AI@%n%@AE@%                                 Integer value
  4495.  
  4496. %@NL@%
  4497. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4498. %@NL@%
  4499. The %@AB@%abs%@AE@% function returns the absolute value of its integer argument %@AI@%n%@AE@%.  %@NL@%
  4500. %@NL@%
  4501. %@NL@%
  4502. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  4503. %@NL@%
  4504. The %@AB@%abs%@AE@% function returns the absolute value of its argument. There is no
  4505. error return.  %@NL@%
  4506. %@NL@%
  4507. %@NL@%
  4508. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  4509. %@NL@%
  4510. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  4511. %@NL@%
  4512. %@NL@%
  4513. %@NL@%
  4514. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  4515. %@NL@%
  4516. %@AB@%cabs%@AE@%, %@AB@%fabs%@AE@%, %@AB@%labs%@AE@%  %@NL@%
  4517. %@NL@%
  4518. %@NL@%
  4519. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  4520. %@NL@%
  4521. %@AS@%  /* ABS.C: This program computes and displays the absolute values of
  4522. %@AS@%   * several numbers.
  4523. %@AS@%   */
  4524. %@AS@%  
  4525. %@AS@%  #include <stdio.h>
  4526. %@AS@%  #include <math.h>
  4527. %@AS@%  #include <stdlib.h>
  4528. %@AS@%  
  4529. %@AS@%  void main()
  4530. %@AS@%  {
  4531. %@AS@%     int    ix = -4, iy;
  4532. %@AS@%     long   lx = -41567L, ly;
  4533. %@AS@%     double dx = -3.141593, dy;
  4534. %@AS@%  
  4535. %@AS@%     iy = abs( ix );
  4536. %@AS@%     printf( "The absolute value of %d is %d\n", ix, iy);
  4537. %@AS@%  
  4538. %@AS@%     ly = labs( lx );
  4539. %@AS@%     printf( "The absolute value of %ld is %ld\n", lx, ly);
  4540. %@AS@%  
  4541. %@AS@%     dy = fabs( dx );
  4542. %@AS@%     printf( "The absolute value of %f is %f\n", dx, dy );
  4543. %@AS@%  }%@AE@%%@NL@%
  4544. %@NL@%
  4545. %@NL@%
  4546. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  4547. %@NL@%
  4548. %@AS@%  
  4549. %@AS@%  
  4550. %@AS@%  The absolute value of -4 is 4
  4551. %@AS@%  The absolute value of -41567 is 41567
  4552. %@AS@%  The absolute value of -3.141593 is 3.141593 %@AE@%%@NL@%
  4553. %@NL@%
  4554. %@NL@%
  4555. %@NL@%
  4556. %@NL@%
  4557. %@QR:access@%%@NL@%
  4558. %@2@%%@CR:C6A00070120 @%%@AB@%access%@AE@%%@EH@%%@NL@%
  4559. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4560. %@NL@%
  4561. %@NL@%
  4562. %@3@%%@AB@%Description%@CR:C6A00070121 @%%@CR:C6A00070122 @%%@AE@%%@EH@%%@NL@%
  4563. %@NL@%
  4564. Determines file-access permission.  %@NL@%
  4565. %@NL@%
  4566. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  4567.  
  4568. %@AB@%#include <errno.h>%@AE@%                Required for definition of %@AB@%errno%@AE@% 
  4569.                                   constants
  4570.  
  4571. %@AS@%  int access( char *pathname, int mode );%@AE@%%@NL@%
  4572. %@NL@%
  4573. %@AI@%pathname%@AE@%                          File or directory path name
  4574.  
  4575. %@AI@%mode%@AE@%                              Permission setting
  4576.  
  4577. %@NL@%
  4578. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4579. %@NL@%
  4580. With files, the %@AB@%access%@AE@% function determines whether the specified file exists
  4581. and can be accessed in %@AI@%mode%@AE@%. The possible mode values and their meanings in
  4582. the %@AB@%access%@AE@% call are as follows: %@CR:C6A00070123 @%  %@NL@%
  4583. %@NL@%
  4584. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  4585. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4586. 00                                Check for existence only
  4587.  
  4588. 02                                Check for write permission
  4589.  
  4590. 04                                Check for read permission
  4591.  
  4592. 06                                Check for read and write permission
  4593.  
  4594. With directories, %@AB@%access%@AE@% determines only whether the specified directory
  4595. exists; under DOS and OS/2, all directories have read and write access.  %@NL@%
  4596. %@NL@%
  4597. %@NL@%
  4598. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  4599. %@NL@%
  4600. The %@AB@%access%@AE@% function returns the value 0 if the file has the given mode. A
  4601. return value of -1 indicates that the named file does not exist or is not
  4602. accessible in the given mode, and %@AB@%errno%@AE@% is set to one of the following
  4603. values:  %@NL@%
  4604. %@NL@%
  4605. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  4606. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4607. %@AB@%EACCES%@AE@%                            Access denied: the file's permission 
  4608.                                   setting does not allow the specified 
  4609.                                   access.
  4610.  
  4611. %@AB@%ENOENT%@AE@%                            File or path name not found.
  4612.  
  4613. %@NL@%
  4614. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  4615. %@NL@%
  4616.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  4617. %@NL@%
  4618. %@NL@%
  4619. %@NL@%
  4620. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  4621. %@NL@%
  4622. %@AB@%chmod%@AE@%, %@AB@%fstat%@AE@%, %@AB@%open%@AE@%, %@AB@%stat%@AE@%  %@NL@%
  4623. %@NL@%
  4624. %@NL@%
  4625. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  4626. %@NL@%
  4627. %@AS@%  /* ACCESS.C: This example uses access to check the file named "data"
  4628. %@AS@%   * to see if it exists and if writing is allowed.
  4629. %@AS@%   */
  4630. %@AS@%  
  4631. %@AS@%  #include <io.h>
  4632. %@AS@%  #include <stdio.h>
  4633. %@AS@%  #include <stdlib.h>
  4634. %@AS@%  
  4635. %@AS@%  void main()
  4636. %@AS@%  {
  4637. %@AS@%     /* Check for existence */
  4638. %@AS@%     if( (access( "access.c", 0 )) != -1 )
  4639. %@AS@%     {
  4640. %@AS@%        printf( "File exists\n" );
  4641. %@AS@%  
  4642. %@AS@%        /* Check for write permission */
  4643. %@AS@%        if( (access( "access.c", 2 )) != -1 )
  4644. %@AS@%           printf( "File has write permission\n" );
  4645. %@AS@%     }
  4646. %@AS@%  }%@AE@%%@NL@%
  4647. %@NL@%
  4648. %@NL@%
  4649. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  4650. %@NL@%
  4651. %@AS@%  
  4652. %@AS@%  
  4653. %@AS@%  File exists
  4654. %@AS@%  File has write permission%@AE@%%@NL@%
  4655. %@NL@%
  4656. %@NL@%
  4657. %@NL@%
  4658. %@NL@%
  4659. %@QR:acos@%%@NL@%
  4660. %@2@%%@CR:C6A00080124 @%%@AB@%acos Functions%@AE@%%@EH@%%@NL@%
  4661. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4662. %@NL@%
  4663. %@NL@%
  4664. %@3@%%@AB@%Description%@CR:C6A00080125 @%%@CR:C6A00080126 @% %@CR:C6A00080127 @%%@CR:C6A00080128 @%%@CR:C6A00080129 @%%@CR:C6A00080130 @%%@AE@%%@EH@%%@NL@%
  4665. %@NL@%
  4666. Calculate the arccosine.  %@NL@%
  4667. %@NL@%
  4668. %@AB@%#include <math.h>%@AE@%  %@NL@%
  4669. %@NL@%
  4670. %@AB@%#include <errno.h>%@AE@%                Required for definition of %@AB@%errno%@AE@% 
  4671.                                   constant
  4672.  
  4673. %@AS@%  double acos( double x );%@AE@%%@NL@%
  4674. %@NL@%
  4675. %@AS@%  long double acosl( long double x );%@AE@%%@NL@%
  4676. %@NL@%
  4677. %@AI@%x%@AE@%                                 Value whose arccosine is to be 
  4678.                                   calculated
  4679.  
  4680. %@NL@%
  4681. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4682. %@NL@%
  4683. The %@AB@%acos%@AE@% functions return the arccosine of %@AI@%x%@AE@% in the range 0 to π radians.
  4684. The value of %@AI@%x%@AE@% must be between -1 and 1. The %@AB@%acosl%@AE@% function is the 80-bit
  4685. counterpart, which uses an 80-bit, 10-byte coprocessor form of arguments and
  4686. return values. See the reference page on the long double functions for more
  4687. details on this data type.  %@NL@%
  4688. %@NL@%
  4689. %@NL@%
  4690. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  4691. %@NL@%
  4692. The %@AB@%acos%@AE@% functions return the arccosine result. If %@AI@%x%@AE@% is less than -1 or
  4693. greater than 1, the function sets %@AB@%errno%@AE@% to %@AB@%EDOM%@AE@%, prints a %@AB@%DOMAIN %@AE@%error
  4694. message to %@AB@%stderr%@AE@%, and returns 0. Error handling can be modified with the
  4695. %@AB@%matherr%@AE@% (or %@AB@%_matherrl%@AE@%) routine.  %@NL@%
  4696. %@NL@%
  4697. %@NL@%
  4698. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  4699. %@NL@%
  4700. %@AB@%acos%@AE@%  %@NL@%
  4701. %@NL@%
  4702. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  4703. %@NL@%
  4704. %@NL@%
  4705. %@AB@%acosl%@AE@%  %@NL@%
  4706. %@NL@%
  4707.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  4708. %@NL@%
  4709. %@NL@%
  4710. %@NL@%
  4711. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  4712. %@NL@%
  4713. %@AB@%asin%@AE@% functions, %@AB@%atan%@AE@% functions, %@AB@%cos%@AE@% functions, %@AB@%matherr%@AE@%, %@AB@%sin%@AE@% functions, %@AB@%tan%@AE@%
  4714. functions  %@NL@%
  4715. %@NL@%
  4716. %@NL@%
  4717. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  4718. %@NL@%
  4719. %@AS@%  /* ASINCOS.C: This program prompts for a value in the range -1 to 1.
  4720. %@AS@%   * Input values outside this range will produce DOMAIN error messages.
  4721. %@AS@%   * If a valid value is entered, the program prints the arcsine and the
  4722. %@AS@%   * arccosine of that value.
  4723. %@AS@%   */
  4724. %@AS@%  
  4725. %@AS@%  #include <math.h>
  4726. %@AS@%  #include <stdio.h>
  4727. %@AS@%  #include <stdlib.h>
  4728. %@AS@%  #include <errno.h>
  4729. %@AS@%  
  4730. %@AS@%  void main()
  4731. %@AS@%  {
  4732. %@AS@%     double x, y;
  4733. %@AS@%  
  4734. %@AS@%     printf( "Enter a real number between -1 and 1: " );
  4735. %@AS@%     scanf( "%lf", &x );
  4736. %@AS@%     y = asin( x );
  4737. %@AS@%     printf( "Arcsine of %f = %f\n", x, y );
  4738. %@AS@%     y = acos( x );
  4739. %@AS@%     printf( "Arccosine of %f = %f\n", x, y );
  4740. %@AS@%  }%@AE@%%@NL@%
  4741. %@NL@%
  4742. %@NL@%
  4743. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  4744. %@NL@%
  4745. %@AS@%  
  4746. %@AS@%  
  4747. %@AS@%  Enter a real number between -1 and 1: .32696
  4748. %@AS@%  Arcsine of 0.326960 = 0.333085
  4749. %@AS@%  Arccosine of 0.326960 = 1.237711%@AE@%%@NL@%
  4750. %@NL@%
  4751. %@NL@%
  4752. %@NL@%
  4753. %@NL@%
  4754. %@QR:alloca@%%@NL@%
  4755. %@2@%%@CR:C6A00090131 @%%@AB@%alloca%@AE@%%@EH@%%@NL@%
  4756. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4757. %@NL@%
  4758. %@NL@%
  4759. %@3@%%@AB@%Description%@CR:C6A00090132 @%%@AE@%%@EH@%%@NL@%
  4760. %@NL@%
  4761. Allocates memory on the stack.  %@NL@%
  4762. %@NL@%
  4763. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  4764.  
  4765. %@AS@%  void *alloca( size_t size );%@AE@%%@NL@%
  4766. %@NL@%
  4767. %@AI@%size%@AE@%                              Bytes to be allocated from stack
  4768.  
  4769. %@NL@%
  4770. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4771. %@NL@%
  4772. The %@AB@%alloca%@AE@% routine allocates %@AI@%size%@AE@% bytes from the program's stack. The
  4773. allocated space is automatically freed when the calling function is exited.
  4774. %@NL@%
  4775. %@NL@%
  4776. When you compile with optimization on (either by default or by using one of
  4777. the /O options), the stack pointer may not be restored properly in functions
  4778. that have no local variables and that also reference the %@AB@%alloca%@AE@% function.
  4779. The following program demonstrates the problem:  %@NL@%
  4780. %@NL@%
  4781. %@AS@%  /* Compile with CL /Lp /AM /Ox /Fc */
  4782. %@AS@%  #include <malloc.h>
  4783. %@AS@%  
  4784. %@AS@%  void main( void )
  4785. %@AS@%  {
  4786. %@AS@%     func( 10 );
  4787. %@AS@%  }
  4788. %@AS@%  void func( register int i )
  4789. %@AS@%  {
  4790. %@AS@%     alloca( i );
  4791. %@AS@%  }%@AE@%%@NL@%
  4792. %@NL@%
  4793. To ensure that the stack pointer is properly restored, make sure that any
  4794. function referencing %@AB@%alloca%@AE@% declares at least one local variable.  %@NL@%
  4795. %@NL@%
  4796. The pointer value returned by %@AB@%alloca%@AE@% should never be passed as an argument
  4797. to %@AB@%free%@AE@%, nor should %@AB@%alloca%@AE@% be used in an expression that is an argument to a
  4798. function.  %@NL@%
  4799. %@NL@%
  4800. %@NL@%
  4801. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  4802. %@NL@%
  4803. The %@AB@%alloca%@AE@% routine returns a %@AB@%void%@AE@% pointer to the allocated space, which is
  4804. guaranteed to be suitably aligned for storage of any type of object. To get
  4805. a pointer to a type other than %@AB@%char%@AE@%, use a type cast on the return value.
  4806. The return value is %@AB@%NULL%@AE@% if the space cannot be allocated.  %@NL@%
  4807. %@NL@%
  4808. %@NL@%
  4809. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  4810. %@NL@%
  4811.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX   XENIX%@NL@%
  4812. %@NL@%
  4813. %@NL@%
  4814. %@NL@%
  4815. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  4816. %@NL@%
  4817. %@AB@%calloc%@AE@% functions, %@AB@%malloc%@AE@% functions, %@AB@%realloc%@AE@% functions  %@NL@%
  4818. %@NL@%
  4819. %@NL@%
  4820. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  4821. %@NL@%
  4822. %@AS@%  /* ALLOCA.C: This program checks the stack space available before
  4823. %@AS@%   * and after using the alloca function to allocate space on the stack.
  4824. %@AS@%   */
  4825. %@AS@%  
  4826. %@AS@%  #include <malloc.h>
  4827. %@AS@%  #include <stdio.h>
  4828. %@AS@%  
  4829. %@AS@%  void main()
  4830. %@AS@%  {
  4831. %@AS@%     char *buffer;
  4832. %@AS@%  
  4833. %@AS@%     printf( "Bytes available on stack: %u\n", stackavail() );
  4834. %@AS@%  
  4835. %@AS@%     /* Allocate memory for string. */
  4836. %@AS@%     buffer = alloca( 120 * sizeof( char ) );
  4837. %@AS@%     printf( "Enter a string: " );
  4838. %@AS@%     gets( buffer );
  4839. %@AS@%     printf( "You entered: %s\n", buffer );
  4840. %@AS@%  
  4841. %@AS@%     printf( "Bytes available on stack: %u\n", stackavail() );
  4842. %@AS@%  }%@AE@%%@NL@%
  4843. %@NL@%
  4844. %@NL@%
  4845. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  4846. %@NL@%
  4847. %@AS@%  
  4848. %@AS@%  
  4849. %@AS@%  Bytes available on stack: 2028
  4850. %@AS@%  Enter a string: How much stack space will this string take?
  4851. %@AS@%  You entered: How much stack space will this string take?
  4852. %@AS@%  Bytes available on stack: 1902%@AE@%%@NL@%
  4853. %@NL@%
  4854. %@NL@%
  4855. %@NL@%
  4856. %@NL@%
  4857. %@QR:_arc@%%@NL@%
  4858. %@2@%%@CR:C6A00100133 @%%@AB@%_arc Functions%@AE@%%@EH@%%@NL@%
  4859. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4860. %@NL@%
  4861. %@NL@%
  4862. %@3@%%@AB@%Description%@CR:C6A00100134 @%%@CR:C6A00100135 @%%@AE@%%@EH@%%@NL@%
  4863. %@NL@%
  4864. Draw elliptical arcs.  %@NL@%
  4865. %@NL@%
  4866. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  4867. %@NL@%
  4868. %@AS@%  short _far _arc( short x1, short y1, short x2, short y2, short x3, 
  4869. %@AS@%    short y3, short x4, short y4 );%@AE@%%@NL@%
  4870. %@NL@%
  4871. %@AS@%  short _far _arc_w( double x1, double y1, double x2, double y2, double x3, 
  4872. %@AS@%    double y3, double x4, double y4 );%@AE@%%@NL@%
  4873. %@NL@%
  4874. %@AS@%  short _far _arc_wxy( struct _wxycoord _far *pwxy1, 
  4875. %@AS@%    struct _wxycoord _far *pwxy2, 
  4876. %@AS@%    struct _wxycoord _far *pwxy3, struct _wxycoord _far *pwxy4);%@AE@%%@NL@%
  4877. %@NL@%
  4878. %@AI@%x1%@AE@%, %@AI@%y1%@AE@%                            Upper-left corner of bounding rectangle
  4879.  
  4880. %@AI@%x2%@AE@%, %@AI@%y2%@AE@%                            Lower-right corner of bounding rectangle
  4881.  
  4882. %@AI@%x3%@AE@%, %@AI@%y3%@AE@%                            Second point of start vector (center of 
  4883.                                   bounding rectangle is first point)
  4884.  
  4885. %@AI@%x4%@AE@%, %@AI@%y4%@AE@%                            Second point of end vector (center of 
  4886.                                   bounding rectangle is first point)
  4887.  
  4888. %@AI@%pwxy1%@AE@%                             Upper-left corner of bounding rectangle
  4889.  
  4890. %@AI@%pwxy2%@AE@%                             Lower-right corner of bounding rectangle
  4891.  
  4892. %@AI@%pwxy3%@AE@%                             Second point of start vector (center of 
  4893.                                   bounding rectangle is first point)
  4894.  
  4895. %@AI@%pwxy4%@AE@%                             Second point of end vector (center of 
  4896.                                   bounding rectangle is first point)
  4897.  
  4898. %@NL@%
  4899. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4900. %@NL@%
  4901. The %@AB@%_arc%@AE@% functions draw elliptical arcs. The center of the arc is the center
  4902. of the bounding rectangle, which is defined by points (%@AI@%x1%@AE@%, %@AI@%y1%@AE@%) and (%@AI@%x2%@AE@%,%@AI@% y2%@AE@%)
  4903. for%@AB@% _arc%@AE@% and %@AB@%_arc_w%@AE@% and by points%@AB@% %@AE@%%@AI@%pwxy1%@AE@% and %@AI@%pwxy2%@AE@% for%@AB@% _arc_wxy%@AE@%. The arc
  4904. starts where it intersects an imaginary line extending from the center of
  4905. the arc through (%@AI@%x3%@AE@%,%@AI@% y3%@AE@%) for %@AB@%_arc%@AE@% and%@AB@% _arc_w%@AE@% and through %@AI@%pwxy3%@AE@% for %@AB@%_arc_wxy%@AE@%.
  4906. It is drawn counterclockwise about the center of the arc, ending where it
  4907. intersects an imaginary line extending from the center of the arc through
  4908. (%@AI@%x4%@AE@%,%@AI@% y4%@AE@%) for %@AB@%_arc %@AE@% and %@AB@%_arc_w%@AE@% and through %@AI@%pwxy4%@AE@% for %@AB@%_arc_wxy%@AE@%.  %@NL@%
  4909. %@NL@%
  4910. The %@AB@%_arc%@AE@% routine uses the view coordinate system. The %@AB@%_arc_w%@AE@% and %@AB@%_arc_wxy%@AE@%
  4911. functions use the real-valued window coordinate system.  %@NL@%
  4912. %@NL@%
  4913. In each case, the arc is drawn using the current color. Since an arc does
  4914. not define a closed area, it is not filled.  %@NL@%
  4915. %@NL@%
  4916. %@NL@%
  4917. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  4918. %@NL@%
  4919. These functions return a nonzero value if the arc is successfully drawn;
  4920. otherwise, they return 0.  %@NL@%
  4921. %@NL@%
  4922. %@NL@%
  4923. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  4924. %@NL@%
  4925.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  4926. %@NL@%
  4927. %@NL@%
  4928. %@NL@%
  4929. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  4930. %@NL@%
  4931. %@AB@%_ellipse%@AE@% functions, %@AB@% _lineto%@AE@% functions, %@AB@% _pie%@AE@% functions, %@AB@% _rectangle%@AE@%
  4932. functions,  %@AB@%_setcolor%@AE@%  %@NL@%
  4933. %@NL@%
  4934. %@NL@%
  4935. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  4936. %@NL@%
  4937. %@AS@%  /* ARC.C: This program draws a simple arc. */
  4938. %@AS@%  
  4939. %@AS@%  #include <graph.h>
  4940. %@AS@%  #include <stdlib.h>
  4941. %@AS@%  #include <conio.h>
  4942. %@AS@%  
  4943. %@AS@%  void main()
  4944. %@AS@%  {
  4945. %@AS@%     short x, y;
  4946. %@AS@%     struct xycoord xystart, xyend, xyfill;
  4947. %@AS@%  
  4948. %@AS@%     /* Find a valid graphics mode */
  4949. %@AS@%     if( !_setvideomode( _MAXRESMODE ) )
  4950. %@AS@%        exit( 1 );
  4951. %@AS@%  
  4952. %@AS@%     /* Draw arcs         */
  4953. %@AS@%     x = 100; y = 100;
  4954. %@AS@%     _arc( x - 60, y - 60, x, y, x - 30, y - 60, x - 60, y - 30 );
  4955. %@AS@%     _arc( x + 60, y + 60, x, y, x,      y + 30, x + 30, y );
  4956. %@AS@%  
  4957. %@AS@%     /* Get endpoints of second arc and enclose the figure, then fill it. */
  4958. %@AS@%     _getarcinfo( &xystart, &xyend, &xyfill );
  4959. %@AS@%     _moveto( xystart.xcoord, xystart.ycoord );
  4960. %@AS@%     _lineto( xyend.xcoord,   xyend.ycoord );
  4961. %@AS@%     _floodfill( xyfill.xcoord, xyfill.ycoord, _getcolor() );
  4962. %@AS@%  
  4963. %@AS@%     getch();
  4964. %@AS@%     _setvideomode( _DEFAULTMODE );
  4965. %@AS@%  }%@AE@%%@NL@%
  4966. %@NL@%
  4967. %@NL@%
  4968. %@NL@%
  4969. %@NL@%
  4970. %@QR:asctime@%%@NL@%
  4971. %@2@%%@CR:C6A00110136 @%%@AB@%asctime%@AE@%%@EH@%%@NL@%
  4972. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4973. %@NL@%
  4974. %@NL@%
  4975. %@3@%%@AB@%Description%@CR:C6A00110137 @%%@CR:C6A00110138 @%%@AE@%%@EH@%%@NL@%
  4976. %@NL@%
  4977. Converts a %@AB@%tm%@AE@% time structure to a character string.  %@NL@%
  4978. %@NL@%
  4979. %@AS@%  #include <time.h>%@AE@%%@NL@%
  4980. %@NL@%
  4981. %@AS@%  char *asctime( const struct tm *timeptr );%@AE@%%@NL@%
  4982. %@NL@%
  4983. %@AI@%timeptr%@AE@%                           Time/date structure
  4984.  
  4985. %@NL@%
  4986. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  4987. %@NL@%
  4988. The %@AB@%asctime%@AE@% function converts a time stored as a structure to a character
  4989. string. The %@AI@%timeptr%@AE@% value is usually obtained from a call to %@AB@%gmtime%@AE@% or
  4990. %@AB@%localtime%@AE@%, both of which return a pointer to a %@AB@%tm%@AE@% structure, defined in
  4991. TIME.H. (See %@AB@%gmtime%@AE@% for a complete description of the %@AB@%tm%@AE@% structure fields.) %@CR:C6A00110139 @%
  4992. %@NL@%
  4993. %@NL@%
  4994. The %@AB@%tm%@AE@% structure contains the following elements:  %@NL@%
  4995. %@NL@%
  4996. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  4997. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  4998. %@AB@%int tm_sec%@AE@%                        Seconds after the minute (0 -59)
  4999.  
  5000. %@AB@%int tm_min%@AE@%                        Minutes after the hour (0 -59)
  5001.  
  5002. %@AB@%int%@AE@% %@AB@%tm_hour%@AE@%                       Hours since midnight (0 -23)
  5003.  
  5004. %@AB@%int%@AE@% %@AB@%tm_mday%@AE@%                       Day of the month (0 -31)
  5005.  
  5006. %@AB@%int tm_mon%@AE@%                        Months since January (0 -11)
  5007.  
  5008. %@AB@%int tm_year%@AE@%                       Years since 1900
  5009.  
  5010. %@AB@%int tm_wday%@AE@%                       Days since Sunday (0 - 6)
  5011.  
  5012. %@AB@%int%@AE@% %@AB@%tm_yday%@AE@%                       Days since January 1 (0 -365)
  5013.  
  5014. %@AB@%int tm_isdst%@AE@%                      Daylight-saving-time flag
  5015.  
  5016. The string result produced by %@AB@%asctime%@AE@% contains exactly 26 characters and has
  5017. the form of the following example:  %@NL@%
  5018. %@NL@%
  5019. %@AS@%  Wed Jan 02 02:03:55 1980\n\0%@AE@%%@NL@%
  5020. %@NL@%
  5021. A 24-hour clock is used. All fields have a constant width. The newline
  5022. character (%@AB@%\n%@AE@%) and the null character (%@AB@%'\0'%@AE@%) occupy the last two positions
  5023. of the string. The %@AB@%asctime%@AE@% function uses a single statically allocated
  5024. buffer to hold the return string. Each call to this routine destroys the
  5025. result of the previous call.  %@NL@%
  5026. %@NL@%
  5027. %@NL@%
  5028. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5029. %@NL@%
  5030. The %@AB@%asctime%@AE@% function returns a pointer to the character string result. There
  5031. is no error return.  %@NL@%
  5032. %@NL@%
  5033. %@NL@%
  5034. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5035. %@NL@%
  5036. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  5037. %@NL@%
  5038. %@NL@%
  5039. %@NL@%
  5040. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5041. %@NL@%
  5042. %@AB@%ctime%@AE@%, %@AB@%ftime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%time%@AE@%, %@AB@%tzset%@AE@%  %@NL@%
  5043. %@NL@%
  5044. %@NL@%
  5045. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5046. %@NL@%
  5047. %@AS@%  /* ASCTIME.C: This program places the system time in the long integer
  5048. %@AS@%  aclock,
  5049. %@AS@%   * translates it into the structure newtime and then converts it to
  5050. %@AS@%   * string form for output, using the asctime function.
  5051. %@AS@%   */
  5052. %@AS@%  
  5053. %@AS@%  #include <time.h>
  5054. %@AS@%  #include <stdio.h>
  5055. %@AS@%  
  5056. %@AS@%  struct tm *newtime;
  5057. %@AS@%  time_t aclock;
  5058. %@AS@%  
  5059. %@AS@%  void main()
  5060. %@AS@%  {
  5061. %@AS@%     time( &aclock );                    /* Get time in seconds */
  5062. %@AS@%  
  5063. %@AS@%     newtime = localtime( &aclock );     /* Convert time to struct tm form
  5064. %@AS@%*/
  5065. %@AS@%  
  5066. %@AS@%     /* Print local time as a string */
  5067. %@AS@%     printf( "The current date and time are: %s\n", asctime( newtime ) );
  5068. %@AS@%  }%@AE@%%@NL@%
  5069. %@NL@%
  5070. %@NL@%
  5071. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5072. %@NL@%
  5073. %@AS@%  
  5074. %@AS@%  
  5075. %@AS@%  The current date and time are: Thu Jun 15 06:57:59 1989%@AE@%%@NL@%
  5076. %@NL@%
  5077. %@NL@%
  5078. %@NL@%
  5079. %@NL@%
  5080. %@QR:asin@%%@NL@%
  5081. %@2@%%@CR:C6A00120140 @%%@AB@%asin Functions%@AE@%%@EH@%%@NL@%
  5082. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5083. %@NL@%
  5084. %@NL@%
  5085. %@3@%%@AB@%Description%@CR:C6A00120141 @%%@CR:C6A00120142 @% %@CR:C6A00120143 @%%@CR:C6A00120144 @%%@CR:C6A00120145 @%%@CR:C6A00120146 @%%@AE@%%@EH@%%@NL@%
  5086. %@NL@%
  5087. Calculate the arcsine.  %@NL@%
  5088. %@NL@%
  5089. %@AS@%  #include <math.h>%@AE@%%@NL@%
  5090. %@NL@%
  5091. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  5092. %@NL@%
  5093. %@AS@%  double asin( double x );%@AE@%%@NL@%
  5094. %@NL@%
  5095. %@AS@%  long double asinl( long double x );%@AE@%%@NL@%
  5096. %@NL@%
  5097. %@AI@%x%@AE@%                                 Value whose arcsine is to be calculated
  5098.  
  5099. %@NL@%
  5100. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5101. %@NL@%
  5102. The %@AB@%asin%@AE@% functions calculate the arcsine of %@AI@%x%@AE@% in the range -π/2 to π/2
  5103. radians. The value of %@AI@%x%@AE@% must be between -1 and 1. The %@AB@%asinl%@AE@% function is the
  5104. 80-bit counterpart, which uses an 80-bit, 10-byte coprocessor form of
  5105. arguments and return values. See the reference page on the long double
  5106. functions for more details on this data type.  %@NL@%
  5107. %@NL@%
  5108. %@NL@%
  5109. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5110. %@NL@%
  5111. The %@AB@%asin%@AE@% functions return the arcsine result. If %@AI@%x%@AE@% is less than -1 or
  5112. greater than 1, %@AB@%asin%@AE@% sets %@AB@%errno%@AE@% to %@AB@%EDOM%@AE@%, prints a %@AB@%DOMAIN%@AE@% error message to
  5113. %@AB@%stderr%@AE@%, and returns 0.  %@NL@%
  5114. %@NL@%
  5115. Error handling can be modified by using the %@AB@%matherr%@AE@% (or %@AB@%_matherrl%@AE@%) routine.
  5116. %@NL@%
  5117. %@NL@%
  5118. %@NL@%
  5119. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5120. %@NL@%
  5121. %@AB@%asin%@AE@%  %@NL@%
  5122. %@NL@%
  5123. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  5124. %@NL@%
  5125. %@NL@%
  5126. %@AB@%asinl%@AE@%  %@NL@%
  5127. %@NL@%
  5128.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  5129. %@NL@%
  5130. %@NL@%
  5131. %@NL@%
  5132. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5133. %@NL@%
  5134. %@AB@%acos%@AE@% functions, %@AB@%atan%@AE@% functions, %@AB@%cos%@AE@% functions, %@AB@%matherr%@AE@%, %@AB@%sin%@AE@% functions,%@AB@% tan%@AE@%
  5135. functions  %@NL@%
  5136. %@NL@%
  5137. %@NL@%
  5138. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5139. %@NL@%
  5140. %@AS@%  /* ASINCOS.C: This program prompts for a value in the range -1 to 1.
  5141. %@AS@%   * Input values outside this range will produce DOMAIN error messages.
  5142. %@AS@%   * If a valid value is entered, the program prints the arcsine and the
  5143. %@AS@%   * arccosine of that value.
  5144. %@AS@%   */
  5145. %@AS@%  
  5146. %@AS@%  #include <math.h>
  5147. %@AS@%  #include <stdio.h>
  5148. %@AS@%  #include <stdlib.h>
  5149. %@AS@%  #include <errno.h>
  5150. %@AS@%  
  5151. %@AS@%  void main()
  5152. %@AS@%  {
  5153. %@AS@%     double x, y;
  5154. %@AS@%  
  5155. %@AS@%     printf( "Enter a real number between -1 and 1: " );
  5156. %@AS@%     scanf( "%lf", &x );
  5157. %@AS@%     y = asin( x );
  5158. %@AS@%     printf( "Arcsine of %f = %f\n", x, y );
  5159. %@AS@%     y = acos( x );
  5160. %@AS@%     printf( "Arccosine of %f = %f\n", x, y );
  5161. %@AS@%  }%@AE@%%@NL@%
  5162. %@NL@%
  5163. %@NL@%
  5164. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5165. %@NL@%
  5166. %@AS@%  
  5167. %@AS@%  
  5168. %@AS@%  Enter a real number between -1 and 1: .32696
  5169. %@AS@%  Arcsine of 0.326960 = 0.333085
  5170. %@AS@%  Arccosine of 0.326960 = 1.237711%@AE@%%@NL@%
  5171. %@NL@%
  5172. %@NL@%
  5173. %@NL@%
  5174. %@NL@%
  5175. %@QR:assert@%%@NL@%
  5176. %@2@%%@CR:C6A00130147 @%%@AB@%assert%@AE@%%@EH@%%@NL@%
  5177. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5178. %@NL@%
  5179. %@NL@%
  5180. %@3@%%@AB@%Description%@CR:C6A00130148 @%%@CR:C6A00130149 @%%@AE@%%@EH@%%@NL@%
  5181. %@NL@%
  5182. Prints an error message and aborts the program.  %@NL@%
  5183. %@NL@%
  5184. %@AB@%#include <assert.h>%@AE@%               
  5185.  
  5186. %@AB@%#include <stdio.h>%@AE@%                
  5187.  
  5188. %@AS@%  void assert( int expression );%@AE@%%@NL@%
  5189. %@NL@%
  5190. %@AI@%expression%@AE@%                        C expression specifying assertion being 
  5191.                                   tested
  5192.  
  5193. %@NL@%
  5194. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5195. %@NL@%
  5196. The %@AB@%assert%@AE@% routine prints a diagnostic message and calls the %@AB@%abort%@AE@% routine
  5197. if %@AI@%expression%@AE@% is false (0). The diagnostic message has the form   %@CR:C6A00130150 @%  %@NL@%
  5198. %@NL@%
  5199. %@AS@%  Assertion failed: expression, file filename, line linenumber%@AE@%%@NL@%
  5200. %@NL@%
  5201. where %@AI@%filename%@AE@% is the name of the source file and %@AI@%linenumber%@AE@% is the line
  5202. number of the assertion that failed in the source file. No action is taken
  5203. if %@AI@%expression%@AE@% is true (nonzero).  %@NL@%
  5204. %@NL@%
  5205. The %@AB@%assert%@AE@% routine is typically used in program development to identify
  5206. program logic errors. The given expression should be chosen so that it holds
  5207. true only if the program is operating as intended. After a program has been
  5208. debugged, the special "no debug" identifier %@AB@%NDEBUG%@AE@% can be used to remove
  5209. %@AB@%assert%@AE@% calls from the program. If %@AB@%NDEBUG%@AE@% is defined (by any value) with a /D
  5210. command-line option or with a %@AB@%#define%@AE@% directive, the C preprocessor removes
  5211. all %@AB@%assert%@AE@% calls from the program source.%@CR:C6A00130151 @%%@CR:C6A00130152 @%  %@NL@%
  5212. %@NL@%
  5213. The %@AB@%assert%@AE@% routine is implemented as a macro.  %@NL@%
  5214. %@NL@%
  5215. %@NL@%
  5216. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5217. %@NL@%
  5218. None.  %@NL@%
  5219. %@NL@%
  5220. %@NL@%
  5221. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5222. %@NL@%
  5223. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  5224. %@NL@%
  5225. %@NL@%
  5226. %@NL@%
  5227. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5228. %@NL@%
  5229. %@AB@%abort%@AE@%, %@AB@%raise%@AE@%, %@AB@%signal%@AE@%  %@NL@%
  5230. %@NL@%
  5231. %@NL@%
  5232. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5233. %@NL@%
  5234. %@AS@%  /* ASSERT.C: In this program, the analyze_string function uses the
  5235. %@AS@%   * assert function to test several conditions related to string and
  5236. %@AS@%   * length. If any of the conditions fails, the program prints a
  5237. %@AS@%   * message indicating what caused the failure.
  5238. %@AS@%   */
  5239. %@AS@%  
  5240. %@AS@%  #include <stdio.h>
  5241. %@AS@%  #include <assert.h>
  5242. %@AS@%  #include <string.h>
  5243. %@AS@%  
  5244. %@AS@%  void analyze_string( char *string );   /* Prototype */
  5245. %@AS@%  
  5246. %@AS@%  void main()
  5247. %@AS@%  {
  5248. %@AS@%     char  test1[] = "abc", *test2 = NULL, test3[] = "";
  5249. %@AS@%  
  5250. %@AS@%     printf ( "Analyzing string '%s'\n", test1 );
  5251. %@AS@%     analyze_string( test1 );
  5252. %@AS@%     printf ( "Analyzing string '%s'\n", test2 );
  5253. %@AS@%     analyze_string( test2 );
  5254. %@AS@%     printf ( "Analyzing string '%s'\n", test3 );
  5255. %@AS@%     analyze_string( test3 );
  5256. %@AS@%  }
  5257. %@AS@%  
  5258. %@AS@%  /* Tests a string to see if it is NULL, empty, or longer than 0 characters
  5259. %@AS@%*/
  5260. %@AS@%  void analyze_string( char * string )
  5261. %@AS@%  {
  5262. %@AS@%     assert( string != NULL );        /* Cannot be NULL */
  5263. %@AS@%     assert( *string != '\0' );       /* Cannot be empty */
  5264. %@AS@%     assert( strlen( string ) > 2 );  /* Length must be greater than 2 */
  5265. %@AS@%  }%@AE@%%@NL@%
  5266. %@NL@%
  5267. %@NL@%
  5268. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5269. %@NL@%
  5270. %@AS@%  
  5271. %@AS@%  
  5272. %@AS@%  Analyzing string 'abc'
  5273. %@AS@%  Analyzing string '(null)'
  5274. %@AS@%  Assertion failed: string != NULL, file assert.c, line 28
  5275. %@AS@%  
  5276. %@AS@%  abnormal program termination %@AE@%%@NL@%
  5277. %@NL@%
  5278. %@NL@%
  5279. %@NL@%
  5280. %@NL@%
  5281. %@QR:atan@%%@NL@%
  5282. %@2@%%@CR:C6A00140153 @%%@AB@%atan Functions%@AE@%%@EH@%%@NL@%
  5283. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5284. %@NL@%
  5285. %@NL@%
  5286. %@3@%%@AB@%Description%@CR:C6A00140154 @%%@CR:C6A00140155 @% %@CR:C6A00140156 @%%@CR:C6A00140157 @% %@CR:C6A00140158 @%%@CR:C6A00140159 @%%@CR:C6A00140160 @%%@AE@%%@EH@%%@NL@%
  5287. %@NL@%
  5288. Calculate the arctangent of %@AI@%x%@AE@% (%@AB@%atan%@AE@% and %@AB@%atanl%@AE@%) and the arctangent of %@AI@%y/x%@AE@%
  5289. (%@AB@%atan2%@AE@% and %@AB@%atan2l%@AE@%).  %@NL@%
  5290. %@NL@%
  5291. %@AS@%  #include <math.h>%@AE@%%@NL@%
  5292. %@NL@%
  5293. %@AS@%  double atan( double x );%@AE@%%@NL@%
  5294. %@NL@%
  5295. %@AS@%  double atan2( double y, double x );%@AE@%%@NL@%
  5296. %@NL@%
  5297. %@AS@%  long double atanl( long double x );%@AE@%%@NL@%
  5298. %@NL@%
  5299. %@AS@%  long double atan2l( long double y, long double x );%@AE@%%@NL@%
  5300. %@NL@%
  5301. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Any number
  5302.  
  5303. %@NL@%
  5304. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5305. %@NL@%
  5306. The %@AB@%atan%@AE@% family of functions calculates the arctangent of %@AI@%x%@AE@%, and the %@AB@%atan2%@AE@%
  5307. family of functions calculates the arctangent of %@AI@%y%@AE@%/%@AI@%x%@AE@%. The %@AB@%atan%@AE@% group returns
  5308. a value in the range -π/2 to π/2 radians, and the %@AB@%atan2%@AE@% group returns a
  5309. value in the range -π toπ radians. The %@AB@%atan2%@AE@% functions use the signs of both
  5310. arguments to determine the quadrant of the return value.  %@NL@%
  5311. %@NL@%
  5312. %@NL@%
  5313. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5314. %@NL@%
  5315. The %@AB@%atan%@AE@% family of functions returns the arctangent result. If both
  5316. arguments of %@AB@%atan2%@AE@% or %@AB@%atan2l%@AE@% are 0, the function sets %@AB@%errno%@AE@% to %@AB@%EDOM%@AE@%, prints
  5317. a %@AB@%DOMAIN%@AE@% error message to %@AB@%stderr%@AE@%, and returns 0.  %@NL@%
  5318. %@NL@%
  5319. Error handling can be modified by using the %@AB@%matherr%@AE@% (or %@AB@%_matherrl%@AE@%) routine.
  5320. %@NL@%
  5321. %@NL@%
  5322. %@NL@%
  5323. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5324. %@NL@%
  5325. %@AB@%atan%@AE@%, %@AB@%atan2%@AE@%  %@NL@%
  5326. %@NL@%
  5327. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  5328. %@NL@%
  5329. %@NL@%
  5330. %@AB@%atanl%@AE@%, %@AB@%atan2l%@AE@%  %@NL@%
  5331. %@NL@%
  5332.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  5333. %@NL@%
  5334. %@NL@%
  5335. %@NL@%
  5336. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5337. %@NL@%
  5338. %@AB@%acos%@AE@% functions, %@AB@%asin%@AE@% functions, %@AB@%cos %@AE@%functions, %@AB@%matherr%@AE@%, %@AB@%sin%@AE@% functions, %@AB@%tan%@AE@%
  5339. functions  %@NL@%
  5340. %@NL@%
  5341. %@NL@%
  5342. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5343. %@NL@%
  5344. %@AS@%  /* ATAN.C: This program calculates the arctangent of 1 and -1. */
  5345. %@AS@%  
  5346. %@AS@%  #include <math.h>
  5347. %@AS@%  #include <stdio.h>
  5348. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  5349. %@NL@%
  5350. %@AS@%  void main()
  5351. %@AS@%  {
  5352. %@AS@%     double x1, x2, y;
  5353. %@AS@%  
  5354. %@AS@%     printf( "Enter a real number: " );
  5355. %@AS@%     scanf( "%lf", &x1 );
  5356. %@AS@%     y = atan( x1 );
  5357. %@AS@%     printf( "Arctangent of %f: %f\n", x1, y );
  5358. %@AS@%     printf( "Enter a second real number: " );
  5359. %@AS@%     scanf( "%lf", &x2 );
  5360. %@AS@%     y = atan2( x1, x2 );
  5361. %@AS@%     printf( "Arctangent of %f / %f: %f\n", x1, x2, y );
  5362. %@AS@%  }%@AE@%%@NL@%
  5363. %@NL@%
  5364. %@NL@%
  5365. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5366. %@NL@%
  5367. %@AS@%  
  5368. %@AS@%  
  5369. %@AS@%  Enter a real number: -862.42
  5370. %@AS@%  Arctangent of -862.420000: -1.569637
  5371. %@AS@%  Enter a second real number: 78.5149
  5372. %@AS@%  Arctangent of -862.420000 / 78.514900: -1.480006 %@AE@%%@NL@%
  5373. %@NL@%
  5374. %@NL@%
  5375. %@NL@%
  5376. %@NL@%
  5377. %@QR:atexit@%%@NL@%
  5378. %@2@%%@CR:C6A00150161 @%%@AB@%atexit%@AE@%%@EH@%%@NL@%
  5379. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5380. %@NL@%
  5381. %@NL@%
  5382. %@3@%%@AB@%Description%@CR:C6A00150162 @%%@CR:C6A00150163 @%%@AE@%%@EH@%%@NL@%
  5383. %@NL@%
  5384. Processes the specified function at exit.  %@NL@%
  5385. %@NL@%
  5386. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  5387.  
  5388. %@AS@%  int atexit( void ( *func )( void ) );%@AE@%%@NL@%
  5389. %@NL@%
  5390. %@AI@%func%@AE@%                              Function to be called
  5391.  
  5392. %@NL@%
  5393. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5394. %@NL@%
  5395. The %@AB@%atexit%@AE@% function is passed the address of a function (%@AI@%func%@AE@%) to be called
  5396. when the program terminates normally. Successive calls to %@AB@%atexit%@AE@% create a
  5397. register of functions that are executed in LIFO (last-in-first-out) order.
  5398. No more than 32 functions can be registered with %@AB@%atexit%@AE@% or %@AB@%onexit%@AE@%. The
  5399. functions passed to %@AB@%atexit%@AE@% cannot take parameters.  %@NL@%
  5400. %@NL@%
  5401. All routines passed to %@AB@%atexit%@AE@% should have the %@AB@%_loadds%@AE@% attribute if used in
  5402. multithread dynamic-link libraries.  %@NL@%
  5403. %@NL@%
  5404. %@NL@%
  5405. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5406. %@NL@%
  5407. The %@AB@%atexit%@AE@% function returns 0 if it is successful, or a nonzero value if an
  5408. error occurs (e.g., if there are already 32 exit functions defined).  %@NL@%
  5409. %@NL@%
  5410. %@NL@%
  5411. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5412. %@NL@%
  5413. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  5414. %@NL@%
  5415. %@NL@%
  5416. Use the ANSI-standard %@AB@%atexit%@AE@% function (rather than the similar %@AB@%onexit%@AE@%
  5417. function) whenever ANSI portability is desired.  %@NL@%
  5418. %@NL@%
  5419. In the OS/2 environment, the %@AB@%atexit%@AE@% function calls the OS/2 function
  5420. %@AB@%DosExitList%@AE@%.  %@NL@%
  5421. %@NL@%
  5422. %@NL@%
  5423. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5424. %@NL@%
  5425. %@AB@%abort%@AE@%, %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, %@AB@%onexit%@AE@%  %@NL@%
  5426. %@NL@%
  5427. %@NL@%
  5428. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5429. %@NL@%
  5430. %@AS@%  /* ATEXIT.C: This program pushes four functions onto the stack of
  5431. %@AS@%  functions
  5432. %@AS@%   * to be executed when atexit is called. When the program exits, these
  5433. %@AS@%   * programs are executed on a "last in, first out" basis.
  5434. %@AS@%   */
  5435. %@AS@%  
  5436. %@AS@%  #include <stdlib.h>
  5437. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  5438. %@NL@%
  5439. %@AS@%  void fn1( void ), fn2( void ), fn3( void ), fn4( void );
  5440. %@AS@%  
  5441. %@AS@%  void main()
  5442. %@AS@%  {
  5443. %@AS@%     atexit( fn1 );
  5444. %@AS@%     atexit( fn2 );
  5445. %@AS@%     atexit( fn3 );
  5446. %@AS@%     atexit( fn4 );
  5447. %@AS@%     printf( "This is executed first.\n" );
  5448. %@AS@%  }
  5449. %@AS@%  
  5450. %@AS@%  void fn1()
  5451. %@AS@%  {
  5452. %@AS@%     printf( "next.\n" );
  5453. %@AS@%  }
  5454. %@AS@%  
  5455. %@AS@%  void fn2()
  5456. %@AS@%  {
  5457. %@AS@%     printf( "executed " );
  5458. %@AS@%  }
  5459. %@AS@%  
  5460. %@AS@%  void fn3()
  5461. %@AS@%  {
  5462. %@AS@%     printf( "is " );
  5463. %@AS@%  }
  5464. %@AS@%  
  5465. %@AS@%  void fn4()
  5466. %@AS@%  {
  5467. %@AS@%     printf( "This " );
  5468. %@AS@%  }%@AE@%%@NL@%
  5469. %@NL@%
  5470. %@NL@%
  5471. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5472. %@NL@%
  5473. %@AS@%  
  5474. %@AS@%  
  5475. %@AS@%  This is executed first.
  5476. %@AS@%  This is executed next. %@AE@%%@NL@%
  5477. %@NL@%
  5478. %@NL@%
  5479. %@NL@%
  5480. %@NL@%
  5481. %@QR:atof@%%@QR:atoi@%%@QR:atol@%%@QR:_atold@%%@NL@%
  5482. %@2@%%@CR:C6A00160164 @%%@AB@%atof, atoi, atol, _atold%@AE@%%@EH@%%@NL@%
  5483. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5484. %@NL@%
  5485. %@NL@%
  5486. %@3@%%@AB@%Description%@CR:C6A00160165 @% %@CR:C6A00160166 @%%@CR:C6A00160167 @%%@AE@%%@EH@%%@NL@%
  5487. %@NL@%
  5488. Convert strings to double (%@AB@%atof%@AE@%), long double (%@AB@%_atold%@AE@%) integer %@AB@%(atoi%@AE@%), or
  5489. long (%@AB@%atol%@AE@%).  %@NL@%
  5490. %@NL@%
  5491. %@AB@%#include <math.h>%@AE@%                 %@AB@%atof%@AE@%,%@AB@% _atold%@AE@%
  5492.  
  5493. %@AB@%#include <stdlib.h>%@AE@%               %@AB@%atof%@AE@%, %@AB@%_atold%@AE@%, %@AB@%atoi%@AE@%, %@AB@%atol%@AE@%
  5494.  
  5495. %@AS@%  double atof( const char *string );%@AE@%%@NL@%
  5496. %@NL@%
  5497. %@AS@%  long double _atold( const char *string );%@AE@%%@NL@%
  5498. %@NL@%
  5499. %@AS@%  int atoi( const char *string );%@AE@%%@NL@%
  5500. %@NL@%
  5501. %@AS@%  long atol( const char *string );%@AE@%%@NL@%
  5502. %@NL@%
  5503. %@AI@%string%@AE@%                            String to be converted
  5504.  
  5505. %@NL@%
  5506. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5507. %@NL@%
  5508. These functions convert a character string to a double-precision
  5509. floating-point value (%@AB@%atof%@AE@%), an integer value (%@AB@%atoi%@AE@%), a long integer value
  5510. (%@AB@%atol%@AE@%), or a long double value (%@AB@%_atold%@AE@%). The input string is a sequence of
  5511. characters that can be interpreted as a numerical value of the specified
  5512. type.%@CR:C6A00160168 @%%@CR:C6A00160169 @%  %@NL@%
  5513. %@NL@%
  5514. The string size that can be handled by the %@AB@%atof%@AE@% or %@AB@%_atold %@AE@%function is
  5515. limited to 100 characters. %@AB@%  %@AE@%%@NL@%
  5516. %@NL@%
  5517. The function stops reading the input string at the first character that it
  5518. cannot recognize as part of a number. This character may be the null
  5519. character (%@AB@%'\0'%@AE@%) terminating the string.  %@NL@%
  5520. %@NL@%
  5521. The %@AB@%atof%@AE@% and %@AB@%_atold%@AE@% functions expect %@AI@%string%@AE@% to have the following form:  %@NL@%
  5522. %@NL@%
  5523. %@AS@%  [[whitespace]] [[{sign}]] [[ IK0digits]] [[.digits]] 
  5524. %@AS@%  [[{d| D | e | E}[[sign]digits]]%@AE@%%@NL@%
  5525. %@NL@%
  5526. A %@AI@%whitespace%@AE@% consists of space and/or tab characters, which are ignored;
  5527. %@AI@%sign%@AE@% is either plus (+) or minus (-); and %@AI@%digits%@AE@% are one or more decimal
  5528. digits. If no digits appear before the decimal point, at least one must
  5529. appear after the decimal point. The decimal digits may be followed by an
  5530. exponent, which consists of an introductory letter (%@AB@%d%@AE@%, %@AB@%D%@AE@%, %@AB@%e%@AE@%, or %@AB@%E%@AE@%) and an
  5531. optionally signed decimal integer.  %@NL@%
  5532. %@NL@%
  5533. The %@AB@%atoi%@AE@% and %@AB@%atol%@AE@% functions do not recognize decimal points or exponents.
  5534. The %@AI@%string%@AE@% argument for these functions has the form  %@NL@%
  5535. %@NL@%
  5536. %@AS@%  [[whitespace]] [[sign]]digits %@AE@%%@NL@%
  5537. %@NL@%
  5538. where %@AI@%whitespace%@AE@%, %@AI@%sign%@AE@%, and %@AI@%digits%@AE@% are exactly as described above for %@AB@%atof%@AE@%.
  5539. %@NL@%
  5540. %@NL@%
  5541. %@NL@%
  5542. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5543. %@NL@%
  5544. Each function returns the %@AB@%double%@AE@%, %@AB@%long double%@AE@%, %@AB@%int%@AE@%, or %@AB@%long%@AE@% value produced
  5545. by interpreting the input characters as a number. The return value is 0 (for
  5546. %@AB@%atoi%@AE@%), 0L (for %@AB@%atol%@AE@%), and 0.0 (for %@AB@%atof%@AE@% and %@AB@%_atold%@AE@%) if the input cannot be
  5547. converted to a value of that type. The return value is undefined in case of
  5548. overflow.  %@NL@%
  5549. %@NL@%
  5550. %@NL@%
  5551. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5552. %@NL@%
  5553. %@AB@%atof%@AE@%,%@AB@% atoi%@AE@%, %@AB@%atol%@AE@%  %@NL@%
  5554. %@NL@%
  5555. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  5556. %@NL@%
  5557. %@NL@%
  5558. %@AB@%_atold%@AE@%  %@NL@%
  5559. %@NL@%
  5560.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  5561. %@NL@%
  5562. %@NL@%
  5563. %@NL@%
  5564. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5565. %@NL@%
  5566. %@AB@%ecvt%@AE@%, %@AB@%fcvt%@AE@%, %@AB@%gcvt%@AE@%  %@NL@%
  5567. %@NL@%
  5568. %@NL@%
  5569. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5570. %@NL@%
  5571. %@AS@%  /* ATOF.C: This program shows how numbers stored as strings can be
  5572. %@AS@%   * converted to numeric values using the atof, atoi, and atol functions.
  5573. %@AS@%   */
  5574. %@AS@%  
  5575. %@AS@%  #include <stdlib.h>
  5576. %@AS@%  #include <stdio.h>
  5577. %@AS@%  
  5578. %@AS@%  void main()
  5579. %@AS@%  {
  5580. %@AS@%     char *s; double x; int i; long l;
  5581. %@AS@%  
  5582. %@AS@%     s = "  -2309.12E-15";    /* Test of atof */
  5583. %@AS@%     x = atof( s );
  5584. %@AS@%     printf( "atof test:  ASCII string: %s\tfloat:     %e\n", s, x );
  5585. %@AS@%  
  5586. %@AS@%     s = "7.8912654773d210";  /* Test of atof */
  5587. %@AS@%     x = atof( s );
  5588. %@AS@%     printf( "atof test:  ASCII string: %s\tfloat:     %e\n", s, x );
  5589. %@AS@%  
  5590. %@AS@%     s = "  -9885 pigs";      /* Test of atoi */
  5591. %@AS@%     i = atoi( s );
  5592. %@AS@%     printf( "atoi test:  ASCII string: %s\t\tinteger: %d\n", s, i );
  5593. %@AS@%  
  5594. %@AS@%     s = "98854 dollars";     /* Test of atol */
  5595. %@AS@%     l = atol( s );
  5596. %@AS@%     printf( "atol test:  ASCII string: %s\t\tlong:    %ld\n", s, l );
  5597. %@AS@%  }%@AE@%%@NL@%
  5598. %@NL@%
  5599. %@NL@%
  5600. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5601. %@NL@%
  5602. %@AS@%  
  5603. %@AS@%  
  5604. %@AS@%  atof test:  ASCII string:   -2309.12E-15        float:     -2.309120e-012
  5605. %@AS@%  atof test:  ASCII string: 7.8912654773d210      float:     7.891265e+210
  5606. %@AS@%  atoi test:  ASCII string:   -9885 pigs          integer: -9885
  5607. %@AS@%  atol test:  ASCII string: 98854 dollars         long:    98854 %@AE@%%@NL@%
  5608. %@NL@%
  5609. %@NL@%
  5610. %@NL@%
  5611. %@NL@%
  5612. %@QR:bdos@%%@NL@%
  5613. %@2@%%@CR:C6A00170170 @%%@AB@%bdos%@AE@%%@EH@%%@NL@%
  5614. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5615. %@NL@%
  5616. %@NL@%
  5617. %@3@%%@AB@%Description%@CR:C6A00170171 @%%@CR:C6A00170172 @%%@AE@%%@EH@%%@NL@%
  5618. %@NL@%
  5619. Invokes the DOS system call.  %@NL@%
  5620. %@NL@%
  5621. %@AB@%#include <dos.h>%@AE@%  %@NL@%
  5622. %@NL@%
  5623. %@AS@%  int bdos( int dosfunc, unsigned int dosdx, unsigned int dosal );%@AE@%%@NL@%
  5624. %@NL@%
  5625. %@AI@%dosfunc%@AE@%                           Function number
  5626.  
  5627. %@AI@%dosdx%@AE@%                             DX register value
  5628.  
  5629. %@AI@%dosal%@AE@%                             AL register value
  5630.  
  5631. %@NL@%
  5632. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5633. %@NL@%
  5634. The %@AB@%bdos%@AE@% function invokes the DOS system call specified by %@AI@%dosfunc%@AE@% after
  5635. placing the values specified by %@AI@%dosdx%@AE@% and %@AI@%dosal%@AE@% in the DX and AL registers,
  5636. respectively. The %@AB@%bdos%@AE@% function executes an INT 21H instruction to invoke
  5637. the system call. When the system call is complete, %@AB@%bdos%@AE@% returns the contents
  5638. of the AX register. %@CR:C6A00170173 @%  %@NL@%
  5639. %@NL@%
  5640. The %@AB@%bdos%@AE@% function is intended to be used to invoke DOS system calls that
  5641. either take no arguments or take arguments only in the DX (DH, DL) and/or AL
  5642. registers.  %@NL@%
  5643. %@NL@%
  5644. Do not use the %@AB@%bdos%@AE@% function to call interrupts that modify the DS register.
  5645. Instead, use the %@AB@%intdosx%@AE@% or %@AB@%int86x%@AE@% function. The %@AB@%intdosx%@AE@% and %@AB@%int86x%@AE@%
  5646. functions load the DS and ES registers from the %@AI@%segregs%@AE@% parameter and also
  5647. store the DS and ES registers into %@AI@%segregs%@AE@% after the function call.  %@NL@%
  5648. %@NL@%
  5649. This call should not be used to invoke system calls that indicate errors by
  5650. setting the carry flag. Since C programs do not have access to this flag,
  5651. your program cannot determine whether the return value is an error code. The
  5652. %@AB@%intdos%@AE@% function should be used in these cases.  %@NL@%
  5653. %@NL@%
  5654. %@NL@%
  5655. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5656. %@NL@%
  5657. The %@AB@%bdos%@AE@% function returns the value of the AX register after the system call
  5658. has completed.  %@NL@%
  5659. %@NL@%
  5660. %@NL@%
  5661. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5662. %@NL@%
  5663.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  5664. %@NL@%
  5665. %@NL@%
  5666. %@NL@%
  5667. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5668. %@NL@%
  5669. %@AB@%intdos%@AE@%, %@AB@%intdosx%@AE@%%@CR:C6A00170174 @%  %@NL@%
  5670. %@NL@%
  5671. %@NL@%
  5672. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5673. %@NL@%
  5674. %@AS@%  /* BDOS.C: This example calls DOS function 0x9 (display string)
  5675. %@AS@%   * to display a $-terminated string.
  5676. %@AS@%   */
  5677. %@AS@%  
  5678. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  5679. %@NL@%
  5680. %@AS@%  /* Function 0x09 assumes that DS will contain segment of the string.
  5681. %@AS@%   * This will be true for all memory models if the string is declared near.
  5682. %@AS@%   */
  5683. %@AS@%  char _near str[] = "Hello world!\r\n$";
  5684. %@AS@%  
  5685. %@AS@%  void main()
  5686. %@AS@%  {
  5687. %@AS@%     /* Offset of string must be in DX, segment in DS. AL is not needed,
  5688. %@AS@%      * so 0 is used.
  5689. %@AS@%      */
  5690. %@AS@%     bdos( 0x09, (int)str, 0 );
  5691. %@AS@%  }%@AE@%%@NL@%
  5692. %@NL@%
  5693. %@NL@%
  5694. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  5695. %@NL@%
  5696. %@AS@%  
  5697. %@AS@%  
  5698. %@AS@%  Hello world! %@AE@%%@NL@%
  5699. %@NL@%
  5700. %@NL@%
  5701. %@NL@%
  5702. %@NL@%
  5703. %@QR:_beginthread@%%@NL@%
  5704. %@2@%%@CR:C6A00180175 @%%@AB@%_beginthread%@AE@%%@EH@%%@NL@%
  5705. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5706. %@NL@%
  5707. %@NL@%
  5708. %@3@%%@AB@%Description%@CR:C6A00180176 @% %@CR:C6A00180177 @%%@AE@%%@EH@%%@NL@%
  5709. %@NL@%
  5710. Begins thread in OS/2 process.  %@NL@%
  5711. %@NL@%
  5712. %@AB@%#include <process.h>%@AE@%              Multithread version of PROCESS.H
  5713.  
  5714. %@AB@%#include <stddef.h>%@AE@%               Declaration of %@AI@%threadid%@AE@% variable
  5715.  
  5716. %@AS@%  int _far  _beginthread( void( _far *start_address )( void _far * ), 
  5717. %@AS@%  void  _far *stack_bottom, unsigned stack_size, void  _far *arglist );%@AE@%%@NL@%
  5718. %@NL@%
  5719. %@AI@%start_address%@AE@%                     Starting address
  5720.  
  5721. %@AI@%stack_bottom%@AE@%                      Address of the thread stack
  5722.  
  5723. %@AI@%stack_size%@AE@%                        Stack size for thread
  5724.  
  5725. %@AI@%arglist%@AE@%                           Argument list for thread
  5726.  
  5727. %@NL@%
  5728. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5729. %@NL@%
  5730. The %@AB@%_beginthread%@AE@% function creates a thread that begins execution of a far
  5731. routine at %@AI@%start_address%@AE@%. When the thread returns from that far routine, it
  5732. is terminated automatically. The user can also terminate the thread by
  5733. calling %@AB@%_endthread%@AE@%.  %@NL@%
  5734. %@NL@%
  5735. The address of the thread stack is given by %@AI@%stack_bottom%@AE@%. If %@AI@%stack_bottom%@AE@% is
  5736. set to %@AB@%NULL%@AE@%, the run-time library code will allocate and deallocate the
  5737. thread stack as needed. Since the %@AB@%_beginthread%@AE@% function can determine the
  5738. current status of all thread IDs, it can free the old stack and allocate a
  5739. new stack whenever a thread is reused.  %@NL@%
  5740. %@NL@%
  5741. If it is not %@AB@%NULL%@AE@%, the %@AI@%stack_bottom%@AE@% argument must specify a word address,
  5742. and the stack must be at least as long as specified by the %@AI@%stack_size%@AE@%
  5743. argument. Usually this memory is either a global array or memory returned by
  5744. %@AB@%malloc%@AE@% or %@AB@%_fmalloc%@AE@%.  %@NL@%
  5745. %@NL@%
  5746. The %@AI@%stack_size%@AE@% argument must be even and nonzero.  %@NL@%
  5747. %@NL@%
  5748. If you are writing multithread programs that make C run-time calls from
  5749. child threads, be sure to allocate a sufficiently large stack. For example,
  5750. the C function %@AB@%printf%@AE@% requires more than 500 bytes of stack space. To be
  5751. safe, allocate at least 2,048 bytes for a thread's stack. (If your child
  5752. thread makes no run-time calls, stack space is generally not a problem.)  %@NL@%
  5753. %@NL@%
  5754. As a general rule, you should have 2K of stack space free when calling any
  5755. API (Applications Program Interface) routine (e.g., OS/2 system calls).  %@NL@%
  5756. %@NL@%
  5757. The %@AI@%arglist%@AE@% is a parameter, the size of a far pointer, to be passed to the
  5758. newly created thread. Typically it is the address of a data item, such as a
  5759. character string, to be passed to the new thread. The %@AI@%arglist%@AE@% may be %@AB@%NULL%@AE@% if
  5760. not needed, but %@AB@%_beginthread%@AE@% should be provided with some value to pass to
  5761. the child thread.  %@NL@%
  5762. %@NL@%
  5763. All threads will be terminated if any thread calls %@AB@%abort%@AE@%, %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, or
  5764. %@AB@%DosExit%@AE@%. A good practice in multithread programming is to make the first
  5765. thread the main thread and wait until other threads have terminated before
  5766. exiting the program.  %@NL@%
  5767. %@NL@%
  5768. The OS/2 function %@AB@%DosCreateThread%@AE@% should not be called directly to create
  5769. threads. The %@AB@%_beginthread%@AE@% function performs initialization procedures
  5770. required to call other C run-time library functions safely.  %@NL@%
  5771. %@NL@%
  5772. %@NL@%
  5773. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5774. %@NL@%
  5775. The function returns the thread identification number of the new thread, if
  5776. successful. A return value of -1 indicates an error, and %@AB@%errno%@AE@% is set to one
  5777. of the following values:  %@NL@%
  5778. %@NL@%
  5779. %@AB@%Value %@AE@%                            %@AB@%Meaning%@AE@%
  5780. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5781. %@AB@%EAGAIN%@AE@%                            Too many threads
  5782.  
  5783. %@AB@%EINVAL%@AE@%                            Invalid argument, "bad stack"
  5784.  
  5785. %@NL@%
  5786. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5787. %@NL@%
  5788.  ANSI   DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  5789. %@NL@%
  5790. %@NL@%
  5791. %@NL@%
  5792. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  5793. %@NL@%
  5794. %@AB@%_endthread%@AE@%  %@NL@%
  5795. %@NL@%
  5796. %@NL@%
  5797. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  5798. %@NL@%
  5799. %@AS@%  /* BEGTHRD.C illustrates multiple threads using functions:
  5800. %@AS@%   *      _beginthread            _endthread
  5801. %@AS@%   *
  5802. %@AS@%   * Also the global variable:
  5803. %@AS@%   *      _threadid
  5804. %@AS@%   *
  5805. %@AS@%   * This program requires the multithread library. For example, compile
  5806. %@AS@%   * with the following command line:
  5807. %@AS@%   *      CL /MT THREADS.C
  5808. %@AS@%   */
  5809. %@AS@%  
  5810. %@AS@%  #define INCL_NOCOMMON
  5811. %@AS@%  #define INCL_NOPM
  5812. %@AS@%  #define INCL_DOSPROCESS
  5813. %@AS@%  #define INCL_VIO
  5814. %@AS@%  #include <os2.h>
  5815. %@AS@%  #include <process.h>    /* _beginthread, _endthread */
  5816. %@AS@%  #include <stddef.h>     /* _threadid                */
  5817. %@AS@%  #include <stdlib.h>
  5818. %@AS@%  #include <conio.h>
  5819. %@AS@%  
  5820. %@AS@%  void Bounce( int c );       /* Prototypes */
  5821. %@AS@%  void CheckKey( void *dummy );%@AE@%%@NL@%
  5822. %@NL@%
  5823. %@AS@%  /* GetRandom returns a random integer between min and max. */
  5824. %@AS@%  #define GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) +
  5825. %@AS@%(min))
  5826. %@AS@%  
  5827. %@AS@%  #define STACK_SIZE   4096
  5828. %@AS@%  
  5829. %@AS@%  BOOL repeat = TRUE;         /* Global repeat flag and video variable */
  5830. %@AS@%  VIOMODEINFO vmi = { sizeof( VIOMODEINFO ) };
  5831. %@AS@%  
  5832. %@AS@%  void main()
  5833. %@AS@%  {
  5834. %@AS@%      PCHAR   stack;
  5835. %@AS@%      CHAR    ch = 'A';
  5836. %@AS@%  
  5837. %@AS@%      /* Get display screen's text row and column information. */
  5838. %@AS@%      VioGetMode( &vmi, 0 );
  5839. %@AS@%  
  5840. %@AS@%      /* Launch CheckKey thread to check for terminating keystroke. */
  5841. %@AS@%      _beginthread( CheckKey, NULL, STACK_SIZE, NULL );
  5842. %@AS@%  
  5843. %@AS@%      /* Loop until CheckKey terminates program. */
  5844. %@AS@%      while( repeat )
  5845. %@AS@%      {
  5846. %@AS@%          /* On first loops, launch character threads. */
  5847. %@AS@%          _beginthread( Bounce, NULL, STACK_SIZE, (void *)ch++ );
  5848. %@AS@%  
  5849. %@AS@%          /* Wait one second between loops. */
  5850. %@AS@%          DosSleep( 1000L );
  5851. %@AS@%      }
  5852. %@AS@%  }
  5853. %@AS@%  
  5854. %@AS@%  /* CheckKey - Thread to wait for a keystroke, then clear repeat flag. */
  5855. %@AS@%  void CheckKey( void *dummy )
  5856. %@AS@%  {
  5857. %@AS@%      getch();
  5858. %@AS@%      repeat = 0;      /* _endthread implied */
  5859. %@AS@%  }
  5860. %@AS@%  
  5861. %@AS@%  /* Bounce - Thread to create and control a colored letter that moves
  5862. %@AS@%   * around on the screen.
  5863. %@AS@%   *
  5864. %@AS@%   * Params: ch - the letter to be moved
  5865. %@AS@%   */
  5866. %@AS@%  void Bounce( int ch )
  5867. %@AS@%  {
  5868. %@AS@%      /* Generate letter and color attribute from thread argument. */
  5869. %@AS@%      char      blankcell[2] = { 0x20, 0x07 };
  5870. %@AS@%      char      blockcell[2] = { ch , (ch % 16) + 1 };
  5871. %@AS@%      int       xold, xcur, yold, ycur;
  5872. %@AS@%      BOOL      first = TRUE;%@AE@%%@NL@%
  5873. %@NL@%
  5874. %@AS@%  /* Seed random number generator and get initial location. */
  5875. %@AS@%      srand( *_threadid );
  5876. %@AS@%      xcur = GetRandom( 0, vmi.col - 1 );
  5877. %@AS@%      ycur = GetRandom( 0, vmi.row - 1 );
  5878. %@AS@%      while( repeat )
  5879. %@AS@%      {
  5880. %@AS@%          /* Pause between loops. */
  5881. %@AS@%          DosSleep( 100L );
  5882. %@AS@%  
  5883. %@AS@%          /* Blank out our old position on the screen, and draw new letter.
  5884. %@AS@%*/
  5885. %@AS@%          if( first )
  5886. %@AS@%              first = FALSE;
  5887. %@AS@%          else
  5888. %@AS@%              VioWrtCellStr( blankcell, 2, yold, xold, 0 );
  5889. %@AS@%          VioWrtCellStr( blockcell, 2, ycur, xcur, 0 );
  5890. %@AS@%  
  5891. %@AS@%          /* Increment the coordinate for next placement of the block. */
  5892. %@AS@%          xold = xcur;
  5893. %@AS@%          yold = ycur;
  5894. %@AS@%          xcur += GetRandom( -1, 1 );
  5895. %@AS@%          ycur += GetRandom( -1, 1 );
  5896. %@AS@%  
  5897. %@AS@%          /* Correct placement (and beep) if about to go off the screen. */
  5898. %@AS@%          if( xcur < 0 )
  5899. %@AS@%              xcur = 1;
  5900. %@AS@%          else if( xcur == vmi.col )
  5901. %@AS@%              xcur = vmi.col - 2;
  5902. %@AS@%          else if( ycur < 0 )
  5903. %@AS@%              ycur = 1;
  5904. %@AS@%          else if( ycur == vmi.row )
  5905. %@AS@%              ycur = vmi.row - 2;
  5906. %@AS@%  
  5907. %@AS@%          /* If not at screen border, continue, otherwise beep. */
  5908. %@AS@%          else
  5909. %@AS@%              continue;
  5910. %@AS@%          DosBeep( (ch - 'A') * 100, 175 );
  5911. %@AS@%      }
  5912. %@AS@%      /* _endthread given (but not really needed) to terminate. */
  5913. %@AS@%      _endthread();
  5914. %@AS@%  }%@AE@%%@NL@%
  5915. %@NL@%
  5916. %@NL@%
  5917. %@NL@%
  5918. %@NL@%
  5919. %@QR:Bessel@%%@NL@%
  5920. %@2@%%@CR:C6A00190178 @%%@AB@%Bessel Functions%@AE@%%@EH@%%@NL@%
  5921. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  5922. %@NL@%
  5923. %@NL@%
  5924. %@3@%%@AB@%Description%@CR:C6A00190179 @%%@CR:C6A00190180 @% %@CR:C6A00190181 @%%@CR:C6A00190182 @% %@CR:C6A00190183 @% %@CR:C6A00190184 @%%@CR:C6A00190185 @%%@CR:C6A00190186 @% %@CR:C6A00190187 @%%@CR:C6A00190188 @%%@CR:C6A00190189 @%%@CR:C6A00190190 @%%@EH@%
  5925. %@AB@%%@AE@%%@NL@%
  5926. %@NL@%
  5927. Compute the Bessel function.  %@NL@%
  5928. %@NL@%
  5929. %@AB@%#include <math.h>%@AE@%  %@NL@%
  5930. %@NL@%
  5931. %@AS@%  double j0( double x );%@AE@%%@NL@%
  5932. %@NL@%
  5933. %@AS@%  double j1( double x );%@AE@%%@NL@%
  5934. %@NL@%
  5935. %@AS@%  double jn( int n, double x );%@AE@%%@NL@%
  5936. %@NL@%
  5937. %@AS@%  double y0( double x );%@AE@%%@NL@%
  5938. %@NL@%
  5939. %@AS@%  double y1( double x );%@AE@%%@NL@%
  5940. %@NL@%
  5941. %@AS@%  double yn( int n, double x );%@AE@%%@NL@%
  5942. %@NL@%
  5943. %@AS@%  long double _j0l( long double x );%@AE@%%@NL@%
  5944. %@NL@%
  5945. %@AS@%  long double _jnl( int n, long double x );%@AE@%%@NL@%
  5946. %@NL@%
  5947. %@AS@%  long double _j1l( long double x );%@AE@%%@NL@%
  5948. %@NL@%
  5949. %@AS@%  long double _y0l( long double x );%@AE@%%@NL@%
  5950. %@NL@%
  5951. %@AS@%  long double _y1l( long double x );%@AE@%%@NL@%
  5952. %@NL@%
  5953. %@AS@%  long double _ynl( int n, long double x );%@AE@%%@NL@%
  5954. %@NL@%
  5955. %@AI@%x%@AE@%                                 Floating-point value
  5956.  
  5957. %@AI@%n%@AE@%                                 Integer order
  5958.  
  5959. %@NL@%
  5960. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  5961. %@NL@%
  5962. The %@AB@%j0%@AE@%, %@AB@%j1%@AE@%, and %@AB@%jn%@AE@% routines return Bessel functions of the first kind─orders
  5963. 0, 1, and %@AI@%n%@AE@%, respectively.  %@NL@%
  5964. %@NL@%
  5965. The %@AB@%y0%@AE@%, %@AB@%y1%@AE@%, and %@AB@%yn%@AE@% routines return Bessel functions of the second
  5966. kind─orders 0, 1, and %@AI@%n%@AE@%, respectively. The argument %@AI@%x%@AE@% must be positive.  %@NL@%
  5967. %@NL@%
  5968. The long double versions of these functions are the 80-bit counterparts and
  5969. use the 80-bit, 10-byte coprocessor form of arguments and return values. See
  5970. the reference page on the long double functions for more details on this
  5971. data type.  %@NL@%
  5972. %@NL@%
  5973. The Bessel functions are explained more fully in most mathematics reference
  5974. books, such as the %@AI@%Handbook of Mathematical Functions%@AE@% (Abramowitz and
  5975. Stegun; Washington: U.S. Government Printing Office, 1964). These functions
  5976. are commonly used in the mathematics of electromagnetic wave theory.  %@NL@%
  5977. %@NL@%
  5978. %@NL@%
  5979. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  5980. %@NL@%
  5981. These functions return the result of a Bessel function of %@AI@%x%@AE@%.  %@NL@%
  5982. %@NL@%
  5983. For %@AB@%y0%@AE@%, %@AB@%y1%@AE@%, or %@AB@%yn%@AE@%, if %@AI@%x%@AE@% is negative, the routine sets %@AB@%errno%@AE@% to %@AB@%EDOM%@AE@%, prints
  5984. a %@AB@%DOMAIN%@AE@% error message to %@AB@%stderr%@AE@%, and returns %@AB@%-HUGE_VAL%@AE@%.  %@NL@%
  5985. %@NL@%
  5986. Error handling can be modified by using the %@AB@%matherr%@AE@% (or %@AB@%_matherrl%@AE@%) routine.
  5987. %@NL@%
  5988. %@NL@%
  5989. %@NL@%
  5990. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  5991. %@NL@%
  5992. %@AB@%j0%@AE@%, %@AB@%j1%@AE@%, %@AB@%jn%@AE@%, %@AB@%y0%@AE@%, %@AB@%y1%@AE@%, %@AB@%yn%@AE@%  %@NL@%
  5993. %@NL@%
  5994.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  5995. %@NL@%
  5996. %@NL@%
  5997. %@AB@%_j0l%@AE@%,  %@AB@%_j1l%@AE@%,  %@AB@%_jnl%@AE@%,  %@AB@%_y0l%@AE@%,  %@AB@%_y1l%@AE@%,  %@AB@%_ynl%@AE@%  %@NL@%
  5998. %@NL@%
  5999.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  6000. %@NL@%
  6001. %@NL@%
  6002. %@NL@%
  6003. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  6004. %@NL@%
  6005. %@AB@%matherr%@AE@%  %@NL@%
  6006. %@NL@%
  6007. %@NL@%
  6008. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6009. %@NL@%
  6010. %@AS@%  /* BESSEL.C: This program illustrates Bessel functions, including:
  6011. %@AS@%   *      j0          j1          jn          y0          y1          yn
  6012. %@AS@%   */
  6013. %@AS@%  
  6014. %@AS@%  #include <math.h>
  6015. %@AS@%  #include <stdio.h>
  6016. %@AS@%  
  6017. %@AS@%  void main()
  6018. %@AS@%  {
  6019. %@AS@%      double x = 2.387;
  6020. %@AS@%      int n = 3, c;
  6021. %@AS@%  
  6022. %@AS@%      printf( "Bessel functions for x = %f:\n", x );
  6023. %@AS@%      printf( "  Kind\t\tOrder\t\Function\tResult\n\n" );
  6024. %@AS@%      printf( "  First\t\t0\tj0( x )\t\t%f\n", j0( x ) );
  6025. %@AS@%      printf( "  First\t\t1\tj1( x )\t\t%f\n", j1( x ) );
  6026. %@AS@%      for( c = 2; c < 5; c++ )
  6027. %@AS@%          printf( "  First\t\t%d\tjn( n, x )\t%f\n", c, jn( c, x ) );
  6028. %@AS@%  
  6029. %@AS@%      printf( "  Second\t0\ty0( x )\t\t%f\n", y0( x ) );
  6030. %@AS@%      printf( "  Second\t1\ty1( x )\t\t%f\n", y1( x ) );
  6031. %@AS@%      for( c = 2; c < 5; c++ )
  6032. %@AS@%          printf( "  Second\t%d\tyn( n, x )\t%f\n", c, yn( c, x ) );
  6033. %@AS@%  }%@AE@%%@NL@%
  6034. %@NL@%
  6035. %@NL@%
  6036. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6037. %@NL@%
  6038. %@AS@%  
  6039. %@AS@%  
  6040. %@AS@%  Bessel functions for x = 2.387000:
  6041. %@AS@%    Kind          Order   Function        Result
  6042. %@AS@%  
  6043. %@AS@%    First         0       j0( x )         0.009288
  6044. %@AS@%    First         1       j1( x )         0.522941
  6045. %@AS@%    First         2       jn( n, x )      0.428870
  6046. %@AS@%    First         3       jn( n, x )      0.195734
  6047. %@AS@%    First         4       jn( n, x )      0.063131
  6048. %@AS@%    Second        0       y0( x )         0.511681
  6049. %@AS@%    Second        1       y1( x )         0.094374
  6050. %@AS@%    Second        2       yn( n, x )      -0.432608
  6051. %@AS@%    Second        3       yn( n, x )      -0.819314
  6052. %@AS@%    Second        4       yn( n, x )      -1.626833%@AE@%%@NL@%
  6053. %@NL@%
  6054. %@NL@%
  6055. %@NL@%
  6056. %@NL@%
  6057. %@QR:_bfreeseg@%%@NL@%
  6058. %@2@%%@CR:C6A00200191 @%%@AB@%_bfreeseg%@AE@%%@EH@%%@NL@%
  6059. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6060. %@NL@%
  6061. %@NL@%
  6062. %@3@%%@AB@%Description%@CR:C6A00200192 @% %@CR:C6A00200193 @%%@AE@%%@EH@%%@NL@%
  6063. %@NL@%
  6064. Frees a specified based heap.  %@NL@%
  6065. %@NL@%
  6066. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  6067.  
  6068. %@AS@%  int _bfreeseg( _segment seg );%@AE@%%@NL@%
  6069. %@NL@%
  6070. %@AI@%seg%@AE@%                               Segment selected
  6071.  
  6072. %@NL@%
  6073. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6074. %@NL@%
  6075. The %@AB@%_bfreeseg%@AE@% function frees a based heap. The %@AI@%seg%@AE@% argument is a based heap
  6076. returned by an earlier call to %@AB@%_bheapseg%@AE@%. It specifies the based heap to be
  6077. freed.  %@NL@%
  6078. %@NL@%
  6079. The number of bytes freed is the number of bytes specified when the block
  6080. was allocated. After the call, the freed heap is again available for
  6081. allocation.  %@NL@%
  6082. %@NL@%
  6083. %@NL@%
  6084. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6085. %@NL@%
  6086. The %@AB@%_bfreeseg%@AE@% function returns 0 if successful and -1 in the case of an
  6087. error.  %@NL@%
  6088. %@NL@%
  6089. %@NL@%
  6090. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6091. %@NL@%
  6092.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  6093. %@NL@%
  6094. %@NL@%
  6095. %@NL@%
  6096. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  6097. %@NL@%
  6098. %@AB@%_bheapseg%@AE@%, %@AB@%calloc%@AE@% functions, %@AB@%free%@AE@% functions,%@AB@% malloc%@AE@% functions, %@AB@%realloc%@AE@%
  6099. functions  %@NL@%
  6100. %@NL@%
  6101. %@NL@%
  6102. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6103. %@NL@%
  6104. %@AS@%  /* BHEAPSEG.C: This program C illustrates dynamic allocation of based
  6105. %@AS@%   * memory using functions _bheapseg, _bfreeseg, _bmalloc, and _bfree.
  6106. %@AS@%   */
  6107. %@AS@%  
  6108. %@AS@%  #include <stdio.h>
  6109. %@AS@%  #include <malloc.h>
  6110. %@AS@%  #include <stdlib.h>
  6111. %@AS@%  #include <string.h>
  6112. %@AS@%  
  6113. %@AS@%  void main()
  6114. %@AS@%  {
  6115. %@AS@%      _segment seg;
  6116. %@AS@%      char _based( seg ) *outstr, _based( seg ) *instr;
  6117. %@AS@%      char _based( seg ) *pout,   _based( seg ) *pin;
  6118. %@AS@%      char tmpstr[80];
  6119. %@AS@%      int  len;
  6120. %@AS@%  
  6121. %@AS@%      printf( "Enter a string: " );
  6122. %@AS@%      gets( tmpstr );
  6123. %@AS@%  
  6124. %@AS@%      /* Request a based heap. Use based so that memory won't be taken from
  6125. %@AS@%       * near heap.
  6126. %@AS@%       */
  6127. %@AS@%      if( (seg = _bheapseg( 1000 )) == _NULLSEG )
  6128. %@AS@%          exit( 1 );
  6129. %@AS@%  
  6130. %@AS@%      /* Allocate based memory for two strings. */
  6131. %@AS@%      len = strlen( tmpstr );
  6132. %@AS@%      if( ((instr  = _bmalloc( seg, len + 1 )) == _NULLOFF) ||
  6133. %@AS@%          ((outstr = _bmalloc( seg, len + 1 )) == _NULLOFF) )
  6134. %@AS@%          exit( 1 );
  6135. %@AS@%  
  6136. %@AS@%      /* Copy a lowercased string to dynamic memory. The based memory is
  6137. %@AS@%       * far when addressed as a whole.
  6138. %@AS@%       */
  6139. %@AS@%      _fstrlwr( _fstrcpy( (char _far *)instr, (char _far *)tmpstr ) );
  6140. %@AS@%  
  6141. %@AS@%      /* Copy input string to output string in reversed order. When reading
  6142. %@AS@%       * and writing individual characters from a based heap, the compiler
  6143. %@AS@%will
  6144. %@AS@%       * try to process them as near, thus speeding up the processing.
  6145. %@AS@%       */
  6146. %@AS@%      for( pin = instr + len - 1, pout = outstr;
  6147. %@AS@%                  pout < outstr + len; pin--, pout++ )
  6148. %@AS@%          *pout = *pin;
  6149. %@AS@%      *pout = '\0';
  6150. %@AS@%  
  6151. %@AS@%      /* Display strings. Again strings as a whole are far. */
  6152. %@AS@%      printf( "Input:  %Fs\n", (char _far *)instr );
  6153. %@AS@%      printf( "Output: %Fs\n", (char _far *)outstr );
  6154. %@AS@%  
  6155. %@AS@%      /* Free blocks and release based heap. */
  6156. %@AS@%      _bfree( seg, instr );
  6157. %@AS@%      _bfree( seg, outstr );
  6158. %@AS@%      _bfreeseg( seg );
  6159. %@AS@%  }%@AE@%%@NL@%
  6160. %@NL@%
  6161. %@NL@%
  6162. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6163. %@NL@%
  6164. %@AS@%  
  6165. %@AS@%  
  6166. %@AS@%  Enter a string: Was I god
  6167. %@AS@%  Input:  was i god
  6168. %@AS@%  Output: dog i saw%@AE@%%@NL@%
  6169. %@NL@%
  6170. %@NL@%
  6171. %@NL@%
  6172. %@NL@%
  6173. %@QR:_bheapseg@%%@NL@%
  6174. %@2@%%@CR:C6A00210194 @%%@AB@%_bheapseg%@AE@%%@EH@%%@NL@%
  6175. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6176. %@NL@%
  6177. %@NL@%
  6178. %@3@%%@AB@%Description%@CR:C6A00210195 @% %@CR:C6A00210196 @%%@AE@%%@EH@%%@NL@%
  6179. %@NL@%
  6180. Allocates a based heap.  %@NL@%
  6181. %@NL@%
  6182. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  6183.  
  6184. %@AS@%  _segment _bheapseg( size_t size );%@AE@%%@NL@%
  6185. %@NL@%
  6186. %@AI@%size%@AE@%                              Segment size to allocate
  6187.  
  6188. %@NL@%
  6189. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6190. %@NL@%
  6191. The %@AB@%_bheapseg%@AE@% function allocates a based-heap segment of at least %@AI@%size%@AE@%
  6192. bytes. (The block may be larger than %@AI@%size%@AE@% bytes because of space required
  6193. for alignment and for maintenance information.)  %@NL@%
  6194. %@NL@%
  6195. The heap code will try to enlarge the heap as necessary. If the original
  6196. block of memory is depleted (e.g., by calls to %@AB@%_bmalloc%@AE@% and %@AB@%_brealloc%@AE@%), the
  6197. run-time code will try to enlarge the heap as necessary.  %@NL@%
  6198. %@NL@%
  6199. The value returned by %@AB@%_bheapseg%@AE@% is the identifier of the based-heap segment.
  6200. This value should be saved and used in subsequent calls to other based-heap
  6201. functions.  %@NL@%
  6202. %@NL@%
  6203. The %@AB@%_bheapseg%@AE@% function can be called repeatedly. For each call, the C
  6204. library will allocate a new based-heap segment.  %@NL@%
  6205. %@NL@%
  6206. %@NL@%
  6207. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6208. %@NL@%
  6209. The %@AB@%_bheapseg%@AE@% function returns the newly allocated segment selector that the
  6210. user must save for use in subsequent based-heap functions. A return value of
  6211. -1 indicates failure.  %@NL@%
  6212. %@NL@%
  6213. Always check the return from the %@AB@%_bheapseg%@AE@% function (especially when it is
  6214. used in real mode), even if the amount of memory requested is small.  %@NL@%
  6215. %@NL@%
  6216. %@NL@%
  6217. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6218. %@NL@%
  6219.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  6220. %@NL@%
  6221. %@NL@%
  6222. %@NL@%
  6223. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  6224. %@NL@%
  6225. %@AB@%calloc%@AE@% functions, %@AB@%free%@AE@% functions, %@AB@%malloc%@AE@% functions, %@AB@%realloc%@AE@% functions  %@NL@%
  6226. %@NL@%
  6227. %@NL@%
  6228. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6229. %@NL@%
  6230. %@AS@%  /* BHEAPSEG.C: This program C illustrates dynamic allocation of based
  6231. %@AS@%   * memory using functions _bheapseg, _bfreeseg, _bmalloc, and _bfree.
  6232. %@AS@%   */
  6233. %@AS@%  
  6234. %@AS@%  #include <stdio.h>
  6235. %@AS@%  #include <malloc.h>
  6236. %@AS@%  #include <stdlib.h>
  6237. %@AS@%  #include <string.h>%@AE@%%@NL@%
  6238. %@NL@%
  6239. %@AS@%  void main()
  6240. %@AS@%  {
  6241. %@AS@%      _segment seg;
  6242. %@AS@%      char _based( seg ) *outstr, _based( seg ) *instr;
  6243. %@AS@%      char _based( seg ) *pout,   _based( seg ) *pin;
  6244. %@AS@%      char tmpstr[80];
  6245. %@AS@%      int  len;
  6246. %@AS@%  
  6247. %@AS@%      printf( "Enter a string: " );
  6248. %@AS@%      gets( tmpstr );
  6249. %@AS@%  
  6250. %@AS@%      /* Request a based heap. Use based so that memory won't be taken from
  6251. %@AS@%       * near heap.
  6252. %@AS@%       */
  6253. %@AS@%      if( (seg = _bheapseg( 1000 )) == _NULLSEG )
  6254. %@AS@%          exit( 1 );
  6255. %@AS@%  
  6256. %@AS@%      /* Allocate based memory for two strings. */
  6257. %@AS@%      len = strlen( tmpstr );
  6258. %@AS@%      if( ((instr  = _bmalloc( seg, len + 1 )) == _NULLOFF) ||
  6259. %@AS@%          ((outstr = _bmalloc( seg, len + 1 )) == _NULLOFF) )
  6260. %@AS@%          exit( 1 );
  6261. %@AS@%  
  6262. %@AS@%      /* Copy a lowercased string to dynamic memory. The based memory is
  6263. %@AS@%       * far when addressed as a whole.
  6264. %@AS@%       */
  6265. %@AS@%      _fstrlwr( _fstrcpy( (char _far *)instr, (char _far *)tmpstr ) );
  6266. %@AS@%  
  6267. %@AS@%      /* Copy input string to output string in reversed order. When reading
  6268. %@AS@%       * and writing individual characters from a based heap, the compiler
  6269. %@AS@%will
  6270. %@AS@%       * try to process them as near, thus speeding up the processing.
  6271. %@AS@%       */
  6272. %@AS@%      for( pin = instr + len - 1, pout = outstr;
  6273. %@AS@%                  pout < outstr + len; pin--, pout++ )
  6274. %@AS@%          *pout = *pin;
  6275. %@AS@%      *pout = '\0';
  6276. %@AS@%  
  6277. %@AS@%      /* Display strings. Again, strings as a whole are far. */
  6278. %@AS@%      printf( "Input:  %Fs\n", (char _far *)instr );
  6279. %@AS@%      printf( "Output: %Fs\n", (char _far *)outstr );
  6280. %@AS@%  
  6281. %@AS@%      /* Free blocks and release based heap. */
  6282. %@AS@%      _bfree( seg, instr );
  6283. %@AS@%      _bfree( seg, outstr );
  6284. %@AS@%      _bfreeseg( seg );
  6285. %@AS@%  }%@AE@%%@NL@%
  6286. %@NL@%
  6287. %@NL@%
  6288. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6289. %@NL@%
  6290. %@AS@%  
  6291. %@AS@%  
  6292. %@AS@%  Enter a string: Was I god
  6293. %@AS@%  Input:  was i god
  6294. %@AS@%  Output: dog i saw%@AE@%%@NL@%
  6295. %@NL@%
  6296. %@NL@%
  6297. %@NL@%
  6298. %@NL@%
  6299. %@QR:_bios_disk@%%@NL@%
  6300. %@2@%%@CR:C6A00220197 @%%@AB@%_bios_disk%@AE@%%@EH@%%@NL@%
  6301. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6302. %@NL@%
  6303. %@NL@%
  6304. %@3@%%@AB@%Description%@CR:C6A00220198 @% %@CR:C6A00220199 @%%@AE@%%@EH@%%@NL@%
  6305. %@NL@%
  6306. Calls BIOS disk services using system call INT 0x13.  %@NL@%
  6307. %@NL@%
  6308. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  6309. %@NL@%
  6310. %@AS@%  unsigned _bios_disk( unsigned service, struct diskinfo_t  *diskinfo );%@AE@%%@NL@%
  6311. %@NL@%
  6312. %@AI@%service%@AE@%                           Disk function desired
  6313.  
  6314. %@AI@%diskinfo%@AE@%                          Disk parameters
  6315.  
  6316. %@NL@%
  6317. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6318. %@NL@%
  6319. The %@AB@%_bios_disk%@AE@% routine uses system call INT 0x13 to provide several
  6320. disk-access functions. The %@AI@%service%@AE@% parameter selects the function desired,
  6321. while the %@AI@%diskinfo%@AE@% structure provides the necessary parameters. Note that
  6322. the low-level disk operations allowed by the %@AB@%_bios_disk%@AE@% routine are very
  6323. dangerous to use because they allow direct manipulation of the disk.  %@NL@%
  6324. %@NL@%
  6325. The %@AI@%diskinfo%@AE@% structure provides the following parameters:  %@NL@%
  6326. %@NL@%
  6327. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  6328. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6329. %@AB@%unsigned drive%@AE@%                    Drive number
  6330.  
  6331. %@AB@%unsigned head%@AE@%                     Head number
  6332.  
  6333. %@AB@%unsigned track%@AE@%                    Track number
  6334.  
  6335. %@AB@%unsigned sector%@AE@%                   Starting sector number
  6336.  
  6337. %@AB@%unsigned nsectors%@AE@%                 Number of sectors to read, write, or 
  6338.                                   compare
  6339.  
  6340. %@AB@%void far *buffer%@AE@%                  Memory location to write to, read from, 
  6341.                                   or compare
  6342.  
  6343. The %@AI@%service%@AE@% argument can be set to one of the following manifest constants:
  6344. %@NL@%
  6345. %@NL@%
  6346. %@AB@%Constant%@AE@%                          %@AB@%Function%@AE@%
  6347. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6348. %@AB@%_DISK_FORMAT%@AE@%                      Formats the track specified by %@AI@%diskinfo%@AE@%.
  6349.                                   The %@AI@%head%@AE@% and %@AI@%track%@AE@% fields indicate the 
  6350.                                   track to format. Only one track can be 
  6351.                                   formatted in a single call. The %@AI@%buffer%@AE@% 
  6352.                                   field points to a set of sector markers.
  6353.                                   The format of the markers depends on the
  6354.                                   type of disk drive; see a technical 
  6355.                                   reference to the PC BIOS to determine 
  6356.                                   the marker format. There is no return 
  6357.                                   value.
  6358.  
  6359. %@AB@%_DISK_READ%@AE@%                        Reads one or more disk sectors into 
  6360.                                   memory. This service uses all fields of 
  6361.                                   the structure pointed to by %@AI@%diskinfo%@AE@%, as
  6362.                                   defined earlier in this section. If no 
  6363.                                   error occurs, the function returns 0 in 
  6364.                                   the high-order byte and the number of 
  6365.                                   sectors read in the low-order byte. If 
  6366.                                   there is an error, the high-order byte 
  6367.                                   will contain a set of status flags. If 
  6368.                                   there is an error, the high-order byte 
  6369.                                   will contain a set of status flags, as 
  6370.                                   defined under %@AB@%_DISK_READ%@AE@%. Status is 
  6371.                                   returned in the 8 high-order bits of the
  6372.                                   return value, as listed below: 
  6373.  
  6374.                                   %@AB@%Bits%@AE@%          %@AB@%Meaning%@AE@%
  6375. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6376.                                   0x01**        Invalid request or a bad 
  6377.                                   command
  6378.  
  6379.                                   0x02**        Address mark not found
  6380.  
  6381.                                   0x04**        Sector not found
  6382.  
  6383.                                   0x05**        Reset failed
  6384.  
  6385.                                   0x07**        Drive parameter activity 
  6386.                                   failed
  6387.  
  6388.                                   0x09**        Direct Memory Access (DMA)
  6389.                                   overrun
  6390.  
  6391.                                   0x0A**        Bad sector flag detected
  6392.  
  6393.                                   0x10**        Data read (ECC) error
  6394.  
  6395.                                   0x11**        Corrected data read (ECC) 
  6396.                                   error
  6397.  
  6398.                                   0x20**        Controller failure
  6399.  
  6400.                                   0x40**        Seek error
  6401.  
  6402.                                   0x80**        Disk timed out or failed 
  6403.                                   to respond
  6404.  
  6405.                                   0xAA**        Drive not ready
  6406.  
  6407.                                   0xBB**        Undefined error
  6408.  
  6409.                                   0xCC**        Write fault on drive
  6410.  
  6411.                                   0xE0**        Status error
  6412.  
  6413. %@AB@%_DISK_RESET%@AE@%                       Forces the disk controller to do a hard 
  6414.                                   reset, preparing for floppy-disk I/O. 
  6415.                                   This is useful after an error occurs in 
  6416.                                   another operation, such as a read. If 
  6417.                                   this service is specified, the%@AI@%%@AE@%
  6418.                                   %@AI@%diskinfo%@AE@% argument is ignored.
  6419.  
  6420. %@AB@%_DISK_STATUS%@AE@%                      Obtains the status of the last disk 
  6421.                                   operation. If this service is specified,
  6422.                                   the %@AI@%diskinfo%@AE@% argument is ignored. 
  6423.  
  6424. %@AB@%_DISK_VERIFY%@AE@%                      Checks the disk to be sure the specified
  6425.                                   sectors exist and can be read. It also 
  6426.                                   runs a CRC (cyclic redundancy check) 
  6427.                                   test. This service uses all fields 
  6428.                                   (except %@AI@%buffer%@AE@%) of the structure pointed
  6429.                                   to by %@AI@%diskinfo%@AE@%, as defined earlier in 
  6430.                                   this section. If no error occurs, the 
  6431.                                   function returns 0 in the high-order 
  6432.                                   byte and the number of sectors compared 
  6433.                                   in the low-order byte. If there is an 
  6434.                                   error, the high-order byte will contain 
  6435.                                   a set of status flags, as defined under %@AB@%%@AE@%
  6436.                                   %@AB@%_DISK_READ%@AE@% (above).
  6437.  
  6438. %@AB@%_DISK_WRITE%@AE@%                       Writes data from memory to one or more 
  6439.                                   disk sectors. This service uses all 
  6440.                                   fields of the structure pointed to by %@AI@%%@AE@%
  6441.                                   %@AI@%diskinfo%@AE@%, as defined earlier in this 
  6442.                                   section. If no error occurs, the 
  6443.                                   function returns 0 in the high-order 
  6444.                                   byte and the number of sectors written 
  6445.                                   in the low-order byte. If there is an 
  6446.                                   error, the high-order byte will contain 
  6447.                                   a set of status flags, as defined under %@AB@%%@AE@%
  6448.                                   %@AB@%_DISK_READ%@AE@% (above).
  6449.  
  6450. %@NL@%
  6451. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6452. %@NL@%
  6453. The %@AB@%_bios_disk%@AE@% function returns the value in the AX register after the BIOS
  6454. interrupt.  %@NL@%
  6455. %@NL@%
  6456. %@NL@%
  6457. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6458. %@NL@%
  6459.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  6460. %@NL@%
  6461. %@NL@%
  6462. %@NL@%
  6463. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6464. %@NL@%
  6465. %@AS@%  /* BDISK.C: This program first attempts to verify a disk by using an
  6466. %@AS@%   * invalid disk head number. After printing the return value error code,
  6467. %@AS@%   * the program verifies the disk by using a valid disk head code.
  6468. %@AS@%   */
  6469. %@AS@%  
  6470. %@AS@%  #include <conio.h>
  6471. %@AS@%  #include <stdio.h>
  6472. %@AS@%  #include <bios.h>
  6473. %@AS@%  
  6474. %@AS@%  void main()
  6475. %@AS@%  {
  6476. %@AS@%     unsigned status = 0;
  6477. %@AS@%     struct diskinfo_t disk_info;
  6478. %@AS@%  
  6479. %@AS@%     disk_info.drive    = 0;
  6480. %@AS@%     disk_info.head     = 10;   /* Invalid head number */
  6481. %@AS@%     disk_info.track    = 1;
  6482. %@AS@%     disk_info.sector   = 2;
  6483. %@AS@%     disk_info.nsectors = 8;%@AE@%%@NL@%
  6484. %@NL@%
  6485. %@AS@%  printf( "Insert disk in drive A: and press any key\n" );
  6486. %@AS@%     getch();
  6487. %@AS@%     status = _bios_disk( _DISK_VERIFY, &disk_info );
  6488. %@AS@%     printf( "Return value: 0x%.4x\n", status );
  6489. %@AS@%     if( status & 0xff00 )      /* Error if high byte is 0 */
  6490. %@AS@%        printf( "Seek error\n" );
  6491. %@AS@%     else
  6492. %@AS@%        printf( "No seek error\n" );
  6493. %@AS@%  
  6494. %@AS@%     printf( "Press any key\n" );
  6495. %@AS@%     getch();
  6496. %@AS@%     disk_info.head = 0;        /* Valid head number */
  6497. %@AS@%     status = _bios_disk( _DISK_VERIFY, &disk_info );
  6498. %@AS@%     printf( "Return value: 0x%.4x\n", status );
  6499. %@AS@%     if( status & 0xff00 )      /* Error if high byte is 0 */
  6500. %@AS@%        printf( "Seek error\n" );
  6501. %@AS@%     else
  6502. %@AS@%        printf( "No seek error\n" );
  6503. %@AS@%  }%@AE@%%@NL@%
  6504. %@NL@%
  6505. %@NL@%
  6506. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6507. %@NL@%
  6508. %@AS@%  
  6509. %@AS@%  
  6510. %@AS@%  Insert disk in drive A: and press any key
  6511. %@AS@%  Return value: 0x0400
  6512. %@AS@%  Seek error
  6513. %@AS@%  Press any key
  6514. %@AS@%  Return value: 0x0008
  6515. %@AS@%  No seek error %@AE@%%@NL@%
  6516. %@NL@%
  6517. %@NL@%
  6518. %@NL@%
  6519. %@NL@%
  6520. %@QR:_bios_equiplist@%%@NL@%
  6521. %@2@%%@CR:C6A00230200 @%%@AB@%_bios_equiplist%@AE@%%@EH@%%@NL@%
  6522. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6523. %@NL@%
  6524. %@NL@%
  6525. %@3@%%@AB@%Description%@CR:C6A00230201 @% %@CR:C6A00230202 @%%@AE@%%@EH@%%@NL@%
  6526. %@NL@%
  6527. Calls BIOS equipment-list service, using system call INT 0x11.  %@NL@%
  6528. %@NL@%
  6529. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  6530. %@NL@%
  6531. %@AS@%  unsigned _bios_equiplist( void );%@AE@%%@NL@%
  6532. %@NL@%
  6533. %@NL@%
  6534. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6535. %@NL@%
  6536. The %@AB@%_bios_equiplist%@AE@% routine uses system call INT 0x11 to determine what
  6537. hardware and peripherals are currently installed on the machine.  %@NL@%
  6538. %@NL@%
  6539. %@NL@%
  6540. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6541. %@NL@%
  6542. The function returns a set of bits indicating what is installed, as defined
  6543. below:  %@NL@%
  6544. %@NL@%
  6545. %@AB@%Bits%@AE@%                              %@AB@%Meaning%@AE@%
  6546. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6547. 0                                 Any disk drive installed if true
  6548.  
  6549. 1                                 True (1) if math coprocessor installed
  6550.  
  6551. 2 -3                              System RAM in 16K blocks (16-64K)
  6552.  
  6553. 4 -5                              Initial video mode
  6554.  
  6555. 6 -7                              Number of floppy-disk drives installed 
  6556.                                   (00 = 1,  01 = 2, etc.)
  6557.  
  6558. 8                                 False (0) if and only if a Direct Memory
  6559.                                   Access (DMA) chip is installed
  6560.  
  6561. 9 -11                             Number of RS232 serial ports installed
  6562.  
  6563. 12                                True (1) if and only if a game adapter 
  6564.                                   is installed
  6565.  
  6566. 13                                True (1) if and only if an internal 
  6567.                                   modem is installed
  6568.  
  6569. 14 -15                            Number of printers installed
  6570.  
  6571. %@NL@%
  6572. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6573. %@NL@%
  6574.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  6575. %@NL@%
  6576. %@NL@%
  6577. %@NL@%
  6578. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6579. %@NL@%
  6580. %@AS@%  /* BEQUIPLI.C: This program checks for the presence of diskettes. */
  6581. %@AS@%  
  6582. %@AS@%  #include <bios.h>
  6583. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  6584. %@NL@%
  6585. %@AS@%  void main()
  6586. %@AS@%  {
  6587. %@AS@%     unsigned equipment;
  6588. %@AS@%  
  6589. %@AS@%     equipment = _bios_equiplist();
  6590. %@AS@%     printf( "Equipment bits: 0x%.4x\n", equipment );
  6591. %@AS@%     if( equipment & 0x1000 )      /* Check for game adapter bit */
  6592. %@AS@%        printf( "Game adapter installed\n" );
  6593. %@AS@%     else
  6594. %@AS@%        printf( "No game adapter installed\n" );
  6595. %@AS@%  }%@AE@%%@NL@%
  6596. %@NL@%
  6597. %@NL@%
  6598. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6599. %@NL@%
  6600. %@AS@%  
  6601. %@AS@%  
  6602. %@AS@%  Equipment bits: 0x4061
  6603. %@AS@%  No game adapter installed%@AE@%%@NL@%
  6604. %@NL@%
  6605. %@NL@%
  6606. %@NL@%
  6607. %@NL@%
  6608. %@QR:_bios_keybrd@%%@NL@%
  6609. %@2@%%@CR:C6A00240203 @%%@AB@%_bios_keybrd%@AE@%%@EH@%%@NL@%
  6610. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6611. %@NL@%
  6612. %@NL@%
  6613. %@3@%%@AB@%Description%@CR:C6A00240204 @% %@CR:C6A00240205 @%%@AE@%%@EH@%%@NL@%
  6614. %@NL@%
  6615. Calls BIOS keyboard services, using INT 0x16.  %@NL@%
  6616. %@NL@%
  6617. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  6618. %@NL@%
  6619. %@AS@%  unsigned _bios_keybrd( unsigned service );%@AE@%%@NL@%
  6620. %@NL@%
  6621. %@AI@%service%@AE@%                           Keyboard function desired
  6622.  
  6623. %@NL@%
  6624. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6625. %@NL@%
  6626. The %@AB@%_bios_keybrd%@AE@% routine uses system call INT 0x16 to access the keyboard
  6627. services. The %@AI@%service%@AE@% argument can be any of the following manifest
  6628. constants:  %@NL@%
  6629. %@NL@%
  6630. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  6631. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6632. %@AB@%_KEYBRD_READ%@AE@%,%@AB@%%@AE@%                     Reads the next character from the 
  6633. %@AB@%_NKEYBRD_READ%@AE@%                     keyboard. If no character has been 
  6634.                                   typed, the call will wait for one. If 
  6635.                                   the low-order byte of the return value 
  6636.                                   is nonzero, the call contains the ASCII 
  6637.                                   value of the character typed. The 
  6638.                                   high-order byte contains the keyboard 
  6639.                                   scan code for the character. The %@AB@%%@AE@%
  6640.                                   %@AB@%_NKEYBRD_READ%@AE@% constant is used with 
  6641.                                   enhanced keyboards to obtain the scan 
  6642.                                   codes for function keys F11 and F12 and 
  6643.                                   the cursor control keys. 
  6644.  
  6645. %@AB@%_KEYBRD_READY%@AE@%,%@AB@%%@AE@%                    Checks whether a keystroke is waiting to
  6646. %@AB@%_NKEYBRD_READY%@AE@%                    be read and, if so, reads it. The return
  6647.                                   value is 0 if no keystroke is waiting, 
  6648.                                   or it is the character waiting to be 
  6649.                                   read, in the same format as the %@AB@%%@AE@%
  6650.                                   %@AB@%_KEYBRD_READ%@AE@% or  %@AB@%_NKEYBRD_READY%@AE@% return. 
  6651.                                   This service does not remove the waiting
  6652.                                   character from the input buffer, as does
  6653.                                   the%@AB@% _KEYBRD_READ%@AE@% or %@AB@%_NKEYBRD_READ%@AE@% 
  6654.                                   service.  The %@AB@%_NKEYBRD_READY%@AE@% constant is
  6655.                                   used with enhanced keyboards to obtain 
  6656.                                   the scan codes for function keys F11 and
  6657.                                   F12 and the cursor control keys.
  6658.  
  6659. %@AB@%_KEYBRD_SHIFTSTATUS%@AE@%, %@AB@%%@AE@%             Returns the current SHIFT-key status. 
  6660. %@AB@%_NKEYBRD_SHIFTSTATUS%@AE@%              Only the low-order byte of the return 
  6661.                                   value is affected. The %@AB@%%@AE@%
  6662.                                   %@AB@%_NKEYBRD_SHIFTSTATUS%@AE@% constant is used to
  6663.                                   get a full 16-bit status value. Any 
  6664.                                   combination of the following bits may be
  6665.                                   set:
  6666.  
  6667.                                   %@AB@%Bit%@AE@%         %@AB@%Meaning%@AE@% %@AB@%if%@AE@% %@AB@%True%@AE@%
  6668. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6669.                                   00H         Rightmost SHIFT key pressed
  6670.  
  6671.                                   01H         Leftmost SHIFT key pressed
  6672.  
  6673.                                   02H         Either CTRL key pressed
  6674.  
  6675.                                   3H          Either ALT key pressed
  6676.  
  6677.                                   04H         SCROLL LOCK on
  6678.  
  6679.                                   05H         NUM LOCK on
  6680.  
  6681.                                   06H         CAPS LOCK on
  6682.  
  6683.                                   07H         In insert mode (INS)
  6684.  
  6685.                                   08H         Left CTRL key pressed
  6686.  
  6687.                                   09H         Left ALT key pressed
  6688.  
  6689.                                   0AH         Right CTRL key pressed
  6690.  
  6691.                                   0BH         Right ALT key pressed
  6692.  
  6693.                                   0CH         SCROLL LOCK key pressed
  6694.  
  6695.                                   0DH         NUM LOCK key pressed
  6696.  
  6697.                                   0EH         CAPS LOCK key pressed
  6698.  
  6699.                                   0FH         SYS REQ key pressed
  6700.  
  6701. %@NL@%
  6702. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6703. %@NL@%
  6704. With the %@AB@%...READ%@AE@% and %@AB@%...SHIFTSTATUS%@AE@% arguments, the %@AB@%_bios_keybrd%@AE@% function
  6705. returns the contents of the AX register after the BIOS call.  %@NL@%
  6706. %@NL@%
  6707. With the %@AB@%...READY%@AE@% argument, %@AB@%_bios_keybrd%@AE@% returns 0 if there is no key. If
  6708. there is a key, %@AB@%_bios_keybrd%@AE@% returns the key waiting to be read (i.e. the
  6709. same value as %@AB@%_KEYBRD_READ%@AE@%).  %@NL@%
  6710. %@NL@%
  6711. With the %@AB@%...READ%@AE@% and the %@AB@%...READY%@AE@% arguments, the %@AB@%_bios_keybrd%@AE@% function
  6712. returns -1 if CTRL+BREAK has been pressed and is the next keystroke to be
  6713. read.  %@NL@%
  6714. %@NL@%
  6715. %@NL@%
  6716. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6717. %@NL@%
  6718.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  6719. %@NL@%
  6720. %@NL@%
  6721. %@NL@%
  6722. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6723. %@NL@%
  6724. %@AS@%  /* BKEYBRD.C: This program prints a message on the screen until the
  6725. %@AS@%   * right SHIFT key is pressed.
  6726. %@AS@%   */
  6727. %@AS@%  
  6728. %@AS@%  #include <bios.h>
  6729. %@AS@%  #include <stdio.h>
  6730. %@AS@%  
  6731. %@AS@%  void main()
  6732. %@AS@%  {
  6733. %@AS@%     while( !(_bios_keybrd( _KEYBRD_SHIFTSTATUS ) & 0001) )
  6734. %@AS@%        printf( "Use the right SHIFT key to stop this message\n" );
  6735. %@AS@%     printf( "Right SHIFT key pressed\n" );
  6736. %@AS@%  }%@AE@%%@NL@%
  6737. %@NL@%
  6738. %@NL@%
  6739. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6740. %@NL@%
  6741. %@AS@%  
  6742. %@AS@%  
  6743. %@AS@%  Use the right SHIFT key to stop this message
  6744. %@AS@%  Use the right SHIFT key to stop this message
  6745. %@AS@%  Use the right SHIFT key to stop this message
  6746. %@AS@%  Use the right SHIFT key to stop this message
  6747. %@AS@%  Right SHIFT key pressed%@AE@%%@NL@%
  6748. %@NL@%
  6749. %@NL@%
  6750. %@NL@%
  6751. %@NL@%
  6752. %@QR:_bios_memsize@%%@NL@%
  6753. %@2@%%@CR:C6A00250206 @%%@AB@%_bios_memsize%@AE@%%@EH@%%@NL@%
  6754. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6755. %@NL@%
  6756. %@NL@%
  6757. %@3@%%@AB@%Description%@CR:C6A00250207 @% %@CR:C6A00250208 @%%@AE@%%@EH@%%@NL@%
  6758. %@NL@%
  6759. Calls the BIOS memory-size service, using system call INT 0x12.  %@NL@%
  6760. %@NL@%
  6761. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  6762. %@NL@%
  6763. %@AS@%  unsigned _bios_memsize( void );%@AE@%%@NL@%
  6764. %@NL@%
  6765. %@NL@%
  6766. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6767. %@NL@%
  6768. The %@AB@%_bios_memsize%@AE@% routine uses system call INT 0x12 to determine the total
  6769. amount of main memory installed.  %@NL@%
  6770. %@NL@%
  6771. %@NL@%
  6772. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6773. %@NL@%
  6774. The routine returns the total amount of installed memory in 1K blocks. The
  6775. maximum return value is 640, representing 640K of main memory.  %@NL@%
  6776. %@NL@%
  6777. %@NL@%
  6778. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6779. %@NL@%
  6780.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  6781. %@NL@%
  6782. %@NL@%
  6783. %@NL@%
  6784. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6785. %@NL@%
  6786. %@AS@%  /* BMEMSIZE.C: This program displays the amount of memory installed. */
  6787. %@AS@%  
  6788. %@AS@%  #include <bios.h>
  6789. %@AS@%  #include <stdio.h>
  6790. %@AS@%  
  6791. %@AS@%  void main()
  6792. %@AS@%  {
  6793. %@AS@%     unsigned memory;
  6794. %@AS@%  
  6795. %@AS@%     memory = _bios_memsize();
  6796. %@AS@%     printf ( "The amount of memory installed is: %dK\n", memory );
  6797. %@AS@%  }%@AE@%%@NL@%
  6798. %@NL@%
  6799. %@NL@%
  6800. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6801. %@NL@%
  6802. %@AS@%  
  6803. %@AS@%  
  6804. %@AS@%  The amount of memory installed is: 639K%@AE@%%@NL@%
  6805. %@NL@%
  6806. %@NL@%
  6807. %@NL@%
  6808. %@NL@%
  6809. %@QR:_bios_printer@%%@NL@%
  6810. %@2@%%@CR:C6A00260209 @%%@AB@%_bios_printer%@AE@%%@EH@%%@NL@%
  6811. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6812. %@NL@%
  6813. %@NL@%
  6814. %@3@%%@AB@%Description%@CR:C6A00260210 @% %@CR:C6A00260211 @%%@AE@%%@EH@%%@NL@%
  6815. %@NL@%
  6816. Calls BIOS printer services using system call INT 0x17.  %@NL@%
  6817. %@NL@%
  6818. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  6819. %@NL@%
  6820. %@AS@%  unsigned _bios_printer( unsigned service, unsigned printer, unsigned data
  6821. %@AS@%  );%@AE@%%@NL@%
  6822. %@NL@%
  6823. %@AI@%service%@AE@%                           Printer function desired
  6824.  
  6825. %@AI@%printer%@AE@%                           Target printer port
  6826.  
  6827. %@AI@%data%@AE@%                              Output data
  6828.  
  6829. %@NL@%
  6830. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6831. %@NL@%
  6832. The %@AB@%_bios_printer%@AE@% routine uses system call INT 0x17 to perform printer
  6833. output services for parallel printers. The %@AI@%printer%@AE@% argument specifies the
  6834. affected printer, where 0 is LPT1, 1 is LPT2, and so forth.  %@NL@%
  6835. %@NL@%
  6836. Some printers do not support the full set of signals. As a result, the "Out
  6837. of Paper" condition, for example, may not be returned to your program.  %@NL@%
  6838. %@NL@%
  6839. The %@AI@%service%@AE@% argument can be any of the following manifest constants:  %@NL@%
  6840. %@NL@%
  6841. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  6842. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6843. %@AB@%_PRINTER_INIT%@AE@%                     Initializes the selected printer. The %@AI@%%@AE@%
  6844.                                   %@AI@%data%@AE@% argument is ignored. The return 
  6845.                                   value is the low-order status byte 
  6846.                                   defined below.
  6847.  
  6848. %@AB@%_PRINTER_STATUS%@AE@%                   Returns the printer status in the 
  6849.                                   low-order status byte defined below. The%@AI@%%@AE@%
  6850.                                   %@AI@%data%@AE@% argument is ignored.
  6851.  
  6852. %@AB@%_PRINTER_WRITE%@AE@%                    Sends the low-order byte of %@AI@%data%@AE@% to the 
  6853.                                   printer specified by %@AI@%printer%@AE@%. The 
  6854.                                   low-order byte of the return value 
  6855.                                   indicates the printer status after the 
  6856.                                   operation, as defined below:%@AI@%%@AE@%
  6857.  
  6858.                                   %@AB@%Bit%@AE@%      %@AB@%Meaning%@AE@% %@AB@%if%@AE@% %@AB@%True%@AE@%
  6859. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6860.                                   0         Printer timed out
  6861.  
  6862.                                   1         Not used
  6863.  
  6864.                                   2         Not used
  6865.  
  6866.                                   3         I/O error
  6867.  
  6868.                                   4         Printer selected
  6869.  
  6870.                                   5         Out of paper
  6871.  
  6872.                                   6         Acknowledge
  6873.  
  6874.                                   7         Printer not busy
  6875.  
  6876. %@AB@%%@AE@%
  6877.  
  6878. %@NL@%
  6879. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  6880. %@NL@%
  6881. The %@AB@%_bios_printer%@AE@% function returns the value in the AX register after the
  6882. BIOS interrupt.  %@NL@%
  6883. %@NL@%
  6884. %@NL@%
  6885. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  6886. %@NL@%
  6887.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  6888. %@NL@%
  6889. %@NL@%
  6890. %@NL@%
  6891. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  6892. %@NL@%
  6893. %@AS@%  /* BPRINTER.C: This program checks the status of the printer attached to
  6894. %@AS@%   * LPT1 when it is off line, then initializes the printer.
  6895. %@AS@%   */
  6896. %@AS@%  
  6897. %@AS@%  #include <bios.h>
  6898. %@AS@%  #include <conio.h>
  6899. %@AS@%  #include <stdio.h>
  6900. %@AS@%  
  6901. %@AS@%  #define LPT1 0
  6902. %@AS@%  
  6903. %@AS@%  void main()
  6904. %@AS@%  {
  6905. %@AS@%     unsigned status;
  6906. %@AS@%  
  6907. %@AS@%     printf ( "Place printer off line and press any key\n" );
  6908. %@AS@%     getch();
  6909. %@AS@%  
  6910. %@AS@%     status = _bios_printer( _PRINTER_STATUS, LPT1, 0 );
  6911. %@AS@%     printf( "Status with printer off line: 0x%.4x\n\n", status );
  6912. %@AS@%     printf( "Put the printer on line and then\n" );
  6913. %@AS@%     printf( "Press any key to initialize printer\n" );
  6914. %@AS@%     getch();
  6915. %@AS@%  
  6916. %@AS@%     status = _bios_printer( _PRINTER_INIT, LPT1, 0 );
  6917. %@AS@%     printf( "Status after printer initialized: 0x%.4x\n", status );
  6918. %@AS@%  }%@AE@%%@NL@%
  6919. %@NL@%
  6920. %@NL@%
  6921. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  6922. %@NL@%
  6923. %@AS@%  
  6924. %@AS@%  
  6925. %@AS@%  Place printer off line and press any key
  6926. %@AS@%  Status with printer off line: 0x0018
  6927. %@AS@%  
  6928. %@AS@%  Put the printer on line and then
  6929. %@AS@%  Press any key to initialize printer
  6930. %@AS@%  Status after printer initialized: 0x0090%@AE@%%@NL@%
  6931. %@NL@%
  6932. %@NL@%
  6933. %@NL@%
  6934. %@NL@%
  6935. %@QR:_bios_serialcom@%%@NL@%
  6936. %@2@%%@CR:C6A00270212 @%%@AB@%_bios_serialcom%@AE@%%@EH@%%@NL@%
  6937. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6938. %@NL@%
  6939. %@NL@%
  6940. %@3@%%@AB@%Description%@CR:C6A00270213 @% %@CR:C6A00270214 @%%@AE@%%@EH@%%@NL@%
  6941. %@NL@%
  6942. Calls BIOS communications services, using system call INT 0x14.  %@NL@%
  6943. %@NL@%
  6944. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  6945. %@NL@%
  6946. %@AS@%  unsigned _bios_serialcom( unsigned service, unsigned serial_port, unsigned
  6947. %@AS@%  data );%@AE@%%@NL@%
  6948. %@NL@%
  6949. %@AI@%service%@AE@%                           Communications service
  6950.  
  6951. %@AI@%serial_port%@AE@%                       Serial port to use
  6952.  
  6953. %@AI@%data%@AE@%                              Port configuration bits
  6954.  
  6955. %@NL@%
  6956. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  6957. %@NL@%
  6958. The %@AB@%_bios_serialcom%@AE@% routine uses system call INT 0x14 to provide serial
  6959. communications services. The %@AI@%serial_port%@AE@% argument is set to 0 for COM1, to 1
  6960. for COM2, and so on.  %@NL@%
  6961. %@NL@%
  6962. The %@AB@%_bios_serialcom%@AE@% routine may not be able to establish reliable
  6963. communications at baud rates in excess of 1,200 baud ( %@AB@%_COM_1200%@AE@%) due to the
  6964. overhead associated with servicing computer interrupts. Faster data
  6965. communication rates are possible with more direct programming of serial-port
  6966. controllers. See %@AI@%C Programmer's Guide to Serial Communications%@AE@% for more
  6967. details on serial-communications programming in C.  %@NL@%
  6968. %@NL@%
  6969. The %@AI@%service%@AE@% argument can be set to one of the following manifest constants:
  6970. %@NL@%
  6971. %@NL@%
  6972. %@AB@%Constant%@AE@%                          %@AB@%Service%@AE@%
  6973. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6974. %@AB@%_COM_INIT%@AE@%                         Sets the port to the parameters 
  6975.                                   specified in the %@AI@%data%@AE@% argument
  6976.  
  6977. %@AB@%_COM_SEND%@AE@%                         Transmits the %@AI@%data%@AE@% characters over the 
  6978.                                   selected serial port
  6979.  
  6980. %@AB@%_COM_RECEIVE%@AE@%                      Accepts an input character from the 
  6981.                                   selected serial port
  6982.  
  6983. %@AB@%_COM_STATUS%@AE@%                       Returns the current status of the 
  6984.                                   selected serial port
  6985.  
  6986. The %@AI@%data%@AE@% argument is ignored if %@AI@%service%@AE@% is set to %@AB@%_COM_RECEIVE%@AE@% or
  6987. %@AB@%_COM_STATUS.%@AE@% The %@AI@%data%@AE@% argument for %@AB@%_COM_INIT%@AE@% is created by combining (with
  6988. the OR operator) one or more of the following constants:  %@NL@%
  6989. %@NL@%
  6990. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  6991. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  6992. %@AB@%_COM_CHR7 %@AE@%                        7 data bits
  6993.  
  6994. %@AB@%_COM_CHR8%@AE@%                         8 data bits
  6995.  
  6996. %@AB@%_COM_STOP1%@AE@%                        1 stop bit
  6997.  
  6998. %@AB@%_COM_STOP2%@AE@%                        2 stop bits
  6999.  
  7000. %@AB@%_COM_NOPARITY%@AE@%                     No parity
  7001.  
  7002. %@AB@%_COM_EVENPARITY%@AE@%                   Even parity
  7003.  
  7004. %@AB@%_COM_ODDPARITY%@AE@%                    Odd parity
  7005.  
  7006. %@AB@%_COM_110%@AE@%                          110 baud
  7007.  
  7008. %@AB@%_COM_150%@AE@%                          150 baud
  7009.  
  7010. %@AB@%_COM_300%@AE@%                          300 baud
  7011.  
  7012. %@AB@%_COM_600%@AE@%                          600 baud
  7013.  
  7014. %@AB@%_COM_1200%@AE@%                         1,200 baud
  7015.  
  7016. %@AB@%_COM_2400%@AE@%                         2,400 baud
  7017.  
  7018. %@AB@%_COM_4800%@AE@%                         4,800 baud
  7019.  
  7020. %@AB@%_COM_9600%@AE@%                         9,600 baud
  7021.  
  7022. The default value of %@AI@%data%@AE@% is 1 stop bit, no parity, and 110 baud.  %@NL@%
  7023. %@NL@%
  7024. %@NL@%
  7025. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7026. %@NL@%
  7027. The function returns a 16-bit integer whose high-order byte contains status
  7028. bits. The meaning of the low-order byte varies, depending on the %@AI@%service%@AE@%
  7029. value. The high-order bits have the following meanings:  %@NL@%
  7030. %@NL@%
  7031. %@AB@%Bit%@AE@%                               %@AB@%Meaning if Set%@AE@%
  7032. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7033. 15                                Timed out
  7034.  
  7035. 14                                Transmission-shift register empty
  7036.  
  7037. 13                                Transmission-hold register empty
  7038.  
  7039. 12                                Break detected
  7040.  
  7041. 11                                Framing error
  7042.  
  7043. 10                                Parity error
  7044.  
  7045. 9                                 Overrun error
  7046.  
  7047. 8                                 Data ready
  7048.  
  7049. When %@AI@%service%@AE@% is%@AB@% _COM_SEND%@AE@%, bit 15 will be set if %@AI@%data%@AE@% could not be sent.  %@NL@%
  7050. %@NL@%
  7051. When %@AI@%service%@AE@% is %@AB@%_COM_RECEIVE%@AE@%, the byte read will be returned in the
  7052. low-order bits if the call is successful. If an error occurs, any of the
  7053. bits 9, 10, 11, or 15 will be set.  %@NL@%
  7054. %@NL@%
  7055. When %@AI@%service%@AE@% is %@AB@%_COM_INIT%@AE@% or %@AB@%_COM_STATUS%@AE@%, the low-order bits are defined as
  7056. follows:  %@NL@%
  7057. %@NL@%
  7058. %@AB@%Bit%@AE@%                               %@AB@%Meaning if Set%@AE@%
  7059. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7060. 7                                 Receive-line signal detected
  7061.  
  7062. 6                                 Ring indicator
  7063.  
  7064. 5                                 Data set ready
  7065.  
  7066. 4                                 Clear to send
  7067.  
  7068. 3                                 Change in receive-line signal detected
  7069.  
  7070. 2                                 Trailing-edge ring indicator
  7071.  
  7072. 1                                 Change in data-set-ready status
  7073.  
  7074. 0                                 Change in clear-to-send status
  7075.  
  7076. Note that this function works only with IBM personal computers and true
  7077. compatibles.  %@NL@%
  7078. %@NL@%
  7079. %@NL@%
  7080. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7081. %@NL@%
  7082.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  7083. %@NL@%
  7084. %@NL@%
  7085. %@NL@%
  7086. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7087. %@NL@%
  7088. %@AS@%  /* BSERIALC.C: This program checks the status of serial port COM1. */
  7089. %@AS@%  
  7090. %@AS@%  #include <bios.h>
  7091. %@AS@%  #include <stdio.h>
  7092. %@AS@%  
  7093. %@AS@%  void main()
  7094. %@AS@%  {
  7095. %@AS@%     unsigned com1_status;
  7096. %@AS@%  
  7097. %@AS@%     com1_status =  _bios_serialcom( _COM_STATUS, 0, 0 );
  7098. %@AS@%     printf ( "COM1 status: 0x%.4x\n", com1_status );
  7099. %@AS@%  }%@AE@%%@NL@%
  7100. %@NL@%
  7101. %@NL@%
  7102. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7103. %@NL@%
  7104. %@AS@%  
  7105. %@AS@%  
  7106. %@AS@%  COM1 status: 0x6000%@AE@%%@NL@%
  7107. %@NL@%
  7108. %@NL@%
  7109. %@NL@%
  7110. %@NL@%
  7111. %@QR:_bios_timeofday@%%@NL@%
  7112. %@2@%%@CR:C6A00280215 @%%@AB@%_bios_timeofday%@AE@%%@EH@%%@NL@%
  7113. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7114. %@NL@%
  7115. %@NL@%
  7116. %@3@%%@AB@%Description%@CR:C6A00280216 @% %@CR:C6A00280217 @%%@AE@%%@EH@%%@NL@%
  7117. %@NL@%
  7118. Calls BIOS time and date services, using system call INT 0x1A.  %@NL@%
  7119. %@NL@%
  7120. %@AB@%#include <bios.h>%@AE@%  %@NL@%
  7121. %@NL@%
  7122. %@AS@%  unsigned _bios_timeofday( unsigned service, long *timeval );%@AE@%%@NL@%
  7123. %@NL@%
  7124. %@AI@%service%@AE@%                           Time function desired
  7125.  
  7126. %@AI@%timeval%@AE@%                           Clock count
  7127.  
  7128. %@NL@%
  7129. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7130. %@NL@%
  7131. The %@AB@%_bios_timeofday%@AE@% routine uses system call INT 0x1A to get or set the
  7132. clock count. The %@AI@%service%@AE@% argument can be either of the following manifest
  7133. constants:  %@NL@%
  7134. %@NL@%
  7135. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  7136. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7137. %@AB@%_TIME_GETCLOCK%@AE@%                    Copies the current value of the clock 
  7138.                                   count to the location pointed to by %@AI@%%@AE@%
  7139.                                   %@AI@%timeval%@AE@%. If midnight has not passed 
  7140.                                   since the last time the system clock was
  7141.                                   read or set, the function returns 0; 
  7142.                                   otherwise, the function returns 1.
  7143.  
  7144. %@AB@%_TIME_SETCLOCK%@AE@%                    Sets the current value of the system 
  7145.                                   clock to the value in the location 
  7146.                                   pointed to by %@AI@%timeval%@AE@%. There is no 
  7147.                                   return value.
  7148.  
  7149. %@NL@%
  7150. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7151. %@NL@%
  7152. The %@AB@%_bios_timeofday%@AE@% function returns the value in the AX register after the
  7153. BIOS interrupt.  %@NL@%
  7154. %@NL@%
  7155. %@NL@%
  7156. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7157. %@NL@%
  7158.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  7159. %@NL@%
  7160. %@NL@%
  7161. %@NL@%
  7162. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7163. %@NL@%
  7164. %@AS@%  /* BTIMEOFD.C: This program gets the current system clock count before and
  7165. %@AS@%  after
  7166. %@AS@%   * a "do-nothing" loop and displays the difference.
  7167. %@AS@%   */
  7168. %@AS@%  
  7169. %@AS@%  #include <bios.h>
  7170. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  7171. %@NL@%
  7172. %@AS@%  void main()
  7173. %@AS@%  {
  7174. %@AS@%     long i, begin_tick, end_tick;
  7175. %@AS@%  
  7176. %@AS@%     _bios_timeofday( _TIME_GETCLOCK, &begin_tick );
  7177. %@AS@%     printf( "Beginning tick count: %lu\n", begin_tick );
  7178. %@AS@%     for( i = 1; i <= 900000; i++ )
  7179. %@AS@%        ;
  7180. %@AS@%     _bios_timeofday( _TIME_GETCLOCK, &end_tick );
  7181. %@AS@%     printf( "Ending tick count:    %lu\n", end_tick );
  7182. %@AS@%     printf( "Elapsed ticks:        %lu\n", end_tick - begin_tick );
  7183. %@AS@%  }%@AE@%%@NL@%
  7184. %@NL@%
  7185. %@NL@%
  7186. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7187. %@NL@%
  7188. %@AS@%  
  7189. %@AS@%  
  7190. %@AS@%  Beginning tick count: 1114255
  7191. %@AS@%  Ending tick count:    1114287
  7192. %@AS@%  Elapsed ticks:        32 %@AE@%%@NL@%
  7193. %@NL@%
  7194. %@NL@%
  7195. %@NL@%
  7196. %@NL@%
  7197. %@QR:bsearch@%%@NL@%
  7198. %@2@%%@CR:C6A00290218 @%%@AB@%bsearch%@AE@%%@EH@%%@NL@%
  7199. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7200. %@NL@%
  7201. %@NL@%
  7202. %@3@%%@AB@%Description%@CR:C6A00290219 @%%@CR:C6A00290220 @%%@CR:C6A00290221 @%%@AE@%%@EH@%%@NL@%
  7203. %@NL@%
  7204. Performs binary search of a sorted array.  %@NL@%
  7205. %@NL@%
  7206. %@AB@%#include <stdlib.h>%@AE@%               Required for ANSI compatibility
  7207.  
  7208. %@AB@%#include <search.h>%@AE@%               Required only for function declarations
  7209.  
  7210. %@AS@%  void *bsearch( const void *key, const void *base, size_t num, size_t
  7211. %@AS@%  width, 
  7212. %@AS@%  int ( *compare )( const void *elem1, const void *elem2 ) );%@AE@%%@NL@%
  7213. %@NL@%
  7214. %@AI@%key%@AE@%                               Object to search for
  7215.  
  7216. %@AI@%base%@AE@%                              Pointer to base of search data
  7217.  
  7218. %@AI@%num%@AE@%                               Number of elements
  7219.  
  7220. %@AI@%width%@AE@%                             Width of elements
  7221.  
  7222. %@AI@%compare%@AE@%                           Function that compares two elements:  %@AI@%%@AE@%
  7223.                                   %@AI@%elem1%@AE@% and %@AI@%elem2%@AE@%
  7224.  
  7225. %@AI@%elem1%@AE@%                             Pointer to the key for the search
  7226.  
  7227. %@AI@%elem2%@AE@%                             Pointer to the array element to be 
  7228.                                   compared with the key
  7229.  
  7230. %@NL@%
  7231. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7232. %@NL@%
  7233. The %@AB@%bsearch%@AE@% function performs a binary search of a sorted array of %@AI@%num%@AE@%
  7234. elements, each of %@AI@%width%@AE@% bytes in size. The %@AI@%base%@AE@% value is a pointer to the
  7235. base of the array to be searched, and %@AI@%key%@AE@% is the value being sought.  %@NL@%
  7236. %@NL@%
  7237. The %@AI@%compare%@AE@% argument is a pointer to a user-supplied routine that compares
  7238. two array elements and returns a value specifying their relationship. The
  7239. %@AB@%bsearch%@AE@% function calls the %@AI@%compare%@AE@% routine one or more times during the
  7240. search, passing pointers to two array elements on each call. The routine
  7241. compares the elements, then returns one of the following values:  %@NL@%
  7242. %@NL@%
  7243. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  7244. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7245. < 0                               %@AI@%elem1%@AE@% less than %@AI@%elem2%@AE@%
  7246.  
  7247. = 0                               %@AI@%elem1%@AE@% identical to %@AI@%elem2%@AE@%
  7248.  
  7249. > 0                               %@AI@%elem1%@AE@% greater than %@AI@%elem2%@AE@%
  7250.  
  7251. If the array you are searching is not in ascending sort order, %@AB@%bsearch%@AE@% does
  7252. not work properly. If the array contains duplicate records with identical
  7253. keys, there is no way to predict which of the duplicate records will be
  7254. located by %@AB@%bsearch%@AE@%.  %@NL@%
  7255. %@NL@%
  7256. %@NL@%
  7257. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7258. %@NL@%
  7259. The %@AB@%bsearch%@AE@% function returns a pointer to the first occurrence of %@AI@%key%@AE@% in the
  7260. array pointed to by %@AI@%base%@AE@%. If %@AI@%key%@AE@% is not found, the function returns %@AB@%NULL%@AE@%.  %@NL@%
  7261. %@NL@%
  7262. %@NL@%
  7263. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7264. %@NL@%
  7265. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  7266. %@NL@%
  7267. %@NL@%
  7268. %@NL@%
  7269. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7270. %@NL@%
  7271. %@AB@%lfind%@AE@%, %@AB@%lsearch%@AE@%, %@AB@%qsort%@AE@%  %@NL@%
  7272. %@NL@%
  7273. %@NL@%
  7274. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7275. %@NL@%
  7276. %@AS@%  /* BSEARCH.C: This program reads the command-line arguments, sorting them
  7277. %@AS@%   * with qsort, and then uses bsearch to find the word "cat."
  7278. %@AS@%   */
  7279. %@AS@%  
  7280. %@AS@%  #include <search.h>
  7281. %@AS@%  #include <string.h>
  7282. %@AS@%  #include <stdio.h>
  7283. %@AS@%  
  7284. %@AS@%  int compare( char **arg1, char **arg2 );  /* Declare a function for
  7285. %@AS@%compare */
  7286. %@AS@%  
  7287. %@AS@%  void main( int argc, char **argv )
  7288. %@AS@%  {
  7289. %@AS@%  
  7290. %@AS@%     char **result;
  7291. %@AS@%     char *key = "cat";
  7292. %@AS@%     int i;
  7293. %@AS@%  
  7294. %@AS@%     /* Sort using Quicksort algorithm: */
  7295. %@AS@%     qsort( (char *)argv, argc, sizeof( char * ), compare );
  7296. %@AS@%  
  7297. %@AS@%     for( i = 0; i < argc; ++i )        /* Output sorted list */
  7298. %@AS@%        printf( "%s ", argv[i] );
  7299. %@AS@%  
  7300. %@AS@%     /*  Find the word "cat" using a binary search algorithm: */
  7301. %@AS@%     result = (char **)bsearch( (char *) &key, (char *)argv, argc,
  7302. %@AS@%                                sizeof( char * ), compare );
  7303. %@AS@%     if( result )
  7304. %@AS@%        printf( "\n%s found at %Fp\n", *result, result );
  7305. %@AS@%     else
  7306. %@AS@%        printf( "\nCat not found!\n" );
  7307. %@AS@%  }
  7308. %@AS@%  
  7309. %@AS@%  int compare( char **arg1, char **arg2 )
  7310. %@AS@%  {
  7311. %@AS@%     /* Compare all of both strings: */
  7312. %@AS@%     return strcmpi( *arg1, *arg2 );
  7313. %@AS@%  }%@AE@%%@NL@%
  7314. %@NL@%
  7315. %@NL@%
  7316. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7317. %@NL@%
  7318. %@AS@%  
  7319. %@AS@%  
  7320. %@AS@%  [C:\LIBREF] bsearch dog pig horse cat human rat cow goat
  7321. %@AS@%  bsearch cat cow dog goat horse human pig rat
  7322. %@AS@%  cat found at 0292:0FD0 %@AE@%%@NL@%
  7323. %@NL@%
  7324. %@NL@%
  7325. %@NL@%
  7326. %@NL@%
  7327. %@QR:cabs@%%@QR:cabsl@%%@NL@%
  7328. %@2@%%@CR:C6A00300222 @%%@AB@%cabs, cabsl%@AE@%%@EH@%%@NL@%
  7329. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7330. %@NL@%
  7331. %@NL@%
  7332. %@3@%%@AB@%Description%@CR:C6A00300223 @%%@CR:C6A00300224 @%%@CR:C6A00300225 @% %@CR:C6A00300226 @%%@CR:C6A00300227 @%%@AE@%%@EH@%%@NL@%
  7333. %@NL@%
  7334. Calculate absolute value of a complex number.  %@NL@%
  7335. %@NL@%
  7336. %@AS@%  #include <math.h>%@AE@%%@NL@%
  7337. %@NL@%
  7338. %@AS@%  double cabs( struct complex z );%@AE@%%@NL@%
  7339. %@NL@%
  7340. %@AS@%  long double cabsl( struct _complexl z );%@AE@%%@NL@%
  7341. %@NL@%
  7342. %@AI@%z%@AE@%                                 Complex number
  7343.  
  7344. %@NL@%
  7345. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7346. %@NL@%
  7347. The %@AB@%cabs%@AE@% and %@AB@%cabsl%@AE@% functions calculate the absolute value of a complex
  7348. number, which must be a structure of type %@AB@%complex%@AE@% (or %@AB@%_complexl%@AE@%). The
  7349. structure %@AI@%z%@AE@% is composed of a real component %@AI@%x%@AE@% and an imaginary component %@AI@%y%@AE@%.
  7350. A call to one of the %@AB@%cabs%@AE@% routines is equivalent to the following:  %@NL@%
  7351. %@NL@%
  7352. %@AS@%  
  7353. %@AS@%  sqrt( z.x*z.x + z.y*z.y )%@AE@%%@NL@%
  7354. %@NL@%
  7355. The %@AB@%cabsl%@AE@% function is the 80-bit counterpart and it uses the 80-bit, 10-byte
  7356. coprocessor form of arguments and return values. See the reference page on
  7357. the long double functions for more details on this data type.  %@NL@%
  7358. %@NL@%
  7359. %@NL@%
  7360. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7361. %@NL@%
  7362. On overflow, these functions call %@AB@%matherr%@AE@% or %@AB@%_matherrl%@AE@%, return %@AB@%HUGE_VAL%@AE@%, and
  7363. set %@AB@%errno%@AE@% to %@AB@%ERANGE%@AE@%.  %@NL@%
  7364. %@NL@%
  7365. %@NL@%
  7366. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7367. %@NL@%
  7368. %@AS@%  cabs%@AE@%%@NL@%
  7369. %@NL@%
  7370.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  7371. %@NL@%
  7372. %@NL@%
  7373. %@AS@%  cabsl%@AE@%%@NL@%
  7374. %@NL@%
  7375.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  7376. %@NL@%
  7377. %@NL@%
  7378. %@NL@%
  7379. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7380. %@NL@%
  7381. %@AB@%abs%@AE@%, %@AB@%fabs%@AE@%, %@AB@%labs%@AE@%  %@NL@%
  7382. %@NL@%
  7383. %@NL@%
  7384. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7385. %@NL@%
  7386. %@AS@%  /* CABS.C: Using cabs, this program calculates the absolute value of
  7387. %@AS@%   * a complex number.
  7388. %@AS@%   */
  7389. %@AS@%  
  7390. %@AS@%  #include <math.h>
  7391. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  7392. %@NL@%
  7393. %@AS@%  void main()
  7394. %@AS@%  {
  7395. %@AS@%     struct complex number = { 3.0, 4.0 };
  7396. %@AS@%     double d;
  7397. %@AS@%  
  7398. %@AS@%     d = cabs( number );
  7399. %@AS@%     printf( "The absolute value of %f + %fi is %f\n",
  7400. %@AS@%             number.x, number.y, d );
  7401. %@AS@%  }%@AE@%%@NL@%
  7402. %@NL@%
  7403. %@NL@%
  7404. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7405. %@NL@%
  7406. %@AS@%  
  7407. %@AS@%  
  7408. %@AS@%  The absolute value of 3.000000 + 4.000000i is 5.000000 %@AE@%%@NL@%
  7409. %@NL@%
  7410. %@NL@%
  7411. %@NL@%
  7412. %@NL@%
  7413. %@QR:calloc@%%@NL@%
  7414. %@2@%%@CR:C6A00310228 @%%@AB@%calloc Functions%@AE@%%@EH@%%@NL@%
  7415. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7416. %@NL@%
  7417. %@NL@%
  7418. %@3@%%@AB@%Description%@CR:C6A00310229 @%%@CR:C6A00310230 @%%@CR:C6A00310231 @% %@CR:C6A00310232 @%%@CR:C6A00310233 @% %@CR:C6A00310234 @%%@CR:C6A00310235 @% %@CR:C6A00310236 @%%@AE@%%@EH@%%@NL@%
  7419. %@NL@%
  7420. Allocate an array in memory with elements initialized to 0.  %@NL@%
  7421. %@NL@%
  7422. %@AB@%#include <stdlib.h>%@AE@%               For ANSI compatibility (%@AB@%calloc%@AE@% only) 
  7423.  
  7424. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  7425.  
  7426. %@AS@%  void *calloc( size_t num, size_t size );%@AE@%%@NL@%
  7427. %@NL@%
  7428. %@AS@%  void _based( void ) *_bcalloc( _segment seg, size_t num, size_t size );%@AE@%%@NL@%
  7429. %@NL@%
  7430. %@AS@%  void _far *_fcalloc( size_t num, size_t size );%@AE@%%@NL@%
  7431. %@NL@%
  7432. %@AS@%  void _near *_ncalloc( size_t num, size_t size );%@AE@%%@NL@%
  7433. %@NL@%
  7434. %@AI@%num%@AE@%                               Number of elements
  7435.  
  7436. %@AI@%size%@AE@%                              Length in bytes of each element
  7437.  
  7438. %@AI@%seg%@AE@%                               Segment selector
  7439.  
  7440. %@NL@%
  7441. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7442. %@NL@%
  7443. The %@AB@%calloc%@AE@% family of functions allocates storage space for an array of %@AI@%num%@AE@%
  7444. elements, each of length %@AI@%size%@AE@% bytes. Each element is initialized to 0.  %@NL@%
  7445. %@NL@%
  7446. In large data models (compact-, large-, and huge-model programs), %@AB@%calloc%@AE@%
  7447. maps to %@AB@% _fcalloc%@AE@%. In small data models (tiny-, small-, and medium-model
  7448. programs), %@AB@%calloc%@AE@% maps to %@AB@%_ncalloc%@AE@%.  %@NL@%
  7449. %@NL@%
  7450. The various %@AB@%calloc%@AE@% functions allocate storage space in the data segments
  7451. shown in the list below:  %@NL@%
  7452. %@NL@%
  7453. %@AB@%Function%@AE@%                          %@AB@%Data Segment%@AE@%
  7454. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7455. %@AB@%calloc%@AE@%                            Depends on data model of program
  7456.  
  7457. %@AB@%_bcalloc%@AE@%                          Based heap, specified by %@AI@%seg%@AE@% segment 
  7458.                                   selector
  7459.  
  7460. %@AB@%_fcalloc%@AE@%                          Far heap (outside default data segment)
  7461.  
  7462. %@AB@%_ncalloc%@AE@%                          Near heap (inside default data segment)
  7463.  
  7464. %@NL@%
  7465. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7466. %@NL@%
  7467. The %@AB@%calloc%@AE@% functions return a pointer to the allocated space. The storage
  7468. space pointed to by the return value is guaranteed to be suitably aligned
  7469. for storage of any type of object. To get a pointer to a type other than
  7470. %@AB@%void%@AE@%, use a type cast on the return value.  %@NL@%
  7471. %@NL@%
  7472. The %@AB@%_fcalloc%@AE@% and %@AB@%_ncalloc%@AE@% functions return %@AB@%NULL%@AE@% if there is insufficient
  7473. memory available or if %@AI@%num%@AE@% or %@AI@%size%@AE@% is 0. The %@AB@%_bcalloc%@AE@% function returns
  7474. %@AB@%_NULLOFF%@AE@% in this case.  %@NL@%
  7475. %@NL@%
  7476. %@NL@%
  7477. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7478. %@NL@%
  7479. %@AS@%  calloc%@AE@%%@NL@%
  7480. %@NL@%
  7481. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  7482. %@NL@%
  7483. %@NL@%
  7484. %@AB@%_bcalloc%@AE@%, %@AB@%_fcalloc%@AE@%, %@AB@%_ncalloc%@AE@%  %@NL@%
  7485. %@NL@%
  7486.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  7487. %@NL@%
  7488. %@NL@%
  7489. %@NL@%
  7490. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7491. %@NL@%
  7492. %@AB@%free %@AE@%functions, %@AB@%halloc%@AE@%, %@AB@%hfree%@AE@%, %@AB@%malloc %@AE@%functions, %@AB@%realloc%@AE@% functions  %@NL@%
  7493. %@NL@%
  7494. %@NL@%
  7495. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7496. %@NL@%
  7497. %@AS@%  /* CALLOC.C: This program uses calloc to allocate space for 40 long
  7498. %@AS@%  integers.
  7499. %@AS@%   * It initializes each element to zero.
  7500. %@AS@%   */
  7501. %@AS@%  
  7502. %@AS@%  #include <stdio.h>
  7503. %@AS@%  #include <malloc.h>
  7504. %@AS@%  
  7505. %@AS@%  void main()
  7506. %@AS@%  {
  7507. %@AS@%     long *buffer;
  7508. %@AS@%  
  7509. %@AS@%     buffer = (long *)calloc( 40, sizeof( long ) );
  7510. %@AS@%     if( buffer != NULL )
  7511. %@AS@%        printf( "Allocated 40 long integers\n" );
  7512. %@AS@%     else
  7513. %@AS@%        printf( "Can't allocate memory\n" );
  7514. %@AS@%     free( buffer );
  7515. %@AS@%  }%@AE@%%@NL@%
  7516. %@NL@%
  7517. %@NL@%
  7518. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7519. %@NL@%
  7520. %@AS@%  
  7521. %@AS@%  
  7522. %@AS@%  Allocated 40 long integers %@AE@%%@NL@%
  7523. %@NL@%
  7524. %@NL@%
  7525. %@NL@%
  7526. %@NL@%
  7527. %@QR:ceil@%%@QR:ceill@%%@NL@%
  7528. %@2@%%@CR:C6A00320237 @%%@AB@%ceil, ceill%@AE@%%@EH@%%@NL@%
  7529. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7530. %@NL@%
  7531. %@NL@%
  7532. %@3@%%@AB@%Description%@CR:C6A00320238 @%%@CR:C6A00320239 @%%@CR:C6A00320240 @%%@AE@%%@EH@%%@NL@%
  7533. %@NL@%
  7534. Calculate the ceiling of a value.  %@NL@%
  7535. %@NL@%
  7536. %@AS@%  #include <math.h>%@AE@%%@NL@%
  7537. %@NL@%
  7538. %@AS@%  double ceil( double x );%@AE@%%@NL@%
  7539. %@NL@%
  7540. %@AS@%  long double ceill( long double x );%@AE@%%@NL@%
  7541. %@NL@%
  7542. %@AI@%x%@AE@%                                 Floating-point value
  7543.  
  7544. %@NL@%
  7545. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7546. %@NL@%
  7547. The %@AB@%ceil%@AE@% and %@AB@%ceill%@AE@% functions return a %@AB@%double%@AE@% (or %@AB@%long double%@AE@%) value
  7548. representing the smallest integer that is greater than or equal to %@AI@%x%@AE@%.  %@NL@%
  7549. %@NL@%
  7550. The %@AB@%ceill%@AE@% function is the 80-bit counterpart and it uses the 80-bit, 10-byte
  7551. coprocessor form of arguments and return values. See the reference page on
  7552. the long double functions for more details on this data type.  %@NL@%
  7553. %@NL@%
  7554. %@NL@%
  7555. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7556. %@NL@%
  7557. These functions return the %@AB@%double%@AE@% or %@AB@%long double%@AE@% result. There is no error
  7558. return.  %@NL@%
  7559. %@NL@%
  7560. %@NL@%
  7561. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7562. %@NL@%
  7563. %@AS@%  ceil%@AE@%%@NL@%
  7564. %@NL@%
  7565. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  7566. %@NL@%
  7567. %@NL@%
  7568. %@AS@%  ceill%@AE@%%@NL@%
  7569. %@NL@%
  7570.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  7571. %@NL@%
  7572. %@NL@%
  7573. %@NL@%
  7574. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7575. %@NL@%
  7576. %@AB@%floor%@AE@%, %@AB@%fmod%@AE@%  %@NL@%
  7577. %@NL@%
  7578. %@NL@%
  7579. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7580. %@NL@%
  7581. %@AS@%  /* FLOOR.C: This example displays the largest integers less than or equal
  7582. %@AS@%   * to the floating-point values 2.8 and -2.8. It then shows the smallest
  7583. %@AS@%   * integers greater than or equal to 2.8 and -2.8.
  7584. %@AS@%   */
  7585. %@AS@%  
  7586. %@AS@%  #include <math.h>
  7587. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  7588. %@NL@%
  7589. %@AS@%  void main()
  7590. %@AS@%  {
  7591. %@AS@%     double y;
  7592. %@AS@%  
  7593. %@AS@%     y = floor( 2.8 );
  7594. %@AS@%     printf( "The floor of 2.8 is %f\n", y );
  7595. %@AS@%     y = floor( -2.8 );
  7596. %@AS@%     printf( "The floor of -2.8 is %f\n", y );
  7597. %@AS@%  
  7598. %@AS@%     y = ceil( 2.8 );
  7599. %@AS@%     printf( "The ceil of 2.8 is %f\n", y );
  7600. %@AS@%     y = ceil( -2.8 );
  7601. %@AS@%     printf( "The ceil of -2.8 is %f\n", y );
  7602. %@AS@%  }%@AE@%%@NL@%
  7603. %@NL@%
  7604. %@NL@%
  7605. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7606. %@NL@%
  7607. %@AS@%  
  7608. %@AS@%  
  7609. %@AS@%  The floor of 2.8 is 2.000000
  7610. %@AS@%  The floor of -2.8 is -3.000000
  7611. %@AS@%  The ceil of 2.8 is 3.000000
  7612. %@AS@%  The ceil of -2.8 is -2.000000 %@AE@%%@NL@%
  7613. %@NL@%
  7614. %@NL@%
  7615. %@NL@%
  7616. %@NL@%
  7617. %@QR:_cexit@%%@QR:_c_exit@%%@NL@%
  7618. %@2@%%@CR:C6A00330241 @%%@AB@%_cexit, _c_exit%@AE@%%@EH@%%@NL@%
  7619. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7620. %@NL@%
  7621. %@NL@%
  7622. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  7623. %@NL@%
  7624. Perform clean-up operations and return without terminating the process.  %@NL@%
  7625. %@NL@%
  7626. %@CR:C6A00330242 @%%@CR:C6A00330243 @%%@AS@%  #include <process.h>       %@AE@%%@NL@%
  7627. %@NL@%
  7628. %@AS@%  void _cexit( void ); %@AE@%%@NL@%
  7629. %@NL@%
  7630. %@AS@%  void _c_exit( void );%@AE@%%@NL@%
  7631. %@NL@%
  7632. %@NL@%
  7633. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7634. %@NL@%
  7635. The %@AB@%_cexit%@AE@% function calls, in LIFO ("last in, first out") order, the
  7636. functions registered by %@AB@%atexit%@AE@% and %@AB@%onexit%@AE@%. Then the %@AB@%_cexit%@AE@% function flushes
  7637. all I/O buffers and closes all open files before returning.  %@NL@%
  7638. %@NL@%
  7639. The %@AB@%_c_exit%@AE@% function returns to the calling process without processing
  7640. %@AB@%atexit%@AE@% or %@AB@%onexit%@AE@% functions or flushing stream buffers.  %@NL@%
  7641. %@NL@%
  7642. The behavior of the %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, %@AB@%_cexit%@AE@%, and %@AB@%_c_exit%@AE@% functions is described
  7643. in the following list:  %@NL@%
  7644. %@NL@%
  7645. %@AB@%Function %@AE@%                         %@AB@%Action%@AE@%
  7646. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7647. %@AB@%exit%@AE@%                              Performs complete C library termination 
  7648.                                   procedures, terminates the process, and 
  7649.                                   exits with the supplied status code
  7650.  
  7651. %@AB@%_exit%@AE@%                             Performs "quick" C library termination 
  7652.                                   procedures, terminates the process, and 
  7653.                                   exits with the supplied status code
  7654.  
  7655. %@AB@%_cexit%@AE@%                            Performs complete C library termination 
  7656.                                   procedures and returns to caller, but 
  7657.                                   does not terminate the process
  7658.  
  7659. %@AB@%_c_exit%@AE@%                           Performs "quick" C library termination 
  7660.                                   procedures and returns to caller, but 
  7661.                                   does not terminate the process
  7662.  
  7663. %@NL@%
  7664. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7665. %@NL@%
  7666. None.  %@NL@%
  7667. %@NL@%
  7668. %@NL@%
  7669. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7670. %@NL@%
  7671.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  7672. %@NL@%
  7673. %@NL@%
  7674. %@NL@%
  7675. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7676. %@NL@%
  7677. %@AB@%abort%@AE@%, %@AB@%atexit%@AE@%, %@AB@%exec%@AE@% functions, %@AB@%exit%@AE@%, %@AB@%onexit%@AE@%, %@AB@%spawn%@AE@% functions, %@AB@%system%@AE@%  %@NL@%
  7678. %@NL@%
  7679. %@NL@%
  7680. %@NL@%
  7681. %@NL@%
  7682. %@QR:cgets@%%@NL@%
  7683. %@2@%%@CR:C6A00340244 @%%@AB@%cgets%@AE@%%@EH@%%@NL@%
  7684. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7685. %@NL@%
  7686. %@NL@%
  7687. %@3@%%@AB@%Description%@CR:C6A00340245 @% %@CR:C6A00340246 @% %@CR:C6A00340247 @%%@CR:C6A00340248 @%%@AE@%%@EH@%%@NL@%
  7688. %@NL@%
  7689. Gets a character string from the console.  %@NL@%
  7690. %@NL@%
  7691. %@AB@%#include <conio.h>%@AE@%                Required only for function declarations
  7692.  
  7693. %@AS@%  char *cgets( char *buffer );%@AE@%%@NL@%
  7694. %@NL@%
  7695. %@AI@%buffer%@AE@%                            Storage location for data
  7696.  
  7697. %@NL@%
  7698. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7699. %@NL@%
  7700. The %@AB@%cgets%@AE@% function reads a string of characters directly from the console
  7701. and stores the string and its length in the location pointed to by %@AI@%buffer%@AE@%.
  7702. The %@AI@%buffer%@AE@% argument must be a pointer to a character array. The first
  7703. element of the array, %@AI@%buffer%@AE@%[0], must contain the maximum length (in
  7704. characters) of the string to be read. The array must contain enough elements
  7705. to hold the string, a terminating null character (%@AB@%'\0'%@AE@%), and two additional
  7706. bytes.  %@NL@%
  7707. %@NL@%
  7708. The %@AB@%cgets%@AE@% function continues to read characters until a
  7709. carriage-return-line-feed (CR-LF) combination is read, or the specified
  7710. number of characters is read. The string is stored starting at %@AI@%str%@AE@%[2]. If a
  7711. CR-LF combination is read, it is replaced with a null character (%@AB@%'\0'%@AE@%)
  7712. before being stored. The %@AB@%cgets%@AE@% function then stores the actual length of the
  7713. string in the second array element, %@AI@%buffer%@AE@%[1].  %@NL@%
  7714. %@NL@%
  7715. Because all DOS editing keys are active when you call %@AB@%cgets%@AE@%, pressing F3
  7716. repeats the last entry.  %@NL@%
  7717. %@NL@%
  7718. %@NL@%
  7719. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7720. %@NL@%
  7721. The %@AB@%cgets%@AE@% function returns a pointer to the start of the string, at
  7722. %@AI@%buffer%@AE@%[2]. There is no error return.  %@NL@%
  7723. %@NL@%
  7724. %@NL@%
  7725. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7726. %@NL@%
  7727.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  7728. %@NL@%
  7729. %@NL@%
  7730. %@NL@%
  7731. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7732. %@NL@%
  7733. %@AB@%getch%@AE@%, %@AB@%getche%@AE@%  %@NL@%
  7734. %@NL@%
  7735. %@NL@%
  7736. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7737. %@NL@%
  7738. %@AS@%  /* CGETS.C: This program creates a buffer and initializes the first byte
  7739. %@AS@%   * to the size of the buffer - 2. Next, the program accepts an input
  7740. %@AS@%string
  7741. %@AS@%   * using cgets and displays the size and text of that string.
  7742. %@AS@%   */
  7743. %@AS@%  
  7744. %@AS@%  #include <conio.h>
  7745. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  7746. %@NL@%
  7747. %@AS@%  void main()
  7748. %@AS@%  {
  7749. %@AS@%     char buffer[82] = { 80 };  /* Maximum characters in first byte */
  7750. %@AS@%     char *result;
  7751. %@AS@%  
  7752. %@AS@%     printf( "Input line of text, followed by carriage return:\n");
  7753. %@AS@%     result = cgets( buffer );  /* Input a line of text */
  7754. %@AS@%     printf( "\nLine length = %d\nText = %s\n", buffer[1], result );
  7755. %@AS@%  }%@AE@%%@NL@%
  7756. %@NL@%
  7757. %@NL@%
  7758. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7759. %@NL@%
  7760. %@AS@%  
  7761. %@AS@%  
  7762. %@AS@%  Input line of text, followed by carriage return:
  7763. %@AS@%  This is some text
  7764. %@AS@%  Line length = 17
  7765. %@AS@%  Text = This is some text %@AE@%%@NL@%
  7766. %@NL@%
  7767. %@NL@%
  7768. %@NL@%
  7769. %@NL@%
  7770. %@QR:_chain_intr@%%@NL@%
  7771. %@2@%%@CR:C6A00350249 @%%@AB@%_chain_intr%@AE@%%@EH@%%@NL@%
  7772. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7773. %@NL@%
  7774. %@NL@%
  7775. %@3@%%@AB@%Description%@CR:C6A00350250 @% %@CR:C6A00350251 @%%@AE@%%@EH@%%@NL@%
  7776. %@NL@%
  7777. Chains an interrupt from one handler to another.  %@NL@%
  7778. %@NL@%
  7779. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  7780. %@NL@%
  7781. %@AS@%  void _chain_intr( void( _interrupt _far *target )());%@AE@%%@NL@%
  7782. %@NL@%
  7783. %@AI@%target%@AE@%                            Target interrupt routine
  7784.  
  7785. %@NL@%
  7786. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7787. %@NL@%
  7788. The %@AB@%_chain_intr%@AE@% routine passes control from one interrupt handler to
  7789. another. The stack and the registers of the first routine are passed to the
  7790. second, allowing the second routine to return as if it had been called
  7791. directly.  %@NL@%
  7792. %@NL@%
  7793. The %@AB@%_chain_intr%@AE@% routine is generally used when a user-defined interrupt
  7794. handler begins processing, then chains to the original interrupt handler to
  7795. finish processing.  %@NL@%
  7796. %@NL@%
  7797. Chaining is one of two techniques, listed below, that can be used to
  7798. transfer control from a new interrupt routine to an old one:  %@NL@%
  7799. %@NL@%
  7800. %@NL@%
  7801.   1.  Call %@AB@%_chain_intr%@AE@% with the interrupt routine as an argument. Do this if
  7802.       your routine is finished and you want the second interrupt routine to
  7803.       terminate the interrupt call.
  7804. %@NL@%
  7805. %@AS@%      void _interrupt new_int( unsigned _es, unsigned _ds,
  7806. %@AS@%         unsigned _di, unsigned _si,... )
  7807. %@AS@%      {
  7808. %@AS@%          ++_di;                  /* Initial processing here  */
  7809. %@AS@%          _chain_intr( old_int ); /* New DI passed to old_int */
  7810. %@AS@%          --_di;                  /* This is never executed   */
  7811. %@AS@%      }%@AE@%%@NL@%
  7812. %@NL@%
  7813. %@NL@%
  7814.   2.  Call the interrupt routine (after casting it to an interrupt function
  7815.       if necessary). Do this if you need to do further processing after the
  7816.       second interrupt routine finishes.
  7817. %@NL@%
  7818. %@AS@%      void _interrupt new_int( unsigned _es, unsigned _ds,
  7819. %@AS@%         unsigned _di, unsigned _si,... )
  7820. %@AS@%      {
  7821. %@AS@%          ++_di;                   /* Initial processing here  */
  7822. %@AS@%          (*old_int)();            /* New DI passed to old_int */
  7823. %@AS@%          _asm mov _di, di         /* Put real DI from old_int */
  7824. %@AS@%                                   /*   into _di for return    */
  7825. %@AS@%      }%@AE@%%@NL@%
  7826. %@NL@%
  7827. %@NL@%
  7828. %@NL@%
  7829. Note that the real registers set by the old interrupt function are not
  7830. automatically set to the pseudoregisters of the new routine.  %@NL@%
  7831. %@NL@%
  7832. Use the %@AB@%_chain_intr%@AE@% function when you do not want to replace the default
  7833. interrupt handler, but you do need to see its input. An example is a TSR
  7834. (terminate-and-stay-resident) program that checks all keyboard input for a
  7835. particular "hot key" sequence.  %@NL@%
  7836. %@NL@%
  7837. The %@AB@%_chain_intr%@AE@% function should be used only with C functions that have been
  7838. declared with type %@AB@%_interrupt%@AE@%. The %@AB@%_interrupt%@AE@% declaration ensures that the
  7839. procedure's entry/exit sequence is appropriate for an interrupt handler.  %@NL@%
  7840. %@NL@%
  7841. %@NL@%
  7842. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7843. %@NL@%
  7844. The %@AB@%_chain_intr%@AE@% function does not return to the caller.  %@NL@%
  7845. %@NL@%
  7846. %@NL@%
  7847. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7848. %@NL@%
  7849.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  7850. %@NL@%
  7851. %@NL@%
  7852. %@NL@%
  7853. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7854. %@NL@%
  7855. %@AB@%_dos_getvect%@AE@%,  %@AB@%_dos_keep%@AE@%,  %@AB@%_dos_setvect%@AE@%  %@NL@%
  7856. %@NL@%
  7857. %@NL@%
  7858. %@NL@%
  7859. %@NL@%
  7860. %@QR:chdir@%%@NL@%
  7861. %@2@%%@CR:C6A00360252 @%%@AB@%chdir%@AE@%%@EH@%%@NL@%
  7862. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7863. %@NL@%
  7864. %@NL@%
  7865. %@3@%%@AB@%Description%@CR:C6A00360253 @%%@AE@%%@EH@%%@NL@%
  7866. %@NL@%
  7867. Changes the current working directory.  %@NL@%
  7868. %@NL@%
  7869. %@AB@%#include <direct.h%@AE@%>               Required only for function declarations
  7870.  
  7871. %@AB@%#include <errno.h>%@AE@%                Required for %@AB@%errno%@AE@% constants
  7872.  
  7873. %@AS@%  int chdir( char *dirname );%@AE@%%@NL@%
  7874. %@NL@%
  7875. %@AI@%dirname%@AE@%                           Path name of new working directory
  7876.  
  7877. %@NL@%
  7878. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7879. %@NL@%
  7880. The %@AB@%chdir%@AE@% function changes the current working directory to the directory
  7881. specified by %@AI@% dirname%@AE@%. The %@AI@%dirname%@AE@% argument must refer to an existing
  7882. directory.  %@NL@%
  7883. %@NL@%
  7884. This function can change the current working directory on any drive; it
  7885. cannot be used to change the default drive itself. For example, if A: is the
  7886. default drive and \BIN is the current working directory, the following call
  7887. changes the current working directory for drive C:  %@NL@%
  7888. %@NL@%
  7889. %@AS@%  chdir("c:\\temp");%@AE@%%@NL@%
  7890. %@NL@%
  7891. Notice that you must place two backslashes ( \\ ) in a C string in order to
  7892. represent a single backslash ( \ ); the backslash is the escape character
  7893. for C strings and therefore requires special handling.  %@NL@%
  7894. %@NL@%
  7895. This function call has no apparent immediate effect. However, when the
  7896. %@AB@%_chdrive%@AE@% function is called to change the default drive to C:, the current
  7897. working directory becomes C:\TEMP.  %@NL@%
  7898. %@NL@%
  7899. In OS/2 protected mode, the current working directory is local to a process
  7900. rather than system-wide. When a process terminates, the current working
  7901. directory is restored to its original value. Under DOS, the new directory
  7902. set by the program becomes the new current working directory.  %@NL@%
  7903. %@NL@%
  7904. %@NL@%
  7905. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7906. %@NL@%
  7907. The %@AB@%chdir%@AE@% function returns a value of 0 if the working directory is
  7908. successfully changed. A return value of -1 indicates an error, in which case
  7909. %@AB@%errno%@AE@% is set to %@AB@%ENOENT%@AE@%, indicating that the specified path name could not be
  7910. found.  %@NL@%
  7911. %@NL@%
  7912. %@NL@%
  7913. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7914. %@NL@%
  7915.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  7916. %@NL@%
  7917. %@NL@%
  7918. %@NL@%
  7919. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  7920. %@NL@%
  7921. %@AB@%_dos_setdrive%@AE@%, %@AB@%mkdir%@AE@%, %@AB@%rmdir%@AE@%, %@AB@%system%@AE@%  %@NL@%
  7922. %@NL@%
  7923. %@NL@%
  7924. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  7925. %@NL@%
  7926. %@AS@%  /* CHGDIR.C: This program uses the chdir function to verify that a
  7927. %@AS@%   * given directory exists. Under real mode that directory also becomes
  7928. %@AS@%   * the current directory. Under protected mode, it is only the default
  7929. %@AS@%   * directory for the current process.
  7930. %@AS@%   */
  7931. %@AS@%  
  7932. %@AS@%  #include <direct.h>
  7933. %@AS@%  #include <stdio.h>
  7934. %@AS@%  #include <stdlib.h>
  7935. %@AS@%  
  7936. %@AS@%  void main( int argc, char *argv[] )
  7937. %@AS@%  {
  7938. %@AS@%     if( chdir( argv[1] )   )
  7939. %@AS@%        printf( "Unable to locate the directory: %s\n", argv[1] );
  7940. %@AS@%     else
  7941. %@AS@%        system( "dir *.c" );
  7942. %@AS@%  }%@AE@%%@NL@%
  7943. %@NL@%
  7944. %@NL@%
  7945. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  7946. %@NL@%
  7947. %@AS@%  
  7948. %@AS@%  
  7949. %@AS@%  [C:\LIBREF] chgdir \tmp
  7950. %@AS@%  
  7951. %@AS@%   The volume label in drive C is OS2.
  7952. %@AS@%   Directory of C:\TMP
  7953. %@AS@%  
  7954. %@AS@%  DUP      C        232   4-18-89  11:18a
  7955. %@AS@%  TEST     C        713   4-07-88   2:49p
  7956. %@AS@%       2 File(s)   14155776 bytes free %@AE@%%@NL@%
  7957. %@NL@%
  7958. %@NL@%
  7959. %@NL@%
  7960. %@NL@%
  7961. %@QR:_chdrive@%%@NL@%
  7962. %@2@%%@CR:C6A00370254 @%%@AB@%_chdrive%@AE@%%@EH@%%@NL@%
  7963. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  7964. %@NL@%
  7965. %@NL@%
  7966. %@3@%%@AB@%Description%@CR:C6A00370255 @%%@CR:C6A00370256 @%%@AE@%%@EH@%%@NL@%
  7967. %@NL@%
  7968. Changes the current working drive.  %@NL@%
  7969. %@NL@%
  7970. %@AB@%#include <direct.h>%@AE@%               Required only for function declarations
  7971.  
  7972. %@AS@%  int _chdrive( int drive );%@AE@%%@NL@%
  7973. %@NL@%
  7974. %@AI@%drive%@AE@%                             Number of new working drive
  7975.  
  7976. %@NL@%
  7977. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  7978. %@NL@%
  7979. The %@AB@%_chdrive%@AE@% function changes the current working drive to the drive
  7980. specified by %@AI@%drive%@AE@%. The %@AI@%drive%@AE@% argument uses an integer to specify the new
  7981. working drive (1=A, 2=B, etc.).  %@NL@%
  7982. %@NL@%
  7983. This function changes only the working drive; the %@AB@%chdir%@AE@% function changes the
  7984. working directory.  %@NL@%
  7985. %@NL@%
  7986. In OS/2 protected mode, the working drive is local to a process rather than
  7987. system-wide. When a process terminates, the working drive is restored to its
  7988. original value. Under DOS, the new drive set by the program becomes the new
  7989. working drive.  %@NL@%
  7990. %@NL@%
  7991. %@NL@%
  7992. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  7993. %@NL@%
  7994. The %@AB@%_chdrive%@AE@% function returns a value of 0 if the working drive is
  7995. successfully changed. A return value of -1 indicates an error.  %@NL@%
  7996. %@NL@%
  7997. %@NL@%
  7998. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  7999. %@NL@%
  8000.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  8001. %@NL@%
  8002. %@NL@%
  8003. %@NL@%
  8004. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8005. %@NL@%
  8006. %@AB@%chdir%@AE@%,  %@AB@%_dos_setdrive%@AE@%,  %@AB@%_fullpath%@AE@%, %@AB@% _getcwd%@AE@%, %@AB@% _getdrive%@AE@%, %@AB@%mkdir%@AE@%, %@AB@%rmdir%@AE@%,
  8007. %@AB@%system%@AE@%  %@NL@%
  8008. %@NL@%
  8009. %@NL@%
  8010. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8011. %@NL@%
  8012. %@AS@%  /* GETDRIVE.C illustrates drive functions including:
  8013. %@AS@%   *      _getdrive       _chdrive        _getdcwd
  8014. %@AS@%   */
  8015. %@AS@%  
  8016. %@AS@%  #include <stdio.h>
  8017. %@AS@%  #include <conio.h>
  8018. %@AS@%  #include <direct.h>
  8019. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  8020. %@NL@%
  8021. %@AS@%  void main()
  8022. %@AS@%  {
  8023. %@AS@%     int ch, drive, curdrive;
  8024. %@AS@%     static char path[_MAX_PATH];
  8025. %@AS@%  
  8026. %@AS@%     /* Save current drive. */
  8027. %@AS@%     curdrive = _getdrive();
  8028. %@AS@%  
  8029. %@AS@%     printf( "Available drives are: \n" );
  8030. %@AS@%  
  8031. %@AS@%     /* If we can switch to the drive, it exists. */
  8032. %@AS@%     for( drive = 1; drive <= 26; drive++ )
  8033. %@AS@%        if( !_chdrive( drive ) )
  8034. %@AS@%           printf( "%c: ", drive + 'A' - 1 );
  8035. %@AS@%  
  8036. %@AS@%     while( 1 )
  8037. %@AS@%     {
  8038. %@AS@%        printf( "\nType drive letter to check or ESC to quit: " );
  8039. %@AS@%        ch = getch();
  8040. %@AS@%        if( ch == 27 )
  8041. %@AS@%           break;
  8042. %@AS@%        if( isalpha( ch ) )
  8043. %@AS@%           putch( ch );
  8044. %@AS@%        if( _getdcwd( toupper( ch ) - 'A' + 1, path, _MAX_PATH ) != NULL )
  8045. %@AS@%           printf( "\nCurrent directory on that drive is %s\n", path );
  8046. %@AS@%     }
  8047. %@AS@%  
  8048. %@AS@%     /* Restore original drive. This is only necessary for DOS. Under OS/2
  8049. %@AS@%      * the current drive of the calling process is always restored.
  8050. %@AS@%      */
  8051. %@AS@%     _chdrive( curdrive );
  8052. %@AS@%     printf( "\n" );
  8053. %@AS@%  }%@AE@%%@NL@%
  8054. %@NL@%
  8055. %@NL@%
  8056. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8057. %@NL@%
  8058. %@AS@%  
  8059. %@AS@%  
  8060. %@AS@%  Available drives are:
  8061. %@AS@%  A: B: C:
  8062. %@AS@%  Type drive letter to check or ESC to quit: q
  8063. %@AS@%  Type drive letter to check or ESC to quit: a
  8064. %@AS@%  Current directory on that drive is A:\
  8065. %@AS@%  
  8066. %@AS@%  Type drive letter to check or ESC to quit: c
  8067. %@AS@%  Current directory on that drive is C:\LIBREF
  8068. %@AS@%  
  8069. %@AS@%  Type drive letter to check or ESC to quit:%@AE@%%@NL@%
  8070. %@NL@%
  8071. %@NL@%
  8072. %@NL@%
  8073. %@NL@%
  8074. %@QR:chmod@%%@NL@%
  8075. %@2@%%@CR:C6A00380257 @%%@AB@%chmod%@AE@%%@EH@%%@NL@%
  8076. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8077. %@NL@%
  8078. %@NL@%
  8079. %@3@%%@AB@%Description%@CR:C6A00380258 @%%@CR:C6A00380259 @% %@CR:C6A00380260 @%%@AE@%%@EH@%%@NL@%
  8080. %@NL@%
  8081. Changes the file-permission settings.  %@NL@%
  8082. %@NL@%
  8083. %@AB@%#include <sys\types.h>%@AE@%            
  8084.  
  8085. %@AB@%#include <sys\stat.h>%@AE@%             
  8086.  
  8087. %@AB@%#include <errno.h>%@AE@%                
  8088.  
  8089. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  8090.  
  8091. %@AS@%  int chmod( char *filename, int pmode );%@AE@%%@NL@%
  8092. %@NL@%
  8093. %@AI@%filename%@AE@%                          Path name of existing file
  8094.  
  8095. %@AI@%pmode%@AE@%                             Permission setting for file
  8096.  
  8097. %@NL@%
  8098. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8099. %@NL@%
  8100. The %@AB@%chmod%@AE@% function changes the permission setting of the file specified by
  8101. %@AI@%filename.%@AE@% The permission setting controls read and write access to the file.
  8102. The constant expression %@AI@%pmode%@AE@% contains one or both of the manifest constants
  8103. %@AB@%S_IWRITE%@AE@% and %@AB@%S_IREAD%@AE@%, defined in SYS\STAT.H. Any other values for %@AI@%pmode%@AE@% are
  8104. ignored. When both constants are given, they are joined with the bitwise-OR
  8105. operator ( | ). The meaning of the %@AI@%pmode%@AE@% argument is as follows:  %@NL@%
  8106. %@NL@%
  8107. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  8108. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8109. %@AB@%S_IWRITE%@AE@%                          Writing permitted
  8110.  
  8111. %@AB@%S_IREAD%@AE@%                           Reading permitted
  8112.  
  8113. %@AB@%S_IREAD%@AE@% |  %@AB@%S_IWRITE%@AE@%               Reading and writing permitted
  8114.  
  8115. If write permission is not given, the file is read-only. Under DOS and OS/2,
  8116. all files are readable; it is not possible to give write-only permission.
  8117. Thus the modes %@AB@%S_IWRITE%@AE@% and %@AB@%S_IREAD%@AE@%  |  %@AB@%S_IWRITE%@AE@% are equivalent.  %@NL@%
  8118. %@NL@%
  8119. %@NL@%
  8120. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8121. %@NL@%
  8122. The %@AB@%chmod%@AE@% function returns the value 0 if the permission setting is
  8123. successfully changed. A return value of -1 indicates an error; in this case,
  8124. %@AB@%errno%@AE@% is set to %@AB@%ENOENT%@AE@%, indicating that the specified file could not be
  8125. found.  %@NL@%
  8126. %@NL@%
  8127. %@NL@%
  8128. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8129. %@NL@%
  8130.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  8131. %@NL@%
  8132. %@NL@%
  8133. %@NL@%
  8134. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8135. %@NL@%
  8136. %@AB@%access%@AE@%, %@AB@%creat%@AE@%, %@AB@%fstat%@AE@%, %@AB@%open%@AE@%, %@AB@%stat%@AE@%  %@NL@%
  8137. %@NL@%
  8138. %@NL@%
  8139. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8140. %@NL@%
  8141. %@AS@%  /* CHMOD.C: This program uses chmod to change the mode of a file to
  8142. %@AS@%   * read-only. It then attempts to modify the file.
  8143. %@AS@%   */
  8144. %@AS@%  
  8145. %@AS@%  #include <sys\types.h>
  8146. %@AS@%  #include <sys\stat.h>
  8147. %@AS@%  #include <io.h>
  8148. %@AS@%  #include <stdio.h>
  8149. %@AS@%  #include <stdlib.h>
  8150. %@AS@%  
  8151. %@AS@%  void main()
  8152. %@AS@%  {
  8153. %@AS@%     /* Make file read-only: */
  8154. %@AS@%     if( chmod( "CHMOD.C", S_IREAD ) == -1 )
  8155. %@AS@%        perror( "File not found\n" );
  8156. %@AS@%     else
  8157. %@AS@%        printf( "Mode changed to read-only\n" );
  8158. %@AS@%     system( "echo /* End of file */ >> CHMOD.C" );
  8159. %@AS@%  
  8160. %@AS@%     /* Change back to read/write: */
  8161. %@AS@%     if( chmod( "CHMOD.C", S_IWRITE ) == -1 )
  8162. %@AS@%        perror( "File not found\n" );
  8163. %@AS@%     else
  8164. %@AS@%        printf( "Mode changed to read/write\n" );
  8165. %@AS@%  }%@AE@%%@NL@%
  8166. %@NL@%
  8167. %@NL@%
  8168. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8169. %@NL@%
  8170. %@AS@%  
  8171. %@AS@%  
  8172. %@AS@%  Mode changed to read-only
  8173. %@AS@%  Access denied
  8174. %@AS@%  Mode changed to read/write %@AE@%%@NL@%
  8175. %@NL@%
  8176. %@NL@%
  8177. %@NL@%
  8178. %@NL@%
  8179. %@QR:chsize@%%@NL@%
  8180. %@2@%%@CR:C6A00390261 @%%@AB@%chsize%@AE@%%@EH@%%@NL@%
  8181. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8182. %@NL@%
  8183. %@NL@%
  8184. %@3@%%@AB@%Description%@CR:C6A00390262 @%%@CR:C6A00390263 @%%@CR:C6A00390264 @%%@AE@%%@EH@%%@NL@%
  8185. %@NL@%
  8186. Changes the file size.  %@NL@%
  8187. %@NL@%
  8188. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  8189.  
  8190. %@AB@%#include <errno.h>%@AE@%                
  8191.  
  8192. %@AS@%  int chsize( int handle, long size );%@AE@%%@NL@%
  8193. %@NL@%
  8194. %@AI@%handle%@AE@%                            Handle referring to open file
  8195.  
  8196. %@AI@%size%@AE@%                              New length of file in bytes
  8197.  
  8198. %@NL@%
  8199. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8200. %@NL@%
  8201. The %@AB@%chsize%@AE@% function extends or truncates the file associated with %@AI@%handle%@AE@% to
  8202. the length specified by %@AI@%size%@AE@%. The file must be open in a mode that permits
  8203. writing. Null characters (%@AB@%'\0'%@AE@%) are appended if the file is extended. If the
  8204. file is truncated, all data from the end of the shortened file to the
  8205. original length of the file is lost.  %@NL@%
  8206. %@NL@%
  8207. In DOS, the directory update is done when a file is closed. Consequently,
  8208. while a program is running, requests to determine the amount of free disk
  8209. space may receive inaccurate results.  %@NL@%
  8210. %@NL@%
  8211. %@NL@%
  8212. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8213. %@NL@%
  8214. The %@AB@%chsize%@AE@% function returns the value 0 if the file size is successfully
  8215. changed. A return value of -1 indicates an error, and %@AB@%errno%@AE@% is set to one of
  8216. the following values:  %@NL@%
  8217. %@NL@%
  8218. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  8219. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8220. %@AB@%EACCES%@AE@%                            Specified file is locked against access 
  8221.                                   (OS/2 and DOS versions 3.0 and later 
  8222.                                   only).
  8223.  
  8224. %@AB@%EBADF%@AE@%                             Specified file is read-only or an 
  8225.                                   invalid file handle.
  8226.  
  8227. %@AB@%ENOSPC%@AE@%                            No space is left on device.
  8228.  
  8229. %@NL@%
  8230. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8231. %@NL@%
  8232.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  8233. %@NL@%
  8234. %@NL@%
  8235. %@NL@%
  8236. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8237. %@NL@%
  8238. %@AB@%close%@AE@%, %@AB@%creat%@AE@%, %@AB@%open%@AE@%  %@NL@%
  8239. %@NL@%
  8240. %@NL@%
  8241. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8242. %@NL@%
  8243. %@AS@%  /* CHSIZE.C: This program uses filelength to report the size of a
  8244. %@AS@%   * file before and after modifying it with chsize.
  8245. %@AS@%   */%@AE@%%@NL@%
  8246. %@NL@%
  8247. %@AS@%  #include <io.h>
  8248. %@AS@%  #include <fcntl.h>
  8249. %@AS@%  #include <sys\types.h>
  8250. %@AS@%  #include <sys\stat.h>
  8251. %@AS@%  #include <stdio.h>
  8252. %@AS@%  
  8253. %@AS@%  void main()
  8254. %@AS@%  {
  8255. %@AS@%     int fh, result;
  8256. %@AS@%     unsigned int nbytes = BUFSIZ;
  8257. %@AS@%  
  8258. %@AS@%     /* Open a file */
  8259. %@AS@%     if( (fh = open( "data", O_RDWR | O_CREAT, S_IREAD | S_IWRITE )) != -1 )
  8260. %@AS@%     {
  8261. %@AS@%        printf( "File length before: %ld\n", filelength( fh ) );
  8262. %@AS@%        if( chsize( fh, 329678 ) == 0 )
  8263. %@AS@%           printf( "Size successfully changed\n" );
  8264. %@AS@%        else
  8265. %@AS@%           printf( "Problem in changing the size\n" );
  8266. %@AS@%        printf( "File length after:  %ld\n", filelength( fh ) );
  8267. %@AS@%        close( fh );
  8268. %@AS@%     }
  8269. %@AS@%  }%@AE@%%@NL@%
  8270. %@NL@%
  8271. %@NL@%
  8272. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8273. %@NL@%
  8274. %@AS@%  
  8275. %@AS@%  
  8276. %@AS@%  File length before: 0
  8277. %@AS@%  Size successfully changed
  8278. %@AS@%  File length after:  329678%@AE@%%@NL@%
  8279. %@NL@%
  8280. %@NL@%
  8281. %@NL@%
  8282. %@NL@%
  8283. %@QR:_clear87@%%@NL@%
  8284. %@2@%%@CR:C6A00400265 @%%@AB@%_clear87%@AE@%%@EH@%%@NL@%
  8285. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8286. %@NL@%
  8287. %@NL@%
  8288. %@3@%%@AB@%Description%@CR:C6A00400266 @%%@CR:C6A00400267 @% %@CR:C6A00400268 @%%@AE@%%@EH@%%@NL@%
  8289. %@NL@%
  8290. Gets and clears the floating-point status word.  %@NL@%
  8291. %@NL@%
  8292. %@AS@%  #include <float.h>%@AE@%%@NL@%
  8293. %@NL@%
  8294. %@AS@%  unsigned int _clear87( void );%@AE@%%@NL@%
  8295. %@NL@%
  8296. %@NL@%
  8297. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8298. %@NL@%
  8299. The %@AB@%_clear87%@AE@% function gets and clears the floating-point status word. The
  8300. floating-point status word is a combination of the 8087/80287 status word
  8301. and other conditions detected by the 8087/80287 exception handler, such as
  8302. floating-point stack overflow and underflow.  %@NL@%
  8303. %@NL@%
  8304. %@NL@%
  8305. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8306. %@NL@%
  8307. The bits in the value returned indicate the floating-point status. See the
  8308. FLOAT.H include file for a complete definition of the bits returned by
  8309. %@AB@%_clear87%@AE@%.  %@NL@%
  8310. %@NL@%
  8311. Many of the math library functions modify the 8087/80287 status word, with
  8312. unpredictable results. Return values from %@AB@%_clear87%@AE@% and %@AB@%_status87%@AE@% become more
  8313. reliable as fewer floating-point operations are performed between known
  8314. states of the floating-point status word.  %@NL@%
  8315. %@NL@%
  8316. %@NL@%
  8317. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8318. %@NL@%
  8319.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  8320. %@NL@%
  8321. %@NL@%
  8322. %@NL@%
  8323. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8324. %@NL@%
  8325. %@AB@%_control87%@AE@%, %@AB@%_status87%@AE@%  %@NL@%
  8326. %@NL@%
  8327. %@NL@%
  8328. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8329. %@NL@%
  8330. %@AS@%  /* CLEAR87.C: This program creates various floating-point problems,
  8331. %@AS@%   * then uses _clear87 to report on these problems.
  8332. %@AS@%   */
  8333. %@AS@%  
  8334. %@AS@%  #include <stdio.h>
  8335. %@AS@%  #include <float.h>
  8336. %@AS@%  
  8337. %@AS@%  void main()
  8338. %@AS@%  {
  8339. %@AS@%     double a = 1e-40, b;
  8340. %@AS@%     float x, y;
  8341. %@AS@%  
  8342. %@AS@%     printf( "Status: %.4x - clear\n", _clear87()  );
  8343. %@AS@%  
  8344. %@AS@%     /* Store into y is inexact and underflows: */
  8345. %@AS@%     y = a;
  8346. %@AS@%     printf( "Status: %.4x - inexact, underflow\n", _clear87() );%@AE@%%@NL@%
  8347. %@NL@%
  8348. %@AS@%  /* y is denormal: */
  8349. %@AS@%     b = y;
  8350. %@AS@%     printf( "Status: %.4x - denormal\n", _clear87() );
  8351. %@AS@%  }%@AE@%%@NL@%
  8352. %@NL@%
  8353. %@NL@%
  8354. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8355. %@NL@%
  8356. %@AS@%  
  8357. %@AS@%  
  8358. %@AS@%  Status: 0000 - clear
  8359. %@AS@%  Status: 0030 - inexact, underflow
  8360. %@AS@%  Status: 0002 - denormal %@AE@%%@NL@%
  8361. %@NL@%
  8362. %@NL@%
  8363. %@NL@%
  8364. %@NL@%
  8365. %@QR:clearerr@%%@NL@%
  8366. %@2@%%@CR:C6A00410269 @%%@AB@%clearerr%@AE@%%@EH@%%@NL@%
  8367. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8368. %@NL@%
  8369. %@NL@%
  8370. %@3@%%@AB@%Description%@CR:C6A00410270 @%%@CR:C6A00410271 @% %@CR:C6A00410272 @%%@CR:C6A00410273 @% %@CR:C6A00410274 @%%@CR:C6A00410275 @% %@CR:C6A00410276 @%%@AE@%%@EH@%%@NL@%
  8371. %@NL@%
  8372. Resets the error indicator for a stream.  %@NL@%
  8373. %@NL@%
  8374. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  8375. %@NL@%
  8376. %@AS@%  void clearerr( FILE *stream );%@AE@%%@NL@%
  8377. %@NL@%
  8378. %@AI@%stream%@AE@%                            Pointer to%@AB@% FILE structure%@AE@%
  8379.  
  8380. %@NL@%
  8381. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8382. %@NL@%
  8383. The %@AB@%clearerr%@AE@% function resets the error indicator and end-of-file indicator
  8384. for %@AI@%stream%@AE@%. Error indicators are not automatically cleared; once the error
  8385. indicator for a specified stream is set, operations on that stream continue
  8386. to return an error value until %@AB@%clearerr%@AE@%,%@AB@% fseek%@AE@%,%@AB@% fsetpos%@AE@%,%@AB@% %@AE@%or %@AB@%rewind%@AE@% is
  8387. called.  %@NL@%
  8388. %@NL@%
  8389. %@NL@%
  8390. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8391. %@NL@%
  8392. None.  %@NL@%
  8393. %@NL@%
  8394. %@NL@%
  8395. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8396. %@NL@%
  8397. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  8398. %@NL@%
  8399. %@NL@%
  8400. %@NL@%
  8401. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8402. %@NL@%
  8403. %@AB@%eof%@AE@%, %@AB@%feof%@AE@%, %@AB@%ferror%@AE@%, %@AB@%perror%@AE@%  %@NL@%
  8404. %@NL@%
  8405. %@NL@%
  8406. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8407. %@NL@%
  8408. %@AS@%  /* CLEARERR.C: This program creates an error on the standard input
  8409. %@AS@%   * stream, then clears it so that future reads won't fail.
  8410. %@AS@%   */
  8411. %@AS@%  
  8412. %@AS@%  #include <stdio.h>
  8413. %@AS@%  
  8414. %@AS@%  void main()
  8415. %@AS@%  {
  8416. %@AS@%     int c;
  8417. %@AS@%  
  8418. %@AS@%     /* Create an error by writing to standard input. */
  8419. %@AS@%     putc( 'c', stdin );
  8420. %@AS@%     if( ferror( stdin ) )
  8421. %@AS@%     {
  8422. %@AS@%        perror( "Write error" );
  8423. %@AS@%        clearerr( stdin );
  8424. %@AS@%     }%@AE@%%@NL@%
  8425. %@NL@%
  8426. %@AS@%  /* See if read causes an error. */
  8427. %@AS@%     printf( "Will input cause an error? " );
  8428. %@AS@%     c = getc( stdin );
  8429. %@AS@%     if( ferror( stdin ) )
  8430. %@AS@%     {
  8431. %@AS@%        perror( "Read error" );
  8432. %@AS@%        clearerr( stdin );
  8433. %@AS@%     }
  8434. %@AS@%  }%@AE@%%@NL@%
  8435. %@NL@%
  8436. %@NL@%
  8437. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8438. %@NL@%
  8439. %@AS@%  
  8440. %@AS@%  
  8441. %@AS@%  Write error: Error 0
  8442. %@AS@%  Will input cause an error? n%@AE@%%@NL@%
  8443. %@NL@%
  8444. %@NL@%
  8445. %@NL@%
  8446. %@NL@%
  8447. %@QR:_clearscreen@%%@NL@%
  8448. %@2@%%@CR:C6A00420277 @%%@AB@%_clearscreen%@AE@%%@EH@%%@NL@%
  8449. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8450. %@NL@%
  8451. %@NL@%
  8452. %@3@%%@AB@%Description%@CR:C6A00420278 @%%@AE@%%@EH@%%@NL@%
  8453. %@NL@%
  8454. Clears the specified area of the screen.  %@NL@%
  8455. %@NL@%
  8456. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  8457. %@NL@%
  8458. %@AS@%  void _far _clearscreen( short area );%@AE@%%@NL@%
  8459. %@NL@%
  8460. %@AI@%area%@AE@%                              Target area
  8461.  
  8462. %@NL@%
  8463. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8464. %@NL@%
  8465. The %@AB@%_clearscreen%@AE@% function erases the target area, filling it with the
  8466. current background color. The %@AI@%area%@AE@% parameter can be one of the following
  8467. manifest constants (defined in GRAPH.H):  %@NL@%
  8468. %@NL@%
  8469. %@AB@%Constant%@AE@%                          %@AB@%Action%@AE@%
  8470. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8471. %@AB@%_GCLEARSCREEN%@AE@%                     Clears and fills the entire screen
  8472.  
  8473. %@AB@%_GVIEWPORT%@AE@%                        Clears and fills only within the current
  8474.                                   view port
  8475.  
  8476. %@AB@%_GWINDOW%@AE@%                          Clears and fills only within the current
  8477.                                   text window
  8478.  
  8479. %@NL@%
  8480. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8481. %@NL@%
  8482. None.  %@NL@%
  8483. %@NL@%
  8484. %@NL@%
  8485. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8486. %@NL@%
  8487.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  8488. %@NL@%
  8489. %@NL@%
  8490. %@NL@%
  8491. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8492. %@NL@%
  8493. %@AB@%_getbkcolor%@AE@%, %@AB@% _setbkcolor%@AE@%  %@NL@%
  8494. %@NL@%
  8495. %@NL@%
  8496. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8497. %@NL@%
  8498. %@AS@%  /* CLRSCRN.C */
  8499. %@AS@%  #include <conio.h>
  8500. %@AS@%  #include <graph.h>
  8501. %@AS@%  #include <stdlib.h>
  8502. %@AS@%  
  8503. %@AS@%  void main()
  8504. %@AS@%  {
  8505. %@AS@%     short xhalf, yhalf, xquar, yquar;
  8506. %@AS@%     struct videoconfig vc;%@AE@%%@NL@%
  8507. %@NL@%
  8508. %@AS@%  /* Find a valid graphics mode. */
  8509. %@AS@%     if( !_setvideomode( _MAXRESMODE ) )
  8510. %@AS@%        exit( 1 );
  8511. %@AS@%  
  8512. %@AS@%     _getvideoconfig( &vc );
  8513. %@AS@%  
  8514. %@AS@%     xhalf = vc.numxpixels / 2;
  8515. %@AS@%     yhalf = vc.numypixels / 2;
  8516. %@AS@%     xquar = xhalf / 2;
  8517. %@AS@%     yquar = yhalf / 2;
  8518. %@AS@%  
  8519. %@AS@%     _setviewport( 0, 0, xhalf - 1, yhalf - 1 );
  8520. %@AS@%     _rectangle( _GBORDER, 0,  0, xhalf - 1, yhalf - 1 );
  8521. %@AS@%     _ellipse( _GFILLINTERIOR, xquar / 4, yquar / 4,
  8522. %@AS@%                         xhalf - (xquar / 4), yhalf - (yquar / 4) );
  8523. %@AS@%     getch();
  8524. %@AS@%     _clearscreen( _GVIEWPORT );
  8525. %@AS@%  
  8526. %@AS@%     getch();
  8527. %@AS@%     _setvideomode( _DEFAULTMODE );
  8528. %@AS@%  }%@AE@%%@NL@%
  8529. %@NL@%
  8530. %@NL@%
  8531. %@NL@%
  8532. %@NL@%
  8533. %@QR:clock@%%@NL@%
  8534. %@2@%%@CR:C6A00430279 @%%@AB@%clock%@AE@%%@EH@%%@NL@%
  8535. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8536. %@NL@%
  8537. %@NL@%
  8538. %@3@%%@AB@%Description%@CR:C6A00430280 @%%@CR:C6A00430281 @%%@AE@%%@EH@%%@NL@%
  8539. %@NL@%
  8540. Calculates the time used by the calling process.  %@NL@%
  8541. %@NL@%
  8542. %@AS@%  #include <time.h>%@AE@%%@NL@%
  8543. %@NL@%
  8544. %@AS@%  clock_t clock( void );%@AE@%%@NL@%
  8545. %@NL@%
  8546. %@NL@%
  8547. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8548. %@NL@%
  8549. The %@AB@%clock%@AE@% function tells how much processor time has been used by the
  8550. calling process. The time in seconds is approximated by dividing the %@AB@%clock%@AE@%
  8551. return value by the value of the %@AB@%CLOCKS_PER_SEC%@AE@% constant.  %@NL@%
  8552. %@NL@%
  8553. In other words, the %@AB@%clock%@AE@% function returns the number of processor timer
  8554. ticks that have elapsed. A timer tick is approximately equal to
  8555. 1/%@AB@%CLOCKS_PER_SEC%@AE@% seconds.  %@NL@%
  8556. %@NL@%
  8557. %@NL@%
  8558. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8559. %@NL@%
  8560. The %@AB@%clock%@AE@% function returns the product of the time in seconds and the value
  8561. of the %@AB@%CLOCKS_PER_SEC%@AE@% constant. If the processor time is not available, the
  8562. function returns the value -1, cast as %@AB@%clock_t%@AE@%.  %@NL@%
  8563. %@NL@%
  8564. %@NL@%
  8565. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8566. %@NL@%
  8567. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  8568. %@NL@%
  8569. %@NL@%
  8570. In both DOS and OS/2, %@AB@%clock%@AE@% returns the time elapsed since the process
  8571. started. This may not be equal to the actual processor time used by the
  8572. process.  %@NL@%
  8573. %@NL@%
  8574. In previous versions of Microsoft C, the %@AB@%CLOCKS_PER_SEC%@AE@% constant was called
  8575. %@AB@%CLK_TCK%@AE@%.  %@NL@%
  8576. %@NL@%
  8577. %@NL@%
  8578. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8579. %@NL@%
  8580. %@AB@%difftime%@AE@%, %@AB@%time%@AE@%  %@NL@%
  8581. %@NL@%
  8582. %@NL@%
  8583. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8584. %@NL@%
  8585. %@AS@%  /* CLOCK.C: This example prompts for how long the program is to run and
  8586. %@AS@%   * then continuously displays the elapsed time for that period.
  8587. %@AS@%   */
  8588. %@AS@%  
  8589. %@AS@%  #include <stdio.h>
  8590. %@AS@%  #include <stdlib.h>
  8591. %@AS@%  #include <time.h>
  8592. %@AS@%  
  8593. %@AS@%  void sleep( clock_t wait );
  8594. %@AS@%  
  8595. %@AS@%  void main()
  8596. %@AS@%  {
  8597. %@AS@%     long    i = 600000L;
  8598. %@AS@%     clock_t start, finish;
  8599. %@AS@%     double  duration;
  8600. %@AS@%  
  8601. %@AS@%     /* Delay for a specified time. */
  8602. %@AS@%     printf( "Delay for three seconds\n" );
  8603. %@AS@%     sleep( (clock_t)3 * CLOCKS_PER_SEC );
  8604. %@AS@%     printf( "Done!\n" );
  8605. %@AS@%  
  8606. %@AS@%     /* Measure the duration of an event. */
  8607. %@AS@%     printf( "Time to do %ld empty loops is ", i );
  8608. %@AS@%     start = clock();
  8609. %@AS@%     while( i-- )
  8610. %@AS@%        ;
  8611. %@AS@%     finish = clock();
  8612. %@AS@%     duration = (double)(finish - start) / CLOCKS_PER_SEC;
  8613. %@AS@%     printf( "%2.1f seconds\n", duration );
  8614. %@AS@%  }
  8615. %@AS@%  
  8616. %@AS@%  /* Pauses for a specified number of microseconds. */
  8617. %@AS@%  void sleep( clock_t wait )
  8618. %@AS@%  {
  8619. %@AS@%      clock_t goal;
  8620. %@AS@%  
  8621. %@AS@%      goal = wait + clock();
  8622. %@AS@%      while( goal > clock() )
  8623. %@AS@%          ;
  8624. %@AS@%  }%@AE@%%@NL@%
  8625. %@NL@%
  8626. %@NL@%
  8627. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8628. %@NL@%
  8629. %@AS@%  
  8630. %@AS@%  
  8631. %@AS@%  Delay for five seconds
  8632. %@AS@%  Done!
  8633. %@AS@%  Time to do 900000 empty loops is 2.0 seconds%@AE@%%@NL@%
  8634. %@NL@%
  8635. %@NL@%
  8636. %@NL@%
  8637. %@NL@%
  8638. %@QR:close@%%@NL@%
  8639. %@2@%%@CR:C6A00440282 @%%@AB@%close%@AE@%%@EH@%%@NL@%
  8640. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8641. %@NL@%
  8642. %@NL@%
  8643. %@3@%%@AB@%Description%@CR:C6A00440283 @%%@CR:C6A00440284 @%%@CR:C6A00440285 @%%@AE@%%@EH@%%@NL@%
  8644. %@NL@%
  8645. Closes a file.  %@NL@%
  8646. %@NL@%
  8647. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  8648.  
  8649. %@AB@%#include <errno.h>%@AE@%                
  8650.  
  8651. %@AS@%  int close( int handle );%@AE@%%@NL@%
  8652. %@NL@%
  8653. %@AI@%handle%@AE@%                            Handle referring to open file
  8654.  
  8655. %@NL@%
  8656. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8657. %@NL@%
  8658. The %@AB@%close%@AE@% function closes the file associated with %@AI@%handle%@AE@%.  %@NL@%
  8659. %@NL@%
  8660. %@NL@%
  8661. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8662. %@NL@%
  8663. The %@AB@%close%@AE@% function returns 0 if the file was successfully closed. A return
  8664. value of -1 indicates an error, and %@AB@%errno%@AE@% is set to %@AB@%EBADF%@AE@%, indicating an
  8665. invalid file-handle argument.  %@NL@%
  8666. %@NL@%
  8667. %@NL@%
  8668. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8669. %@NL@%
  8670.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  8671. %@NL@%
  8672. %@NL@%
  8673. %@NL@%
  8674. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8675. %@NL@%
  8676. %@AB@%chsize%@AE@%, %@AB@%creat%@AE@%, %@AB@%dup%@AE@%, %@AB@%dup2%@AE@%, %@AB@%open%@AE@%, %@AB@%unlink%@AE@%  %@NL@%
  8677. %@NL@%
  8678. %@NL@%
  8679. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8680. %@NL@%
  8681. %@AS@%  /* OPEN.C: This program uses open to open a file named OPEN.C for input
  8682. %@AS@%   * and a file named OPEN.OUT for output. The files are then closed.
  8683. %@AS@%   */
  8684. %@AS@%  
  8685. %@AS@%  #include <fcntl.h>
  8686. %@AS@%  #include <sys\types.h>
  8687. %@AS@%  #include <sys\stat.h>
  8688. %@AS@%  #include <io.h>
  8689. %@AS@%  #include <stdio.h>
  8690. %@AS@%  
  8691. %@AS@%  void main()
  8692. %@AS@%  {
  8693. %@AS@%     int fh1, fh2;
  8694. %@AS@%     fh1 = open( "OPEN.C", O_RDONLY );
  8695. %@AS@%     if( fh1 == -1 )
  8696. %@AS@%        perror( "open failed on input file" );
  8697. %@AS@%     else
  8698. %@AS@%     {
  8699. %@AS@%        printf( "open succeeded on input file\n" );
  8700. %@AS@%        close( fh1 );
  8701. %@AS@%     }%@AE@%%@NL@%
  8702. %@NL@%
  8703. %@AS@%  fh2 = open( "OPEN.OUT", O_WRONLY | O_CREAT, S_IREAD | S_IWRITE );
  8704. %@AS@%     if( fh2 == -1 )
  8705. %@AS@%        perror( "open failed on output file" );
  8706. %@AS@%     else
  8707. %@AS@%     {
  8708. %@AS@%        printf( "open succeeded on output file\n" );
  8709. %@AS@%        close( fh2 );
  8710. %@AS@%     }
  8711. %@AS@%  }%@AE@%%@NL@%
  8712. %@NL@%
  8713. %@NL@%
  8714. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8715. %@NL@%
  8716. %@AS@%  
  8717. %@AS@%  
  8718. %@AS@%  open succeeded on input file
  8719. %@AS@%  open succeeded on output file%@AE@%%@NL@%
  8720. %@NL@%
  8721. %@NL@%
  8722. %@NL@%
  8723. %@NL@%
  8724. %@QR:_control87@%%@NL@%
  8725. %@2@%%@CR:C6A00450286 @%%@AB@%_control87%@AE@%%@EH@%%@NL@%
  8726. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8727. %@NL@%
  8728. %@NL@%
  8729. %@3@%%@AB@%Description%@CR:C6A00450287 @% %@CR:C6A00450288 @%%@CR:C6A00450289 @%%@AE@%%@EH@%%@NL@%
  8730. %@NL@%
  8731. Gets and sets the floating-point control word.  %@NL@%
  8732. %@NL@%
  8733. %@AS@%  #include <float.h>%@AE@%%@NL@%
  8734. %@NL@%
  8735. %@AS@%  unsigned int _control87( unsigned int new, unsigned int mask );%@AE@%%@NL@%
  8736. %@NL@%
  8737. %@AI@%new%@AE@%                               New control-word bit values
  8738.  
  8739. %@AI@%mask%@AE@%                              Mask for new control-word bits to set
  8740.  
  8741. %@NL@%
  8742. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8743. %@NL@%
  8744. The %@AB@%_control87%@AE@% function gets and sets the floating-point control word. The
  8745. floating-point control word allows the program to change the precision,
  8746. rounding, and infinity modes in the floating-point-math package.
  8747. Floating-point exceptions can also be masked or unmasked using the
  8748. %@AB@%_control87%@AE@% function.  %@NL@%
  8749. %@NL@%
  8750. If the value for %@AI@%mask%@AE@% is equal to 0, then %@AB@%_control87%@AE@% gets the floating-point
  8751. control word. If %@AI@%mask%@AE@% is nonzero, then a new value for the control word is
  8752. set in the following manner: for any bit that is on (equal to 1) in %@AI@%mask%@AE@%,
  8753. the corresponding bit in %@AI@%new%@AE@% is used to update the control word. To put it
  8754. another way,  %@NL@%
  8755. %@NL@%
  8756. %@AS@%  fpcntrl = ((fpcntrl & ~mask) | (new & mask))%@AE@%%@NL@%
  8757. %@NL@%
  8758. where %@AS@% fpcntrl %@AE@% is the floating-point control word.  %@NL@%
  8759. %@NL@%
  8760. The possible values for the mask constant (%@AI@%mask%@AE@%) and new control values
  8761. (%@AI@%new%@AE@%) are shown in Table R.1.  %@NL@%
  8762. %@NL@%
  8763. %@AB@%Table   R.1 Hex Values%@AE@%
  8764.  
  8765. %@TH:  56  1588 02 13 11 17 35 @%
  8766. Mask         Hex Value  Constant         Hex Value
  8767. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8768. MCW_EM       0x003F     
  8769. (Interrupt              
  8770. exception)              
  8771.  
  8772.                         %@AB@%EM_INVALID%@AE@%       0x0001 
  8773.  
  8774.                         %@AB@%EM_DENORMAL%@AE@%      0x0002 
  8775.  
  8776.                         %@AB@%EM_ZERODIVIDE%@AE@%    0x0004 
  8777.  
  8778.                         %@AB@%EM_OVERFLOW%@AE@%      0x0008 
  8779.  
  8780.                         %@AB@%EM_UNDERFLOW%@AE@%     0x0010 
  8781.  
  8782.                         %@AB@%EM_INEXACT%@AE@%       0x0020 
  8783.  
  8784.                         
  8785.  
  8786. MCW_IC       0x1000     
  8787. (Infinity               
  8788. control)                
  8789.  
  8790.                         %@AB@%IC_AFFINE%@AE@%        0x1000 
  8791.  
  8792.                         %@AB@%IC_PROJECTIVE%@AE@%    0x0000 
  8793.  
  8794.                         
  8795.  
  8796. MCW_RC       0x0C00     
  8797. (Rounding               
  8798. control)                
  8799.  
  8800.                         %@AB@%RC_CHOP%@AE@%          0x0C00 
  8801.  
  8802.                         %@AB@%RC_UP%@AE@%            0x0800 
  8803.  
  8804.                         %@AB@%RC_DOWN%@AE@%          0x0400 
  8805.  
  8806.                         %@AB@%RC_NEAR%@AE@%          0x0000 
  8807.  
  8808.                         
  8809.  
  8810. MCW_PC       0x0300     
  8811. (Precision              
  8812. control)                
  8813.  
  8814.                         %@AB@%PC_24 (24 bits)%@AE@%  0x0000 
  8815.  
  8816.                         %@AB@%PC_53 (53 bits)%@AE@%  0x0200 
  8817.  
  8818.                         %@AB@%PC_64 (64 bits)%@AE@%  0x0300 
  8819.  
  8820. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8821.  
  8822. %@TE:  56  1588 02 13 11 17 35 @%
  8823.  
  8824. %@NL@%
  8825. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8826. %@NL@%
  8827. The bits in the value returned indicate the floating-point control state.
  8828. See the FLOAT.H include file for a complete definition of the bits returned
  8829. by %@AB@%_control87%@AE@%.  %@NL@%
  8830. %@NL@%
  8831. %@NL@%
  8832. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8833. %@NL@%
  8834.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  8835. %@NL@%
  8836. %@NL@%
  8837. %@NL@%
  8838. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8839. %@NL@%
  8840. %@AB@%_clear87%@AE@%, %@AB@% _status87%@AE@%  %@NL@%
  8841. %@NL@%
  8842. %@NL@%
  8843. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8844. %@NL@%
  8845. %@AS@%  /* CNTRL87.C: This program uses _control87 to output the control word,
  8846. %@AS@%   * set the precision to 24 bits, and reset the status to the default.
  8847. %@AS@%   */
  8848. %@AS@%  
  8849. %@AS@%  #include <stdio.h>
  8850. %@AS@%  #include <float.h>%@AE@%%@NL@%
  8851. %@NL@%
  8852. %@AS@%  void main()
  8853. %@AS@%  {
  8854. %@AS@%     double a = 0.1;
  8855. %@AS@%  
  8856. %@AS@%     /* Show original control word and do calculation. */
  8857. %@AS@%     printf( "Original: 0x%.4x\n", _control87( 0, 0 ) );
  8858. %@AS@%     printf( "%1.1f * %1.1f = %.15e\n", a, a, a * a );
  8859. %@AS@%  
  8860. %@AS@%     /* Set precision to 24 bits and recalculate. */
  8861. %@AS@%     printf( "24-bit:   0x%.4x\n", _control87( PC_24, MCW_PC ) );
  8862. %@AS@%     printf( "%1.1f * %1.1f = %.15e\n", a, a, a * a );
  8863. %@AS@%  
  8864. %@AS@%     /* Restore to default and recalculate. */
  8865. %@AS@%     printf( "Default:  0x%.4x\n", _control87( CW_DEFAULT, 0xffff ) );
  8866. %@AS@%     printf( "%1.1f * %1.1f = %.15e\n", a, a, a * a );
  8867. %@AS@%  }%@AE@%%@NL@%
  8868. %@NL@%
  8869. %@NL@%
  8870. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8871. %@NL@%
  8872. %@AS@%  
  8873. %@AS@%  
  8874. %@AS@%  Original: 0x1332
  8875. %@AS@%  0.1 * 0.1 = 1.000000000000000e-002
  8876. %@AS@%  24-bit:   0x1332
  8877. %@AS@%  0.1 * 0.1 = 9.999999776482582e-003
  8878. %@AS@%  Default:  0x1032
  8879. %@AS@%  0.1 * 0.1 = 1.000000000000000e-002%@AE@%%@NL@%
  8880. %@NL@%
  8881. %@NL@%
  8882. %@NL@%
  8883. %@NL@%
  8884. %@QR:cos@%%@NL@%
  8885. %@2@%%@CR:C6A00460290 @%%@AB@%cos Functions%@AE@%%@EH@%%@NL@%
  8886. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8887. %@NL@%
  8888. %@NL@%
  8889. %@3@%%@AB@%Description%@CR:C6A00460291 @%%@CR:C6A00460292 @%%@CR:C6A00460293 @% %@CR:C6A00460294 @%%@AE@%%@EH@%%@NL@%
  8890. %@NL@%
  8891. Calculate the cosine (%@AB@%cos%@AE@% and %@AB@%cosl%@AE@%) or hyperbolic cosine (%@AB@%cosh%@AE@% and %@AB@%coshl%@AE@%).  %@NL@%
  8892. %@NL@%
  8893. %@AS@%  #include <math.h>%@AE@%%@NL@%
  8894. %@NL@%
  8895. %@AS@%  double cos( double x );%@AE@%%@NL@%
  8896. %@NL@%
  8897. %@AS@%  double cosh( double x );%@AE@%%@NL@%
  8898. %@NL@%
  8899. %@AS@%  long double cosl( long double x );%@AE@%%@NL@%
  8900. %@NL@%
  8901. %@AS@%  long double coshl( long double x );%@AE@%%@NL@%
  8902. %@NL@%
  8903. %@AI@%x%@AE@%                                 Angle in radians
  8904.  
  8905. %@NL@%
  8906. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  8907. %@NL@%
  8908. The %@AB@%cos%@AE@% and %@AB@%cosh%@AE@% functions return the cosine and hyperbolic cosine,
  8909. respectively, of %@AI@%x%@AE@%.  %@NL@%
  8910. %@NL@%
  8911. The %@AB@%cosl%@AE@% and %@AB@%coshl%@AE@% functions are the 80-bit counterparts and use the 80-bit,
  8912. 10-byte coprocessor form of arguments and return values. See the reference
  8913. page on the long double functions for more details on this data type.%@AB@%  %@AE@%%@NL@%
  8914. %@NL@%
  8915. %@NL@%
  8916. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  8917. %@NL@%
  8918. If %@AI@%x%@AE@% is large, a partial loss of significance in the result may occur in a
  8919. call to %@AB@%cos%@AE@%, in which case the function generates a %@AB@%PLOSS%@AE@% error. If %@AI@%x%@AE@% is so
  8920. large that significance is completely lost, %@AB@%cos%@AE@% prints a %@AB@%TLOSS%@AE@% message to
  8921. %@AB@%stderr%@AE@% and returns 0. In both cases, %@AB@%errno%@AE@% is set to %@AB@%ERANGE.%@AE@%  %@NL@%
  8922. %@NL@%
  8923. If the result is too large in a %@AB@%cosh%@AE@% call, the function returns %@AB@%HUGE_VAL%@AE@% and
  8924. sets %@AB@%errno%@AE@% to %@AB@%ERANGE%@AE@%.  %@NL@%
  8925. %@NL@%
  8926. %@NL@%
  8927. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  8928. %@NL@%
  8929. %@AB@%cos%@AE@%,%@AB@% cosh%@AE@%  %@NL@%
  8930. %@NL@%
  8931. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  8932. %@NL@%
  8933. %@NL@%
  8934. %@AB@%cosl%@AE@%, %@AB@%coshl%@AE@%  %@NL@%
  8935. %@NL@%
  8936.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  8937. %@NL@%
  8938. %@NL@%
  8939. %@NL@%
  8940. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  8941. %@NL@%
  8942. %@AB@%acos %@AE@%functions, %@AB@%asin %@AE@%functions, %@AB@%atan%@AE@% functions, %@AB@%matherr%@AE@%, %@AB@%sin%@AE@% functions, %@AB@%tan%@AE@%
  8943. functions  %@NL@%
  8944. %@NL@%
  8945. %@NL@%
  8946. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  8947. %@NL@%
  8948. %@AS@%  /* SINCOS.C: This program displays the sine, hyperbolic sine, cosine,
  8949. %@AS@%   * and hyperbolic cosine of pi / 2.
  8950. %@AS@%   */
  8951. %@AS@%  
  8952. %@AS@%  #include <math.h>
  8953. %@AS@%  #include <stdio.h>
  8954. %@AS@%  
  8955. %@AS@%  void main()
  8956. %@AS@%  {
  8957. %@AS@%     double pi = 3.1415926535;
  8958. %@AS@%     double x, y;
  8959. %@AS@%  
  8960. %@AS@%     x = pi / 2;
  8961. %@AS@%     y = sin( x );
  8962. %@AS@%     printf( "sin( %f ) = %f\n", x, y );
  8963. %@AS@%     y = sinh( x );
  8964. %@AS@%     printf( "sinh( %f ) = %f\n",x, y );
  8965. %@AS@%     y = cos( x );
  8966. %@AS@%     printf( "cos( %f ) = %f\n", x, y );
  8967. %@AS@%     y = cosh( x );
  8968. %@AS@%     printf( "cosh( %f ) = %f\n",x, y );
  8969. %@AS@%  }%@AE@%%@NL@%
  8970. %@NL@%
  8971. %@NL@%
  8972. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  8973. %@NL@%
  8974. %@AS@%  
  8975. %@AS@%  
  8976. %@AS@%  sin( 1.570796 ) = 1.000000
  8977. %@AS@%  sinh( 1.570796 ) = 2.301299
  8978. %@AS@%  cos( 1.570796 ) = 0.000000
  8979. %@AS@%  cosh( 1.570796 ) = 2.509178 %@AE@%%@NL@%
  8980. %@NL@%
  8981. %@NL@%
  8982. %@NL@%
  8983. %@NL@%
  8984. %@QR:cprintf@%%@NL@%
  8985. %@2@%%@CR:C6A00470295 @%%@AB@%cprintf%@AE@%%@EH@%%@NL@%
  8986. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  8987. %@NL@%
  8988. %@NL@%
  8989. %@3@%%@AB@%Description%@CR:C6A00470296 @%%@CR:C6A00470297 @% %@CR:C6A00470298 @%%@CR:C6A00470299 @% %@CR:C6A00470300 @%%@CR:C6A00470301 @%%@AE@%%@EH@%%@NL@%
  8990. %@NL@%
  8991. Formats and prints to the console.  %@NL@%
  8992. %@NL@%
  8993. %@AB@%#include <conio.h>%@AE@%                Required only for function declarations
  8994.  
  8995. %@AS@%  int cprintf( char *format [[, argument]] ... );%@AE@%%@NL@%
  8996. %@NL@%
  8997. %@AI@%format%@AE@%                            Format control string
  8998.  
  8999. %@AI@%argument%@AE@%                          Optional arguments
  9000.  
  9001. %@NL@%
  9002. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9003. %@NL@%
  9004. The %@AB@%cprintf%@AE@% function formats and prints a series of characters and values
  9005. directly to the console, using the %@AB@%putch%@AE@% function to output characters. Each
  9006. %@AI@%argument%@AE@% (if any) is converted and output according to the corresponding
  9007. format specification in %@AI@%format%@AE@%. The format has the same form and function as
  9008. the %@AI@%format%@AE@% argument for the %@AB@%printf%@AE@% function; see %@AB@%printf%@AE@% for a description of
  9009. the format and arguments.  %@NL@%
  9010. %@NL@%
  9011. Note that unlike the %@AB@%fprintf%@AE@%, %@AB@%printf%@AE@%, and %@AB@%sprintf%@AE@% functions, %@AB@%cprintf%@AE@% does
  9012. not translate line-feed characters into carriage-return-line-feed
  9013. combinations on output.  %@NL@%
  9014. %@NL@%
  9015. %@NL@%
  9016. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9017. %@NL@%
  9018. The %@AB@%cprintf%@AE@% function returns the number of characters printed.  %@NL@%
  9019. %@NL@%
  9020. %@NL@%
  9021. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9022. %@NL@%
  9023.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9024. %@NL@%
  9025. %@NL@%
  9026. %@NL@%
  9027. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9028. %@NL@%
  9029. %@AB@%cscanf, fprintf%@AE@%, %@AB@%printf%@AE@%, %@AB@%sprintf%@AE@%, %@AB@%vprintf%@AE@%  %@NL@%
  9030. %@NL@%
  9031. %@NL@%
  9032. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9033. %@NL@%
  9034. %@AS@%  /* CPRINTF.C: This program displays some variables to the console. */
  9035. %@AS@%  
  9036. %@AS@%  #include <conio.h>
  9037. %@AS@%  
  9038. %@AS@%  void main()
  9039. %@AS@%  {
  9040. %@AS@%     int      i = -16, h = 29;
  9041. %@AS@%     unsigned u = 62511;
  9042. %@AS@%     char     c = 'A';
  9043. %@AS@%     char     s[] = "Test";%@AE@%%@NL@%
  9044. %@NL@%
  9045. %@AS@%  /* Note that console output does not translate \n as
  9046. %@AS@%      * standard output does. Use \r\n instead.
  9047. %@AS@%      */
  9048. %@AS@%     cprintf( "%d  %.4x  %u  %c %s\r\n", i, h, u, c, s );
  9049. %@AS@%  
  9050. %@AS@%  }%@AE@%%@NL@%
  9051. %@NL@%
  9052. %@NL@%
  9053. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9054. %@NL@%
  9055. %@AS@%  
  9056. %@AS@%  
  9057. %@AS@%  -16  001d  62511  A Test%@AE@%%@NL@%
  9058. %@NL@%
  9059. %@NL@%
  9060. %@NL@%
  9061. %@NL@%
  9062. %@QR:cputs@%%@NL@%
  9063. %@2@%%@CR:C6A00480302 @%%@AB@%cputs%@AE@%%@EH@%%@NL@%
  9064. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9065. %@NL@%
  9066. %@NL@%
  9067. %@3@%%@AB@%Description%@CR:C6A00480303 @%%@CR:C6A00480304 @% %@CR:C6A00480305 @%%@CR:C6A00480306 @%%@AE@%%@EH@%%@NL@%
  9068. %@NL@%
  9069. Puts a string to the console.  %@NL@%
  9070. %@NL@%
  9071. %@AB@%#include <conio.h>%@AE@%                Required only for function declarations
  9072.  
  9073. %@AS@%  int cputs( char *string );%@AE@%%@NL@%
  9074. %@NL@%
  9075. %@AI@%string%@AE@%                            Output string
  9076.  
  9077. %@NL@%
  9078. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9079. %@NL@%
  9080. The %@AB@%cputs%@AE@% function writes the null-terminated string pointed to by %@AI@%string%@AE@%
  9081. directly to the console. Note that a carriage-return-line-feed (CR-LF)
  9082. combination is not automatically appended to the string.  %@NL@%
  9083. %@NL@%
  9084. %@NL@%
  9085. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9086. %@NL@%
  9087. If successful, %@AB@%cputs%@AE@% returns a 0. If the function fails, it returns a
  9088. nonzero value.  %@NL@%
  9089. %@NL@%
  9090. %@NL@%
  9091. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9092. %@NL@%
  9093.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9094. %@NL@%
  9095. %@NL@%
  9096. %@NL@%
  9097. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9098. %@NL@%
  9099. %@AB@%putch%@AE@%  %@NL@%
  9100. %@NL@%
  9101. %@NL@%
  9102. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9103. %@NL@%
  9104. %@AS@%  /* CPUTS.C: This program first displays a string to the console. */
  9105. %@AS@%  
  9106. %@AS@%  #include <conio.h>
  9107. %@AS@%  
  9108. %@AS@%  void main()
  9109. %@AS@%  {
  9110. %@AS@%     /* String to print at console. Note the \r (return) character. */
  9111. %@AS@%     char *buffer = "Hello world (courtesy of cputs)!\r\n";
  9112. %@AS@%  
  9113. %@AS@%     cputs( buffer );
  9114. %@AS@%  }%@AE@%%@NL@%
  9115. %@NL@%
  9116. %@NL@%
  9117. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9118. %@NL@%
  9119. %@AS@%  
  9120. %@AS@%  
  9121. %@AS@%  Hello world (courtesy of cputs)! %@AE@%%@NL@%
  9122. %@NL@%
  9123. %@NL@%
  9124. %@NL@%
  9125. %@NL@%
  9126. %@QR:creat@%%@NL@%
  9127. %@2@%%@CR:C6A00490307 @%%@AB@%creat%@AE@%%@EH@%%@NL@%
  9128. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9129. %@NL@%
  9130. %@NL@%
  9131. %@3@%%@AB@%Description%@CR:C6A00490308 @%%@CR:C6A00490309 @%%@CR:C6A00490310 @% %@CR:C6A00490311 @%%@AE@%%@EH@%%@NL@%
  9132. %@NL@%
  9133. Creates a new file.  %@NL@%
  9134. %@NL@%
  9135. %@AB@%#include <sys\types.h>%@AE@%            
  9136.  
  9137. %@AB@%#include <sys\stat.h>%@AE@%             
  9138.  
  9139. %@AB@%#include <errno.h>%@AE@%                
  9140.  
  9141. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  9142.  
  9143. %@AS@%  int creat( char *filename, int pmode );%@AE@%%@NL@%
  9144. %@NL@%
  9145. %@AI@%filename%@AE@%                          Path name of new file
  9146.  
  9147. %@AI@%pmode%@AE@%                             Permission setting
  9148.  
  9149. %@NL@%
  9150. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9151. %@NL@%
  9152. The %@AB@%creat%@AE@% function either creates a new file or opens and truncates an
  9153. existing file. If the file specified by %@AI@%filename%@AE@% does not exist, a new file
  9154. is created with the given permission setting and is opened for writing. If
  9155. the file already exists and its permission setting allows writing, %@AB@%creat%@AE@%
  9156. truncates the file to length 0, destroying the previous contents, and opens
  9157. it for writing.  %@NL@%
  9158. %@NL@%
  9159. The permission setting, %@AI@%pmode%@AE@%, applies to newly created files only. The new
  9160. file receives the specified permission setting after it is closed for the
  9161. first time. The integer expression %@AI@%pmode%@AE@% contains one or both of the
  9162. manifest constants %@AB@%S_IWRITE%@AE@% and%@AB@% S_IREAD%@AE@%, defined in SYS\STAT.H. When both of
  9163. the constants are given, they are joined with the bitwise-OR operator ( | ).
  9164. The %@AI@%pmode%@AE@% argument is set to one of the following values: %@CR:C6A00490312 @%  %@NL@%
  9165. %@NL@%
  9166. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  9167. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9168. %@AB@%S_IWRITE%@AE@%                          Writing permitted
  9169.  
  9170. %@AB@%S_IREAD%@AE@%                           Reading permitted
  9171.  
  9172. %@AB@%S_IREAD%@AE@% | %@AB@%S_IWRITE%@AE@%                Reading and writing permitted
  9173.  
  9174. If write permission is not given, the file is read-only. Under DOS and OS/2,
  9175. it is not possible to give write-only permission. Thus, the %@AB@%S_IWRITE%@AE@% and
  9176. %@AB@%S_IREAD%@AE@% | %@AB@%S_IWRITE%@AE@% modes are equivalent. Under DOS versions 3.0 and later,
  9177. files opened using %@AB@%creat%@AE@% are always opened in compatibility mode (see%@AB@%
  9178. %@AB@%sopen%@AE@%).  %@NL@%
  9179. %@NL@%
  9180. The %@AB@%creat%@AE@% function applies the current file-permission mask to %@AI@%pmode%@AE@% before
  9181. setting the permissions (see %@AB@%umask%@AE@%).  %@NL@%
  9182. %@NL@%
  9183. Note that the %@AB@%creat%@AE@% routine is provided primarily for compatibility with
  9184. previous libraries. A call to %@AB@%open%@AE@% with %@AB@%O_CREAT%@AE@% and %@AB@%O_TRUNC%@AE@% in the %@AI@%oflag
  9185. %@AI@%%@AE@%argument is equivalent to %@AB@%creat%@AE@% and is preferable for new code.  %@NL@%
  9186. %@NL@%
  9187. %@NL@%
  9188. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9189. %@NL@%
  9190. If successful, %@AB@%creat%@AE@% returns a handle for the created file. Otherwise, it
  9191. returns -1 and sets %@AB@%errno%@AE@% to one of the following constants:  %@NL@%
  9192. %@NL@%
  9193. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  9194. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9195. %@AB@%EACCES%@AE@%                            Path name specifies an existing 
  9196.                                   read-only file or specifies a directory 
  9197.                                   instead of a file
  9198.  
  9199. %@AB@%EMFILE %@AE@%                           No more handles available (too many open
  9200.                                   files)
  9201.  
  9202. %@AB@%ENOENT%@AE@%                            Path name not found
  9203.  
  9204. %@NL@%
  9205. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9206. %@NL@%
  9207.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  9208. %@NL@%
  9209. %@NL@%
  9210. %@NL@%
  9211. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9212. %@NL@%
  9213. %@AB@%chmod%@AE@%, %@AB@%chsize%@AE@%, %@AB@%close%@AE@%, %@AB@%dup%@AE@%, %@AB@%dup2%@AE@%, %@AB@%open%@AE@%, %@AB@%sopen%@AE@%, %@AB@%umask%@AE@%  %@NL@%
  9214. %@NL@%
  9215. %@NL@%
  9216. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9217. %@NL@%
  9218. %@AS@%  /* CREAT.C: This program uses creat to create the file (or truncate the
  9219. %@AS@%   * existing file) named data and open it for writing.
  9220. %@AS@%   */
  9221. %@AS@%  
  9222. %@AS@%  #include <sys\types.h>
  9223. %@AS@%  #include <sys\stat.h>
  9224. %@AS@%  #include <io.h>
  9225. %@AS@%  #include <stdio.h>
  9226. %@AS@%  #include <stdlib.h>
  9227. %@AS@%  
  9228. %@AS@%  void main()
  9229. %@AS@%  {
  9230. %@AS@%     int fh;
  9231. %@AS@%  
  9232. %@AS@%     fh = creat( "data", S_IREAD | S_IWRITE );
  9233. %@AS@%     if( fh == -1 )
  9234. %@AS@%        perror( "Couldn't create data file" );
  9235. %@AS@%     else
  9236. %@AS@%     {
  9237. %@AS@%        printf( "Created data file.\n" );
  9238. %@AS@%        close( fh );
  9239. %@AS@%     }
  9240. %@AS@%  }%@AE@%%@NL@%
  9241. %@NL@%
  9242. %@NL@%
  9243. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9244. %@NL@%
  9245. %@AS@%  
  9246. %@AS@%  
  9247. %@AS@%  Created data file.%@AE@%%@NL@%
  9248. %@NL@%
  9249. %@NL@%
  9250. %@NL@%
  9251. %@NL@%
  9252. %@QR:cscanf@%%@NL@%
  9253. %@2@%%@CR:C6A00500313 @%%@AB@%cscanf%@AE@%%@EH@%%@NL@%
  9254. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9255. %@NL@%
  9256. %@NL@%
  9257. %@3@%%@AB@%Description%@CR:C6A00500314 @%%@CR:C6A00500315 @% %@CR:C6A00500316 @%%@CR:C6A00500317 @% %@CR:C6A00500318 @%%@AE@%%@EH@%%@NL@%
  9258. %@NL@%
  9259. Reads formatted data from the console.  %@NL@%
  9260. %@NL@%
  9261. %@AB@%#include <conio.h>%@AE@%                Required only for function declarations
  9262.  
  9263. %@AS@%  int cscanf( char *format [[, argument]] ... );%@AE@%%@NL@%
  9264. %@NL@%
  9265. %@AI@%format%@AE@%                            Format-control string
  9266.  
  9267. %@AI@%argument%@AE@%                          Optional arguments
  9268.  
  9269. %@NL@%
  9270. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9271. %@NL@%
  9272. The %@AB@%cscanf%@AE@% function reads data directly from the console into the locations
  9273. given by %@AI@%argument%@AE@%. The %@AB@%getche%@AE@% function is used to read characters. Each
  9274. optional argument must be a pointer to a variable with a type that
  9275. corresponds to a type specifier in %@AI@%format%@AE@%. The format controls the
  9276. interpretation of the input fields and has the same form and function as the
  9277. %@AI@%format%@AE@% argument for the %@AB@%scanf%@AE@% function; see %@AB@%scanf%@AE@% for a description of
  9278. %@AI@%format%@AE@%.  %@NL@%
  9279. %@NL@%
  9280. While %@AB@%cscanf%@AE@% normally echoes the input character, it will not do so if the
  9281. last call was to %@AB@%ungetch%@AE@%.  %@NL@%
  9282. %@NL@%
  9283. %@NL@%
  9284. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9285. %@NL@%
  9286. The %@AB@%cscanf%@AE@% function returns the number of fields that were successfully
  9287. converted and assigned. The return value does not include fields that were
  9288. read but not assigned.  %@NL@%
  9289. %@NL@%
  9290. The return value is %@AB@%EOF%@AE@% for an attempt to read at end-of-file. This may
  9291. occur when keyboard input is redirected at the operating system command-line
  9292. level. A return value of 0 means that no fields were assigned.  %@NL@%
  9293. %@NL@%
  9294. %@NL@%
  9295. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9296. %@NL@%
  9297.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9298. %@NL@%
  9299. %@NL@%
  9300. %@NL@%
  9301. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9302. %@NL@%
  9303. %@AB@%cprintf, fscanf, scanf, sscanf%@AE@%  %@NL@%
  9304. %@NL@%
  9305. %@NL@%
  9306. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9307. %@NL@%
  9308. %@AS@%  /* CSCANF.C: This program prompts for a string and uses cscanf to read
  9309. %@AS@%   * in the response. Then cscanf returns the number of items matched,
  9310. %@AS@%   * and the program displays that number.
  9311. %@AS@%   */
  9312. %@AS@%  
  9313. %@AS@%  #include <stdio.h>
  9314. %@AS@%  #include <conio.h>%@AE@%%@NL@%
  9315. %@NL@%
  9316. %@AS@%  void main()
  9317. %@AS@%  {
  9318. %@AS@%     int   result, i[3];
  9319. %@AS@%  
  9320. %@AS@%     cprintf( "Enter three integers: ");
  9321. %@AS@%     result = cscanf( "%i %i %i", &i[0], &i[1], &i[2] );
  9322. %@AS@%     cprintf( "\r\nYou entered " );
  9323. %@AS@%     while( result-- )
  9324. %@AS@%        cprintf( "%i ", i[result] );
  9325. %@AS@%     cprintf( "\r\n" );
  9326. %@AS@%  
  9327. %@AS@%  }%@AE@%%@NL@%
  9328. %@NL@%
  9329. %@NL@%
  9330. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9331. %@NL@%
  9332. %@AS@%  
  9333. %@AS@%  
  9334. %@AS@%  Enter three integers: 34 43 987k
  9335. %@AS@%  You entered 987 43 34 %@AE@%%@NL@%
  9336. %@NL@%
  9337. %@NL@%
  9338. %@NL@%
  9339. %@NL@%
  9340. %@QR:ctime@%%@NL@%
  9341. %@2@%%@CR:C6A00510319 @%%@AB@%ctime%@AE@%%@EH@%%@NL@%
  9342. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9343. %@NL@%
  9344. %@NL@%
  9345. %@3@%%@AB@%Description%@CR:C6A00510320 @%%@CR:C6A00510321 @% %@CR:C6A00510322 @%%@AE@%%@EH@%%@NL@%
  9346. %@NL@%
  9347. Converts a time stored as a %@AB@%time_t%@AE@% value to a character string.  %@NL@%
  9348. %@NL@%
  9349. %@AB@%#include <time.h>%@AE@%                 Required only for function declarations
  9350.  
  9351. %@AS@%  char *ctime( const time_t *timer );%@AE@%%@NL@%
  9352. %@NL@%
  9353. %@AI@%timer%@AE@%                             Pointer to stored time
  9354.  
  9355. %@NL@%
  9356. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9357. %@NL@%
  9358. The %@AB@%ctime%@AE@% function converts a time stored as a %@AB@%time_t%@AE@% value to a character
  9359. string. The %@AI@%timer%@AE@% value is usually obtained from a call to %@AB@%time%@AE@%, which
  9360. returns the number of seconds elapsed since 00:00:00 Greenwich mean time,
  9361. January 1, 1970.  %@NL@%
  9362. %@NL@%
  9363. The string result produced by %@AB@%ctime%@AE@% contains exactly 26 characters and has
  9364. the form of the following example:  %@NL@%
  9365. %@NL@%
  9366. %@AS@%  Wed Jan 02 02:03:55 1980\n\0%@AE@%%@NL@%
  9367. %@NL@%
  9368. A 24-hour clock is used. All fields have a constant width. The newline
  9369. character (%@AB@%\n%@AE@%)%@AB@% %@AE@%and the null character (%@AB@%'\0'%@AE@%) occupy the last two positions
  9370. of the string.  %@NL@%
  9371. %@NL@%
  9372. Calls to the %@AB@%ctime%@AE@% function modify the single statically allocated buffer
  9373. used by the %@AB@%gmtime%@AE@% and the %@AB@%localtime%@AE@% functions. Each call to one of these
  9374. routines destroys the result of the previous call. The %@AB@%ctime%@AE@% function also
  9375. shares a static buffer with the %@AB@%asctime%@AE@% function. Thus, a call to %@AB@%ctime%@AE@%
  9376. destroys the results of any previous call to%@AB@% asctime%@AE@%, %@AB@%localtime%@AE@%, or %@AB@%gmtime%@AE@%.
  9377. %@NL@%
  9378. %@NL@%
  9379. %@NL@%
  9380. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9381. %@NL@%
  9382. The %@AB@%ctime%@AE@% function returns a pointer to the character string result. If %@AI@%time%@AE@%
  9383. represents a date before 1980, %@AB@%ctime%@AE@% returns %@AB@%NULL%@AE@%.  %@NL@%
  9384. %@NL@%
  9385. %@NL@%
  9386. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9387. %@NL@%
  9388. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  9389. %@NL@%
  9390. %@NL@%
  9391. %@NL@%
  9392. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9393. %@NL@%
  9394. %@AB@%asctime%@AE@%, %@AB@%ftime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%time%@AE@%  %@NL@%
  9395. %@NL@%
  9396. %@NL@%
  9397. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9398. %@NL@%
  9399. %@AS@%  /* ASCTIME.C: This program places the system time in the long integer
  9400. %@AS@%  aclock,
  9401. %@AS@%   * translates it into the structure newtime and then converts it to
  9402. %@AS@%   * string form for output, using the asctime function.
  9403. %@AS@%   */
  9404. %@AS@%  
  9405. %@AS@%  #include <time.h>
  9406. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  9407. %@NL@%
  9408. %@AS@%  struct tm *newtime;
  9409. %@AS@%  time_t aclock;
  9410. %@AS@%  
  9411. %@AS@%  void main()
  9412. %@AS@%  {
  9413. %@AS@%     time( &aclock );                    /* Get time in seconds. */
  9414. %@AS@%  
  9415. %@AS@%     newtime = localtime( &aclock );     /* Convert time to struct tm form.
  9416. %@AS@%*/
  9417. %@AS@%  
  9418. %@AS@%     /* Print local time as a string. */
  9419. %@AS@%     printf( "The current date and time are: %s\n", asctime( newtime ) );
  9420. %@AS@%  }%@AE@%%@NL@%
  9421. %@NL@%
  9422. %@NL@%
  9423. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9424. %@NL@%
  9425. %@AS@%  
  9426. %@AS@%  
  9427. %@AS@%  The current date and time are: Thu Jun 15 06:57:59 1989%@AE@%%@NL@%
  9428. %@NL@%
  9429. %@NL@%
  9430. %@NL@%
  9431. %@NL@%
  9432. %@QR:cwait@%%@NL@%
  9433. %@2@%%@CR:C6A00520323 @%%@AB@%cwait%@AE@%%@EH@%%@NL@%
  9434. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9435. %@NL@%
  9436. %@NL@%
  9437. %@3@%%@AB@%Description%@CR:C6A00520324 @%%@CR:C6A00520325 @% %@CR:C6A00520326 @%%@CR:C6A00520327 @%%@AE@%%@EH@%%@NL@%
  9438. %@NL@%
  9439. Waits until the child process terminates.  %@NL@%
  9440. %@NL@%
  9441. %@AS@%  #include <process.h>%@AE@%%@NL@%
  9442. %@NL@%
  9443. %@AS@%  int cwait( int *termstat, int procid, int action );%@AE@%%@NL@%
  9444. %@NL@%
  9445. %@AI@%termstat%@AE@%                          Address for termination status code
  9446.  
  9447. %@AI@%procid%@AE@%                            Process ID of child
  9448.  
  9449. %@AI@%action%@AE@%                            Action code
  9450.  
  9451. %@NL@%
  9452. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9453. %@NL@%
  9454. The %@AB@%cwait%@AE@% function suspends the calling process until the specified child
  9455. process terminates.  %@NL@%
  9456. %@NL@%
  9457. If not %@AB@%NULL%@AE@%, %@AI@%termstat%@AE@% points to a buffer where %@AB@%cwait%@AE@% will place the
  9458. termination-status word and the return code of the terminated child process.
  9459. %@NL@%
  9460. %@NL@%
  9461. The termination-status word indicates whether or not the child process
  9462. terminated normally by calling the OS/2 %@AB@%DosExit%@AE@% function. (Programs that
  9463. terminate with %@AB@%exit%@AE@% or by "falling off the end of main" use %@AB@%DosExit%@AE@%
  9464. internally.) If the process did terminate normally, the low-order and
  9465. high-order bytes of the termination-status word are as follows:  %@NL@%
  9466. %@NL@%
  9467. %@AB@%Byte%@AE@%                              %@AB@%Contents%@AE@%
  9468. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9469. High order                        Contains the low-order byte of the 
  9470.                                   result code that the child code passed 
  9471.                                   to %@AB@%DosExit%@AE@%. The%@AB@% DosExit%@AE@% function is 
  9472.                                   called if the child process called %@AB@%exit%@AE@% 
  9473.                                   or %@AB@%_exit%@AE@%, returned from %@AB@%main%@AE@%, or reached
  9474.                                   the end of %@AB@%main%@AE@%. The low-order byte of 
  9475.                                   the result code is either the low-order 
  9476.                                   byte of the argument to %@AB@%_exit%@AE@% or %@AB@%exit%@AE@%, 
  9477.                                   the low-order byte of the return value 
  9478.                                   from %@AB@%main%@AE@%, or a random value if the 
  9479.                                   child process reached the end of %@AB@%main%@AE@%.
  9480.  
  9481. Low order                         0 (normal termination).
  9482.  
  9483. If the child process terminates without calling %@AB@%DosExit%@AE@%, the high-order and
  9484. low-order bytes of the termination-status word are as follows:  %@NL@%
  9485. %@NL@%
  9486. %@AB@%Byte%@AE@%                              %@AB@%Contents%@AE@%
  9487. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9488. High order                        0
  9489.  
  9490. Low order                         Termination code from %@AB@%DosCWait%@AE@%:
  9491.  
  9492.                                   %@AB@%Code%@AE@%        %@AB@%Meaning%@AE@%
  9493. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9494.                                   1           Hard-error abort
  9495.  
  9496.                                   2           Trap operation
  9497.  
  9498.                                   3           %@AB@%SIGTERM%@AE@% signal not 
  9499.                                               intercepted
  9500.  
  9501. The %@AI@%procid%@AE@% argument specifies which child-process termination to wait for.
  9502. This value is returned by the call to the %@AB@%spawn%@AE@% function that started the
  9503. child process. If the specified child process terminates before %@AB@%cwait%@AE@% is
  9504. called, the function returns immediately.  %@NL@%
  9505. %@NL@%
  9506. The %@AI@%action%@AE@% argument specifies when the parent process resumes execution, as
  9507. shown in the following list:  %@NL@%
  9508. %@NL@%
  9509. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  9510. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9511. %@AB@%WAIT_CHILD%@AE@%                        The parent process waits until the 
  9512.                                   specified child process has ended.
  9513.  
  9514. %@AB@%WAIT_GRANDCHILD%@AE@%                   The parent process waits until the 
  9515.                                   specified child process and all child 
  9516.                                   processes of that child process have 
  9517.                                   ended.
  9518.  
  9519. The %@AB@%WAIT_CHILD%@AE@% and %@AB@%WAIT_GRANDCHILD%@AE@% action codes are defined in PROCESS.H.  %@NL@%
  9520. %@NL@%
  9521. %@NL@%
  9522. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9523. %@NL@%
  9524. If the %@AB@%cwait%@AE@% function returns after normal termination of the child process,
  9525. it returns the child's process ID.  %@NL@%
  9526. %@NL@%
  9527. If the %@AB@%cwait%@AE@% function returns after abnormal termination of the child
  9528. process, it returns -1 and sets %@AB@%errno%@AE@% to%@AB@% EINTR%@AE@%.  %@NL@%
  9529. %@NL@%
  9530. Otherwise, the %@AB@%cwait%@AE@% function returns -1 immediately and sets %@AB@%errno%@AE@% to one
  9531. of the following error codes:  %@NL@%
  9532. %@NL@%
  9533. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  9534. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9535. %@AB@%ECHILD%@AE@%                            No child process exists, or invalid 
  9536.                                   process ID
  9537.  
  9538. %@AB@%EINVAL%@AE@%                            Invalid action code
  9539.  
  9540. %@NL@%
  9541. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9542. %@NL@%
  9543.  ANSI   DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9544. %@NL@%
  9545. %@NL@%
  9546. Note that the OS/2 %@AB@%DosExit%@AE@% function allows programs to return a 16-bit
  9547. result code. However, the %@AB@%wait%@AE@% and %@AB@%cwait%@AE@% functions return only the low-order
  9548. byte of that result code.  %@NL@%
  9549. %@NL@%
  9550. %@NL@%
  9551. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9552. %@NL@%
  9553. %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, %@AB@%spawn %@AE@%functions, %@AB@%wait%@AE@%  %@NL@%
  9554. %@NL@%
  9555. %@NL@%
  9556. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9557. %@NL@%
  9558. %@AS@%  /* CWAIT.C: This program launches several child processes and waits
  9559. %@AS@%   * for a specified process to finish.
  9560. %@AS@%   */
  9561. %@AS@%  
  9562. %@AS@%  #define INCL_NOPM
  9563. %@AS@%  #define INCL_NOCOMMON
  9564. %@AS@%  #define INCL_DOSPROCESS
  9565. %@AS@%  #include <os2.h>        /* DosSleep */
  9566. %@AS@%  #include <process.h>    /* cwait    */
  9567. %@AS@%  #include <stdlib.h>
  9568. %@AS@%  #include <stdio.h>
  9569. %@AS@%  #include <time.h>
  9570. %@AS@%  
  9571. %@AS@%  /* Macro to get a random integer within a specified range */
  9572. %@AS@%  #define getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) +
  9573. %@AS@%(min))
  9574. %@AS@%  
  9575. %@AS@%  struct  CHILD
  9576. %@AS@%  {
  9577. %@AS@%      int     pid;
  9578. %@AS@%      char    name[10];
  9579. %@AS@%  } child[4] = { { 0, "Ann" }, { 0, "Beth"  }, { 0, "Carl" }, { 0, "Dave" }
  9580. %@AS@%};
  9581. %@AS@%  
  9582. %@AS@%  void main( int argc, char *argv[] )
  9583. %@AS@%  {
  9584. %@AS@%      int     termstat, pid, c, tmp;
  9585. %@AS@%  
  9586. %@AS@%      srand( (unsigned)time( NULL ) );               /* Seed randomizer */
  9587. %@AS@%      /* If no arguments, this is the parent. */
  9588. %@AS@%      if( argc == 1 )
  9589. %@AS@%      {
  9590. %@AS@%          /* Spawn children in numeric order. */
  9591. %@AS@%          for( c = 0; c < 4; c++ )
  9592. %@AS@%              child[c].pid = spawnl( P_NOWAIT, argv[0], argv[0],
  9593. %@AS@%                                     child[c].name, NULL );%@AE@%%@NL@%
  9594. %@NL@%
  9595. %@AS@%  /* Wait for randomly specified child, and respond when done. */
  9596. %@AS@%          c = getrandom( 0, 3 );
  9597. %@AS@%          printf( "Come here, %s\n", child[c].name );
  9598. %@AS@%          cwait( &termstat, child[c].pid, WAIT_CHILD );
  9599. %@AS@%          printf( "Thank you, %s\n", child[c].name );
  9600. %@AS@%      }
  9601. %@AS@%  
  9602. %@AS@%      /* If there are arguments, this must be a child. */
  9603. %@AS@%      else
  9604. %@AS@%      {
  9605. %@AS@%          /* Delay for a period determined by process number. */
  9606. %@AS@%          DosSleep( (argv[1][0] - 'A' + 1) * 1000L );
  9607. %@AS@%          printf( "Hi, dad. It's %s.\n", argv[1] );
  9608. %@AS@%      }
  9609. %@AS@%  }%@AE@%%@NL@%
  9610. %@NL@%
  9611. %@NL@%
  9612. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9613. %@NL@%
  9614. %@AS@%  
  9615. %@AS@%  
  9616. %@AS@%  Come here, Carl
  9617. %@AS@%  Hi, dad. It's Ann.
  9618. %@AS@%  Hi, dad. It's Beth.
  9619. %@AS@%  Hi, dad. It's Carl.
  9620. %@AS@%  Thank you, Carl
  9621. %@AS@%  Hi, dad. It's Dave. %@AE@%%@NL@%
  9622. %@NL@%
  9623. %@NL@%
  9624. %@NL@%
  9625. %@NL@%
  9626. %@QR:dieeetomsbin@%%@QR:dmsbintoieee@%%@NL@%
  9627. %@2@%%@CR:C6A00530328 @%%@AB@%dieeetomsbin, dmsbintoieee%@AE@%%@EH@%%@NL@%
  9628. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9629. %@NL@%
  9630. %@NL@%
  9631. %@3@%%@AB@%Description %@CR:C6A00530329 @% %@CR:C6A00530330 @% %@CR:C6A00530331 @% %@CR:C6A00530332 @%%@AE@%%@EH@%%@NL@%
  9632. %@NL@%
  9633. Convert between IEEE double value and Microsoft (MS) binary double value.  %@NL@%
  9634. %@NL@%
  9635. %@AS@%  #include <math.h>%@AE@%%@NL@%
  9636. %@NL@%
  9637. %@AS@%  int dieeetomsbin( double *src8, double *dst8 );%@AE@%%@NL@%
  9638. %@NL@%
  9639. %@AS@%  int dmsbintoieee( double *src8, double *dst8 );%@AE@%%@NL@%
  9640. %@NL@%
  9641. %@AI@%src8%@AE@%                              Buffer containing value to convert
  9642.  
  9643. %@AI@%dst8%@AE@%                              Buffer to store converted value
  9644.  
  9645. %@NL@%
  9646. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9647. %@NL@%
  9648. The %@AB@%dieeetomsbin%@AE@% routine converts a double-precision number in IEEE
  9649. (Institute of Electrical and Electronic Engineers) format to Microsoft (MS)
  9650. binary format. The routine %@AB@%dmsbintoieee%@AE@% converts a double-precision number
  9651. in MS binary format to IEEE format.  %@NL@%
  9652. %@NL@%
  9653. These routines allow C programs (which store floating-point numbers in the
  9654. IEEE format) to use numeric data in random-access data files created with
  9655. those versions of Microsoft BASIC that store floating-point numbers in MS
  9656. binary format, and vice versa.  %@NL@%
  9657. %@NL@%
  9658. The argument %@AI@%src8%@AE@% is a pointer to the %@AB@%double%@AE@% value to be converted. The
  9659. result is stored at the location given by %@AI@%dst8%@AE@%.  %@NL@%
  9660. %@NL@%
  9661. These routines do not handle IEEE NANs ("not a number") and infinities. IEEE
  9662. denormals are treated as 0 in the conversions.  %@NL@%
  9663. %@NL@%
  9664. %@NL@%
  9665. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9666. %@NL@%
  9667. These functions return 0 if the conversion is successful and 1 if the
  9668. conversion causes an overflow.  %@NL@%
  9669. %@NL@%
  9670. %@NL@%
  9671. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9672. %@NL@%
  9673.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9674. %@NL@%
  9675. %@NL@%
  9676. %@NL@%
  9677. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9678. %@NL@%
  9679. %@AB@%fieeetomsbin%@AE@%, %@AB@%fmsbintoieee%@AE@%  %@NL@%
  9680. %@NL@%
  9681. %@NL@%
  9682. %@NL@%
  9683. %@NL@%
  9684. %@QR:difftime@%%@NL@%
  9685. %@2@%%@CR:C6A00540333 @%%@AB@%difftime%@AE@%%@EH@%%@NL@%
  9686. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9687. %@NL@%
  9688. %@NL@%
  9689. %@3@%%@AB@%Description%@CR:C6A00540334 @%%@CR:C6A00540335 @%%@CR:C6A00540336 @% %@CR:C6A00540337 @%%@CR:C6A00540338 @%%@AE@%%@EH@%%@NL@%
  9690. %@NL@%
  9691. Finds the difference between two times.  %@NL@%
  9692. %@NL@%
  9693. %@AB@%#include <time.h>%@AE@%                 Required only for function declarations
  9694.  
  9695. %@AS@%  double difftime( time_t timer1, time_t timer0 );%@AE@%%@NL@%
  9696. %@NL@%
  9697. %@AI@%timer0%@AE@%                            Beginning time
  9698.  
  9699. %@AI@%timer1%@AE@%                            Ending time
  9700.  
  9701. %@NL@%
  9702. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9703. %@NL@%
  9704. The %@AB@%difftime%@AE@% function computes the difference between the supplied time
  9705. values, %@AI@%timer0 %@AE@%and%@AI@% timer1%@AE@%.  %@NL@%
  9706. %@NL@%
  9707. %@NL@%
  9708. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9709. %@NL@%
  9710. The %@AB@%difftime%@AE@% function returns, in seconds, the elapsed time from %@AI@%timer0%@AE@% to
  9711. %@AI@%timer1%@AE@%. The value returned is a double-precision number.  %@NL@%
  9712. %@NL@%
  9713. %@NL@%
  9714. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9715. %@NL@%
  9716. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  9717. %@NL@%
  9718. %@NL@%
  9719. %@NL@%
  9720. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9721. %@NL@%
  9722. %@AB@%time%@AE@%  %@NL@%
  9723. %@NL@%
  9724. %@NL@%
  9725. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9726. %@NL@%
  9727. %@AS@%  /* DIFFTIME.C: This program calculates the amount of time needed to
  9728. %@AS@%   * do a floating-point multiply 50000 times.
  9729. %@AS@%   */
  9730. %@AS@%  
  9731. %@AS@%  #include <stdio.h>
  9732. %@AS@%  #include <stdlib.h>
  9733. %@AS@%  #include <time.h>
  9734. %@AS@%  
  9735. %@AS@%  void main()
  9736. %@AS@%  {
  9737. %@AS@%     time_t   start, finish;
  9738. %@AS@%     unsigned loop;
  9739. %@AS@%     double   result, elapsed_time;
  9740. %@AS@%  
  9741. %@AS@%     printf( "This program will do a floating point multiply 50000 times\n"
  9742. %@AS@%);
  9743. %@AS@%     printf( "Working...\n" );
  9744. %@AS@%  
  9745. %@AS@%     time( &start );
  9746. %@AS@%     for( loop = 0; loop < 50000L; loop++ )
  9747. %@AS@%        result = 3.63 * 5.27;
  9748. %@AS@%     time( &finish );%@AE@%%@NL@%
  9749. %@NL@%
  9750. %@AS@%  elapsed_time = difftime( finish, start );
  9751. %@AS@%     printf( "\nProgram takes %6.2f seconds.\n", elapsed_time );
  9752. %@AS@%  }%@AE@%%@NL@%
  9753. %@NL@%
  9754. %@NL@%
  9755. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9756. %@NL@%
  9757. %@AS@%  
  9758. %@AS@%  
  9759. %@AS@%  This program will do a floating point multiply 50000 times
  9760. %@AS@%  Working...
  9761. %@AS@%  
  9762. %@AS@%  Program takes   4.00 seconds. %@AE@%%@NL@%
  9763. %@NL@%
  9764. %@NL@%
  9765. %@NL@%
  9766. %@NL@%
  9767. %@QR:_displaycursor@%%@NL@%
  9768. %@2@%%@CR:C6A00550339 @%%@AB@%_displaycursor%@AE@%%@EH@%%@NL@%
  9769. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9770. %@NL@%
  9771. %@NL@%
  9772. %@3@%%@AB@%Description%@CR:C6A00550340 @%%@AE@%%@EH@%%@NL@%
  9773. %@NL@%
  9774. Sets the cursor toggle for graphics functions.  %@NL@%
  9775. %@NL@%
  9776. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  9777. %@NL@%
  9778. %@AS@%  short _far _displaycursor( short toggle );%@AE@%%@NL@%
  9779. %@NL@%
  9780. %@AI@%toggle%@AE@%                            Cursor state
  9781.  
  9782. %@NL@%
  9783. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9784. %@NL@%
  9785. Upon entry into each graphic routine, the screen cursor is turned off. The
  9786. %@AB@%_displaycursor%@AE@% function determines whether the cursor will be turned back on
  9787. when programs exit graphic routines. If %@AI@%toggle%@AE@% is set to %@AB@%_GCURSORON,%@AE@% the
  9788. cursor will be restored on exit. If %@AI@%toggle%@AE@% is set to %@AB@%_GCURSOROFF,%@AE@% the cursor
  9789. will be left off.  %@NL@%
  9790. %@NL@%
  9791. %@NL@%
  9792. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9793. %@NL@%
  9794. The function returns the previous value of %@AI@%toggle%@AE@%. There is no error return.
  9795. %@NL@%
  9796. %@NL@%
  9797. %@NL@%
  9798. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9799. %@NL@%
  9800.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9801. %@NL@%
  9802. %@NL@%
  9803. %@NL@%
  9804. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9805. %@NL@%
  9806. %@AB@%_gettextcursor%@AE@%, %@AB@%_settextcursor%@AE@%  %@NL@%
  9807. %@NL@%
  9808. %@NL@%
  9809. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9810. %@NL@%
  9811. %@AS@%  /* DISCURS.C: This program changes the cursor shape using _gettextcursor
  9812. %@AS@%   * and _settextcursor, and hides the cursor using _displaycursor.
  9813. %@AS@%   */
  9814. %@AS@%  
  9815. %@AS@%  #include <conio.h>
  9816. %@AS@%  #include <graph.h>
  9817. %@AS@%  
  9818. %@AS@%  void main()
  9819. %@AS@%  {
  9820. %@AS@%     short oldcursor;
  9821. %@AS@%     short newcursor = 0x007;        /* Full block cursor */
  9822. %@AS@%  
  9823. %@AS@%     /* Save old cursor shape and make sure cursor is on */
  9824. %@AS@%     oldcursor = _gettextcursor();
  9825. %@AS@%     _clearscreen( _GCLEARSCREEN );
  9826. %@AS@%     _displaycursor( _GCURSORON );
  9827. %@AS@%     _outtext( "\nOld cursor shape: " );
  9828. %@AS@%     getch();
  9829. %@AS@%  
  9830. %@AS@%     /* Change cursor shape */
  9831. %@AS@%     _outtext( "\nNew cursor shape: " );
  9832. %@AS@%     _settextcursor( newcursor );
  9833. %@AS@%     getch();%@AE@%%@NL@%
  9834. %@NL@%
  9835. %@AS@%  /* Restore original cursor shape */
  9836. %@AS@%     _outtext( "\n" );
  9837. %@AS@%     _settextcursor( oldcursor );
  9838. %@AS@%  }%@AE@%%@NL@%
  9839. %@NL@%
  9840. %@NL@%
  9841. %@NL@%
  9842. %@NL@%
  9843. %@QR:div@%%@NL@%
  9844. %@2@%%@CR:C6A00560341 @%%@AB@%div%@AE@%%@EH@%%@NL@%
  9845. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9846. %@NL@%
  9847. %@NL@%
  9848. %@3@%%@AB@%Description%@CR:C6A00560342 @%%@CR:C6A00560343 @%%@AE@%%@EH@%%@NL@%
  9849. %@NL@%
  9850. Computes the quotient and the remainder of two integer values.  %@NL@%
  9851. %@NL@%
  9852. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  9853. %@NL@%
  9854. %@AS@%  div_t div( int numer, int denom );%@AE@%%@NL@%
  9855. %@NL@%
  9856. %@AI@%numer%@AE@%                             Numerator
  9857.  
  9858. %@AI@%denom%@AE@%                             Denominator
  9859.  
  9860. %@NL@%
  9861. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9862. %@NL@%
  9863. The %@AB@%div%@AE@% function divides %@AI@%numer%@AE@% by %@AI@%denom%@AE@%, computing the quotient and the
  9864. remainder. The %@AB@%div_t%@AE@% structure contains the following elements:  %@NL@%
  9865. %@NL@%
  9866. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  9867. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9868. %@AB@%int quot%@AE@%                          Quotient
  9869.  
  9870. %@AB@%int rem%@AE@%                           Remainder
  9871.  
  9872. The sign of the quotient is the same as that of the mathematical quotient.
  9873. Its absolute value is the largest integer that is less than the absolute
  9874. value of the mathematical quotient. If the denominator is 0, the program
  9875. will terminate with an error message.  %@NL@%
  9876. %@NL@%
  9877. %@NL@%
  9878. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9879. %@NL@%
  9880. The %@AB@%div%@AE@% function returns a structure of type %@AB@%div_t%@AE@%, comprising both the
  9881. quotient and the remainder. The structure is defined in STDLIB.H.  %@NL@%
  9882. %@NL@%
  9883. %@NL@%
  9884. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9885. %@NL@%
  9886. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  9887. %@NL@%
  9888. %@NL@%
  9889. %@NL@%
  9890. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9891. %@NL@%
  9892. %@AB@%ldiv%@AE@%  %@NL@%
  9893. %@NL@%
  9894. %@NL@%
  9895. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9896. %@NL@%
  9897. %@AS@%  /* DIV.C: This example takes two integers as command-line arguments and
  9898. %@AS@%   * displays the results of the integer division. This program accepts
  9899. %@AS@%   * two arguments on the command line following the program name, then
  9900. %@AS@%   * calls div to divide the first argument by the second. Finally,
  9901. %@AS@%   * it prints the structure members quot and rem.
  9902. %@AS@%   */
  9903. %@AS@%  
  9904. %@AS@%  #include <stdlib.h>
  9905. %@AS@%  #include <stdio.h>
  9906. %@AS@%  #include <math.h>%@AE@%%@NL@%
  9907. %@NL@%
  9908. %@AS@%  void main( int argc, char *argv[] )
  9909. %@AS@%  {
  9910. %@AS@%     int x,y;
  9911. %@AS@%     div_t div_result;
  9912. %@AS@%  
  9913. %@AS@%     x = atoi( argv[1] );
  9914. %@AS@%     y = atoi( argv[2] );
  9915. %@AS@%  
  9916. %@AS@%     printf( "x is %d, y is %d\n", x, y );
  9917. %@AS@%     div_result = div( x, y );
  9918. %@AS@%     printf( "The quotient is %d, and the remainder is %d\n",
  9919. %@AS@%             div_result.quot, div_result.rem );
  9920. %@AS@%  }%@AE@%%@NL@%
  9921. %@NL@%
  9922. %@NL@%
  9923. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  9924. %@NL@%
  9925. %@AS@%  
  9926. %@AS@%  
  9927. %@AS@%  [C:\LIBREF] div 876 13
  9928. %@AS@%  x is 876, y is 13
  9929. %@AS@%  The quotient is 67, and the remainder is 5 %@AE@%%@NL@%
  9930. %@NL@%
  9931. %@NL@%
  9932. %@NL@%
  9933. %@NL@%
  9934. %@QR:_dos_allocmem@%%@NL@%
  9935. %@2@%%@CR:C6A00570344 @%%@AB@%_dos_allocmem%@AE@%%@EH@%%@NL@%
  9936. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  9937. %@NL@%
  9938. %@NL@%
  9939. %@3@%%@AB@%Description%@CR:C6A00570345 @% %@CR:C6A00570346 @%%@AE@%%@EH@%%@NL@%
  9940. %@NL@%
  9941. Allocates a block of memory, using DOS service 0x48.  %@NL@%
  9942. %@NL@%
  9943. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  9944. %@NL@%
  9945. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  9946. %@NL@%
  9947. %@AS@%  unsigned _dos_allocmem( unsigned size, unsigned *seg );%@AE@%%@NL@%
  9948. %@NL@%
  9949. %@AI@%size%@AE@%                              Block size to allocate
  9950.  
  9951. %@AI@%seg%@AE@%                               Return buffer for segment descriptor
  9952.  
  9953. %@NL@%
  9954. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  9955. %@NL@%
  9956. The %@AB@%_dos_allocmem%@AE@% function uses DOS service 0x48 to allocate a block of
  9957. memory %@AI@%size%@AE@% paragraphs long. (A paragraph is 16 bytes.) Allocated blocks are
  9958. always paragraph aligned. The segment descriptor for the initial segment of
  9959. the new block is returned in the word that %@AI@%seg%@AE@% points to. If the request
  9960. cannot be satisfied, the maximum possible size (in paragraphs) is returned
  9961. in this word instead.  %@NL@%
  9962. %@NL@%
  9963. %@NL@%
  9964. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  9965. %@NL@%
  9966. If successful, the %@AB@%_dos_allocmem%@AE@% returns 0. Otherwise, it returns the DOS
  9967. error code and sets %@AB@%errno%@AE@% to %@AB@%ENOMEM%@AE@%, indicating insufficient memory or
  9968. invalid arena (memory area) headers.  %@NL@%
  9969. %@NL@%
  9970. %@NL@%
  9971. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  9972. %@NL@%
  9973.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  9974. %@NL@%
  9975. %@NL@%
  9976. %@NL@%
  9977. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  9978. %@NL@%
  9979. %@AB@%alloca%@AE@%, %@AB@%calloc%@AE@% functions, %@AB@%_dos_freemem%@AE@%, %@AB@%_dos_setblock%@AE@%, %@AB@%halloc%@AE@%, %@AB@%malloc%@AE@%
  9980. functions  %@NL@%
  9981. %@NL@%
  9982. %@NL@%
  9983. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  9984. %@NL@%
  9985. %@AS@%  /* DALOCMEM.C: This program allocates 20 paragraphs of memory, increases
  9986. %@AS@%   * the allocation to 40 paragraphs, and then frees the memory space.
  9987. %@AS@%   */
  9988. %@AS@%  
  9989. %@AS@%  #include <dos.h>
  9990. %@AS@%  #include <stdio.h>
  9991. %@AS@%  
  9992. %@AS@%  void main()
  9993. %@AS@%  {
  9994. %@AS@%     unsigned segment;
  9995. %@AS@%     unsigned maxsize;%@AE@%%@NL@%
  9996. %@NL@%
  9997. %@AS@%  /* Allocate 20 paragraphs */
  9998. %@AS@%     if( _dos_allocmem( 20, &segment ) != 0 )
  9999. %@AS@%        printf( "allocation failed\n" );
  10000. %@AS@%     else
  10001. %@AS@%        printf( "allocation successful\n" );
  10002. %@AS@%  
  10003. %@AS@%     /* Increase allocation to 40 paragraphs */
  10004. %@AS@%     if( _dos_setblock( 40, segment, &maxsize ) != 0 )
  10005. %@AS@%        printf( "allocation increase failed\n" );
  10006. %@AS@%     else
  10007. %@AS@%        printf( "allocation increase successful\n" );
  10008. %@AS@%  
  10009. %@AS@%     /* free memory */
  10010. %@AS@%     if( _dos_freemem( segment ) != 0 )
  10011. %@AS@%        printf( "free memory failed\n" );
  10012. %@AS@%     else
  10013. %@AS@%        printf( "free memory successful\n" );
  10014. %@AS@%  }%@AE@%%@NL@%
  10015. %@NL@%
  10016. %@NL@%
  10017. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10018. %@NL@%
  10019. %@AS@%  
  10020. %@AS@%  
  10021. %@AS@%  allocation successful
  10022. %@AS@%  allocation increase successful
  10023. %@AS@%  free memory successful %@AE@%%@NL@%
  10024. %@NL@%
  10025. %@NL@%
  10026. %@NL@%
  10027. %@NL@%
  10028. %@QR:_dos_close@%%@NL@%
  10029. %@2@%%@CR:C6A00580347 @%%@AB@%_dos_close%@AE@%%@EH@%%@NL@%
  10030. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10031. %@NL@%
  10032. %@NL@%
  10033. %@3@%%@AB@%Description%@CR:C6A00580348 @% %@CR:C6A00580349 @%%@AE@%%@EH@%%@NL@%
  10034. %@NL@%
  10035. Closes a file using system call INT 0x3E.  %@NL@%
  10036. %@NL@%
  10037. %@AB@%#include <dos.h>%@AE@%                  
  10038.  
  10039. %@AB@%#include <errno.h>%@AE@%                
  10040.  
  10041. %@AS@%  unsigned _dos_close( int handle );%@AE@%%@NL@%
  10042. %@NL@%
  10043. %@AI@%handle%@AE@%                            Target file handle
  10044.  
  10045. %@NL@%
  10046. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10047. %@NL@%
  10048. The %@AB@%_dos_close%@AE@% function uses system call 0x3E to close the file indicated by
  10049. %@AI@%handle%@AE@%. The file's %@AI@%handle%@AE@% argument is returned by the call that created or
  10050. last opened the file.  %@NL@%
  10051. %@NL@%
  10052. %@NL@%
  10053. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10054. %@NL@%
  10055. The function returns 0 if successful. Otherwise, it returns the DOS error
  10056. code and sets %@AB@%errno%@AE@% to %@AB@%EBADF%@AE@%, indicating an invalid file handle.  %@NL@%
  10057. %@NL@%
  10058. Do not use the DOS interface I/O routines with the console, low-level, or
  10059. stream I/O routines.  %@NL@%
  10060. %@NL@%
  10061. %@NL@%
  10062. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10063. %@NL@%
  10064.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10065. %@NL@%
  10066. %@NL@%
  10067. %@NL@%
  10068. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10069. %@NL@%
  10070. %@AB@%close%@AE@%,%@AB@% creat%@AE@%, %@AB@% _dos_creat%@AE@% functions, %@AB@% _dos_open%@AE@%, %@AB@% _dos_read%@AE@%, %@AB@% _dos_write%@AE@%,
  10071. %@AB@%dup%@AE@%, %@AB@%open%@AE@%  %@NL@%
  10072. %@NL@%
  10073. %@NL@%
  10074. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10075. %@NL@%
  10076. %@AS@%  /* DOPEN.C: This program uses DOS I/O functions to open and close a file.
  10077. %@AS@%  */
  10078. %@AS@%  
  10079. %@AS@%  #include <fcntl.h>
  10080. %@AS@%  #include <stdio.h>
  10081. %@AS@%  #include <dos.h>
  10082. %@AS@%  
  10083. %@AS@%  void main()
  10084. %@AS@%  {
  10085. %@AS@%     int fh;
  10086. %@AS@%  
  10087. %@AS@%     /* Open file with _dos_open function */
  10088. %@AS@%     if( _dos_open( "data1", O_RDONLY, &fh ) != 0 )
  10089. %@AS@%        perror( "Open failed on input file\n" );
  10090. %@AS@%     else
  10091. %@AS@%        printf( "Open succeeded on input file\n" );%@AE@%%@NL@%
  10092. %@NL@%
  10093. %@AS@%  /* Close file with _dos_close function */
  10094. %@AS@%     if( _dos_close( fh ) != 0 )
  10095. %@AS@%        perror( "Close failed\n" );
  10096. %@AS@%     else
  10097. %@AS@%        printf( "File successfully closed\n" );
  10098. %@AS@%  }%@AE@%%@NL@%
  10099. %@NL@%
  10100. %@NL@%
  10101. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10102. %@NL@%
  10103. %@AS@%  
  10104. %@AS@%  
  10105. %@AS@%  Open succeeded on input file
  10106. %@AS@%  File successfully closed %@AE@%%@NL@%
  10107. %@NL@%
  10108. %@NL@%
  10109. %@NL@%
  10110. %@NL@%
  10111. %@QR:_dos_creat@%%@NL@%
  10112. %@2@%%@CR:C6A00590350 @%%@AB@%_dos_creat Functions%@AE@%%@EH@%%@NL@%
  10113. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10114. %@NL@%
  10115. %@NL@%
  10116. %@3@%%@AB@%Description%@CR:C6A00590351 @%%@CR:C6A00590352 @% %@CR:C6A00590353 @%%@AE@%%@EH@%%@NL@%
  10117. %@NL@%
  10118. Create a new file.  %@NL@%
  10119. %@NL@%
  10120. %@AB@%#include <dos.h>%@AE@%                  
  10121.  
  10122. %@AB@%#include <errno.h>%@AE@%                
  10123.  
  10124. %@AS@%  unsigned _dos_creat( char *filename, unsigned attrib, int *handle );%@AE@%%@NL@%
  10125. %@NL@%
  10126. %@AS@%  unsigned _dos_creatnew( char *filename, unsigned attrib, int *handle );%@AE@%%@NL@%
  10127. %@NL@%
  10128. %@AI@%filename%@AE@%                          File path name
  10129.  
  10130. %@AI@%attrib%@AE@%                            File attributes
  10131.  
  10132. %@AI@%handle%@AE@%                            Handle return buffer
  10133.  
  10134. %@NL@%
  10135. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10136. %@NL@%
  10137. The %@AB@%_dos_creat%@AE@% and %@AB@%_dos_creatnew%@AE@% routines create and open a new file named
  10138. %@AI@%filename%@AE@%; this new file has the access attributes specified in the %@AI@%attrib%@AE@%
  10139. argument. The new file's handle is copied into the integer location pointed
  10140. to by %@AI@%handle%@AE@%. The file is opened for both read and write access. If file
  10141. sharing is installed, the file is opened in compatibility mode.  %@NL@%
  10142. %@NL@%
  10143. The %@AB@%_dos_creat%@AE@% routine uses system call INT 0x3C, and the %@AB@%_dos_creatnew%@AE@%
  10144. routine uses system call INT 0x5B. If the file already exists, %@AB@%_dos_creat%@AE@%
  10145. erases its contents and leaves its attributes unchanged; however, the
  10146. %@AB@%_dos_creatnew%@AE@% routine fails if the file already exists.  %@NL@%
  10147. %@NL@%
  10148. %@NL@%
  10149. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10150. %@NL@%
  10151. If successful, both routines return 0. Otherwise, they return the DOS error
  10152. code and set %@AB@%errno%@AE@% to one of the following values:  %@NL@%
  10153. %@NL@%
  10154. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  10155. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10156. %@AB@%EACCES%@AE@%                            Access denied because the directory is 
  10157.                                   full or, for %@AB@%_dos_creat%@AE@% only, the file 
  10158.                                   exists and cannot be overwritten
  10159.  
  10160. %@AB@%EEXIST%@AE@%                            File already exists (%@AB@%_dos_creatnew%@AE@% only)
  10161.  
  10162. %@AB@%EMFILE%@AE@%                            Too many open file handles
  10163.  
  10164. %@AB@%ENOENT%@AE@%                            Path or file not found
  10165.  
  10166. %@NL@%
  10167. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10168. %@NL@%
  10169.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10170. %@NL@%
  10171. %@NL@%
  10172. %@NL@%
  10173. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10174. %@NL@%
  10175. %@AS@%  /* DCREAT.C: This program creates a file using the _dos_creat function.
  10176. %@AS@%  The
  10177. %@AS@%   * program cannot create a new file using the _dos_creatnew function
  10178. %@AS@%   * because it already exists.
  10179. %@AS@%   */
  10180. %@AS@%  
  10181. %@AS@%  #include <stdio.h>
  10182. %@AS@%  #include <stdlib.h>
  10183. %@AS@%  #include <dos.h>
  10184. %@AS@%  
  10185. %@AS@%  void main()
  10186. %@AS@%  {
  10187. %@AS@%     int fh1, fh2;
  10188. %@AS@%     int result;
  10189. %@AS@%  
  10190. %@AS@%     if( _dos_creat( "data", _A_NORMAL, &fh1 ) != 0 )
  10191. %@AS@%        printf( "Couldn't create data file\n" );
  10192. %@AS@%     else
  10193. %@AS@%     {
  10194. %@AS@%        printf( "Created data file.\n" );
  10195. %@AS@%  
  10196. %@AS@%        /* If _dos_creat is successful, the _dos_creatnew call
  10197. %@AS@%         * will fail since the file exists
  10198. %@AS@%         */
  10199. %@AS@%        if( _dos_creatnew( "data", _A_RDONLY, &fh2 ) != 0 )
  10200. %@AS@%           printf( "Couldn't create data file\n" );
  10201. %@AS@%        else
  10202. %@AS@%        {
  10203. %@AS@%           printf( "Created data file.\n" );
  10204. %@AS@%           _dos_close( fh2 );
  10205. %@AS@%        }
  10206. %@AS@%        _dos_close( fh1 );
  10207. %@AS@%     }
  10208. %@AS@%  }%@AE@%%@NL@%
  10209. %@NL@%
  10210. %@NL@%
  10211. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10212. %@NL@%
  10213. %@AS@%  
  10214. %@AS@%  
  10215. %@AS@%  Created data file.
  10216. %@AS@%  Couldn't create data file %@AE@%%@NL@%
  10217. %@NL@%
  10218. %@NL@%
  10219. %@NL@%
  10220. %@NL@%
  10221. %@QR:_dos_find@%%@NL@%
  10222. %@2@%%@CR:C6A00600354 @%%@AB@%_dos_find Functions%@AE@%%@EH@%%@NL@%
  10223. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10224. %@NL@%
  10225. %@NL@%
  10226. %@3@%%@AB@%Description%@CR:C6A00600355 @% %@CR:C6A00600356 @% %@CR:C6A00600357 @%%@AE@%%@EH@%%@NL@%
  10227. %@NL@%
  10228. Find the file with the specified attributes or find the next file with the
  10229. specified attributes.  %@NL@%
  10230. %@NL@%
  10231. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10232. %@NL@%
  10233. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  10234. %@NL@%
  10235. %@AS@%  unsigned _dos_findfirst( char *filename, unsigned attrib, struct find_t
  10236. %@AS@%  *fileinfo );%@AE@%%@NL@%
  10237. %@NL@%
  10238. %@AS@%  unsigned _dos_findnext( struct find_t *fileinfo );%@AE@%%@NL@%
  10239. %@NL@%
  10240. %@AI@%filename%@AE@%                          Target file name
  10241.  
  10242. %@AI@%attrib%@AE@%                            Target attributes
  10243.  
  10244. %@AI@%fileinfo%@AE@%                          File-information buffer
  10245.  
  10246. %@NL@%
  10247. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10248. %@NL@%
  10249. The %@AB@%_dos_findfirst%@AE@% routine uses system call INT 0x4E to return information
  10250. about the first instance of a file whose name and attributes match %@AI@%filename%@AE@%
  10251. and %@AI@%attrib%@AE@%.  %@NL@%
  10252. %@NL@%
  10253. The %@AI@%filename%@AE@% argument may use wildcards (%@AB@%*%@AE@% and %@AB@%?%@AE@%). The %@AI@%attrib%@AE@% argument can
  10254. be any of the following manifest constants:  %@NL@%
  10255. %@NL@%
  10256. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  10257. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10258. %@AB@%_A_ARCH%@AE@%                           Archive. Set whenever the file is 
  10259.                                   changed, and cleared by the DOS BACKUP 
  10260.                                   command.
  10261.  
  10262. %@AB@%_A_HIDDEN%@AE@%                         Hidden file. Cannot be found with the 
  10263.                                   DOS DIR command. Returns information 
  10264.                                   about normal files as well as about 
  10265.                                   files with this attribute.
  10266.  
  10267. %@AB@%_A_NORMAL%@AE@%                         Normal. File can be read or written 
  10268.                                   without restriction.
  10269.  
  10270. %@AB@%_A_RDONLY%@AE@%                         Read-only. File cannot be opened for 
  10271.                                   writing, and a file with the same name 
  10272.                                   cannot be created. Returns information 
  10273.                                   about normal files as well as about 
  10274.                                   files with this attribute.
  10275.  
  10276. %@AB@%_A_SUBDIR%@AE@%                         Subdirectory. Returns information about 
  10277.                                   normal files as well as about files with
  10278.                                   this attribute.
  10279.  
  10280. %@AB@%_A_SYSTEM%@AE@%                         System file. Cannot be found with the 
  10281.                                   DOS DIR command. Returns information 
  10282.                                   about normal files as well as about 
  10283.                                   files with this attribute.
  10284.  
  10285. %@AB@%_A_VOLID%@AE@%                          Volume ID. Only one file can have this 
  10286.                                   attribute, and it must be in the root 
  10287.                                   directory.
  10288.  
  10289. Multiple constants can be combined (with the OR operator), using the
  10290. vertical-bar ( | ) character.  %@NL@%
  10291. %@NL@%
  10292. If the %@AI@%attributes %@AE@%argument to either of these functions is %@AB@%_A_RDONLY%@AE@%,%@AB@%
  10293. %@AB@%%@AE@%_A_HIDDEN,%@AB@% _A_SYSTEM%@AE@%, or %@AB@%_A_SUBDIR%@AE@%, the function also returns any normal
  10294. attribute files that match the %@AI@%filename%@AE@% argument. That is, a normal file
  10295. does not have a read-only, hidden, system, or directory attribute.  %@NL@%
  10296. %@NL@%
  10297. Information is returned in a %@AB@%find_t%@AE@% structure, defined in DOS.H. The %@AB@%find_t%@AE@%
  10298. structure contains the following elements:  %@NL@%
  10299. %@NL@%
  10300. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  10301. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10302. %@AB@%char reserved[21]%@AE@%                 Reserved for use by DOS
  10303.  
  10304. %@AB@%char attrib%@AE@%                       Attribute byte for matched path
  10305.  
  10306. %@AB@%unsigned wr_time%@AE@%                  Time of last write to file
  10307.  
  10308. %@AB@%unsigned wr_date%@AE@%                  Date of last write to file
  10309.  
  10310. %@AB@%long size%@AE@%                         Length of file in bytes
  10311.  
  10312. %@AB@%char name[13]%@AE@%                     Null-terminated name of matched 
  10313.                                   file/directory, without
  10314.                                   the path
  10315.  
  10316. The formats for the %@AB@%wr_time%@AE@% and %@AB@%wr_date%@AE@% elements are in DOS format and are
  10317. not usable by any other C run-time function. The time format is shown below:
  10318. %@NL@%
  10319. %@NL@%
  10320. %@AB@%Bits%@AE@%                              %@AB@%Contents%@AE@%
  10321. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10322. 0 - 4                             Number of 2-second increments (0 - 29)
  10323.  
  10324. 5 -10                             Minutes (0 - 59)
  10325.  
  10326. 11-15                             Hours (0 - 23)
  10327.  
  10328. The date format is shown below:  %@NL@%
  10329. %@NL@%
  10330. %@AB@%Bits%@AE@%                              %@AB@%Contents%@AE@%
  10331. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10332. 0 - 4                             Day of month (1-31)
  10333.  
  10334. 5 - 8                             Month (1-12)
  10335.  
  10336. 9 -15                             Year (relative to 1980)
  10337.  
  10338. Do not alter the contents of the buffer between a call to %@AB@%_dos_findfirst%@AE@% and
  10339. a subsequent call to the %@AB@%_dos_findnext%@AE@% function. Also, the buffer should not
  10340. be altered between calls to %@AB@%_dos_findnext%@AE@%.  %@NL@%
  10341. %@NL@%
  10342. The %@AB@%_dos_findnext%@AE@% routine uses system call 0x4F to find the next name, if
  10343. any, that matches the %@AI@%filename%@AE@% and %@AI@%attrib%@AE@% arguments specified in a prior
  10344. call to %@AB@%_dos_findfirst%@AE@%. The %@AI@%fileinfo%@AE@% argument must point to a structure
  10345. initialized by a previous call to %@AB@%_dos_findfirst%@AE@%. The contents of the
  10346. structure will be altered as described above if a match is found.  %@NL@%
  10347. %@NL@%
  10348. %@NL@%
  10349. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10350. %@NL@%
  10351. If successful, both functions return 0. Otherwise, they return the DOS error
  10352. code and set %@AB@%errno%@AE@% to %@AB@%ENOENT%@AE@%, indicating that %@AI@% filename%@AE@% could not be
  10353. matched.  %@NL@%
  10354. %@NL@%
  10355. %@NL@%
  10356. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10357. %@NL@%
  10358.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10359. %@NL@%
  10360. %@NL@%
  10361. %@NL@%
  10362. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10363. %@NL@%
  10364. %@AS@%  /* DFIND.C: This program finds and prints all files in the current
  10365. %@AS@%  directory with
  10366. %@AS@%   * the .c extension.
  10367. %@AS@%   */
  10368. %@AS@%  
  10369. %@AS@%  #include <stdio.h>
  10370. %@AS@%  #include <dos.h>
  10371. %@AS@%  
  10372. %@AS@%  main()
  10373. %@AS@%  {
  10374. %@AS@%     struct find_t  c_file;
  10375. %@AS@%  
  10376. %@AS@%     /* find first .c file in current directory */
  10377. %@AS@%     _dos_findfirst( "*.c", _A_NORMAL, &c_file );
  10378. %@AS@%  
  10379. %@AS@%     printf( "Listing of .c files\n\n" );
  10380. %@AS@%     printf( "File: %s is %ld bytes\n", c_file.name, c_file.size );
  10381. %@AS@%  
  10382. %@AS@%     /* find the rest of the .c files */
  10383. %@AS@%     while( _dos_findnext( &c_file ) == 0 )
  10384. %@AS@%        printf( "File: %s is %ld bytes\n", c_file.name, c_file.size );
  10385. %@AS@%  }%@AE@%%@NL@%
  10386. %@NL@%
  10387. %@NL@%
  10388. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10389. %@NL@%
  10390. %@AS@%  
  10391. %@AS@%  
  10392. %@AS@%  Listing of .c files
  10393. %@AS@%  
  10394. %@AS@%  File: CHDIR.C is 524 bytes
  10395. %@AS@%  File: SIGFP.C is 2674 bytes
  10396. %@AS@%  File: MAX.C is 258 bytes
  10397. %@AS@%  File: CGETS.C is 577 bytes
  10398. %@AS@%  File: FWRITE.C is 1123 bytes %@AE@%%@NL@%
  10399. %@NL@%
  10400. %@NL@%
  10401. %@NL@%
  10402. %@NL@%
  10403. %@QR:_dos_freemem@%%@NL@%
  10404. %@2@%%@CR:C6A00610358 @%%@AB@%_dos_freemem%@AE@%%@EH@%%@NL@%
  10405. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10406. %@NL@%
  10407. %@NL@%
  10408. %@3@%%@AB@%Description%@CR:C6A00610359 @% %@CR:C6A00610360 @%%@AE@%%@EH@%%@NL@%
  10409. %@NL@%
  10410. Releases a block of memory (INT 0x49).  %@NL@%
  10411. %@NL@%
  10412. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10413. %@NL@%
  10414. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  10415. %@NL@%
  10416. %@AS@%  unsigned _dos_freemem( unsigned seg );%@AE@%%@NL@%
  10417. %@NL@%
  10418. %@AI@%seg%@AE@%                               Block to be released
  10419.  
  10420. %@NL@%
  10421. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10422. %@NL@%
  10423. The %@AB@%_dos_freemem%@AE@% function uses system call 0x49 to release a block of memory
  10424. previously allocated by %@AB@%_dos_allocmem%@AE@%. The %@AI@%seg%@AE@% argument is a value returned
  10425. by a previous call to %@AB@%_dos_allocmem%@AE@%. The freed memory may no longer be used
  10426. by the application program.  %@NL@%
  10427. %@NL@%
  10428. %@NL@%
  10429. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10430. %@NL@%
  10431. If successful, %@AB@%_dos_freemem%@AE@% returns 0. Otherwise, it returns the DOS error
  10432. code and sets %@AB@%errno%@AE@% to %@AB@%ENOMEM%@AE@%, indicating a bad segment value (one that does
  10433. not correspond to a segment returned by a previous %@AB@%_dos_allocmem%@AE@% call) or
  10434. invalid arena headers.  %@NL@%
  10435. %@NL@%
  10436. %@NL@%
  10437. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10438. %@NL@%
  10439.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10440. %@NL@%
  10441. %@NL@%
  10442. %@NL@%
  10443. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10444. %@NL@%
  10445. %@AB@%_dos_allocmem%@AE@%, %@AB@% _dos_setblock%@AE@%, %@AB@%free%@AE@% functions  %@NL@%
  10446. %@NL@%
  10447. %@NL@%
  10448. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10449. %@NL@%
  10450. %@AS@%  /* DALOCMEM.C: This program allocates 20 paragraphs of memory, increases
  10451. %@AS@%   * the allocation to 40 paragraphs, and then frees the memory space.
  10452. %@AS@%   */
  10453. %@AS@%  
  10454. %@AS@%  #include <dos.h>
  10455. %@AS@%  #include <stdio.h>
  10456. %@AS@%  
  10457. %@AS@%  void main()
  10458. %@AS@%  {
  10459. %@AS@%     unsigned segment;
  10460. %@AS@%     unsigned maxsize;
  10461. %@AS@%  
  10462. %@AS@%     /* Allocate 20 paragraphs */
  10463. %@AS@%     if( _dos_allocmem( 20, &segment ) != 0 )
  10464. %@AS@%        printf( "allocation failed\n" );
  10465. %@AS@%     else
  10466. %@AS@%        printf( "allocation successful\n" );%@AE@%%@NL@%
  10467. %@NL@%
  10468. %@AS@%  /* Increase allocation to 40 paragraphs */
  10469. %@AS@%     if( _dos_setblock( 40, segment, &maxsize ) != 0 )
  10470. %@AS@%        printf( "allocation increase failed\n" );
  10471. %@AS@%     else
  10472. %@AS@%        printf( "allocation increase successful\n" );
  10473. %@AS@%  
  10474. %@AS@%     /* Free memory */
  10475. %@AS@%     if( _dos_freemem( segment ) != 0 )
  10476. %@AS@%        printf( "free memory failed\n" );
  10477. %@AS@%     else
  10478. %@AS@%        printf( "free memory successful\n" );
  10479. %@AS@%  }%@AE@%%@NL@%
  10480. %@NL@%
  10481. %@NL@%
  10482. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10483. %@NL@%
  10484. %@AS@%  
  10485. %@AS@%  
  10486. %@AS@%  allocation successful
  10487. %@AS@%  allocation increase successful
  10488. %@AS@%  free memory successful %@AE@%%@NL@%
  10489. %@NL@%
  10490. %@NL@%
  10491. %@NL@%
  10492. %@NL@%
  10493. %@QR:_dos_getdate@%%@NL@%
  10494. %@2@%%@CR:C6A00620361 @%%@AB@%_dos_getdate%@AE@%%@EH@%%@NL@%
  10495. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10496. %@NL@%
  10497. %@NL@%
  10498. %@3@%%@AB@%Description%@CR:C6A00620362 @% %@CR:C6A00620363 @%%@AE@%%@EH@%%@NL@%
  10499. %@NL@%
  10500. Gets current system date using system call INT 0x2A.  %@NL@%
  10501. %@NL@%
  10502. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10503. %@NL@%
  10504. %@AS@%  void _dos_getdate( struct dosdate_t *date );%@AE@%%@NL@%
  10505. %@NL@%
  10506. %@AI@%date%@AE@%                              Current system date
  10507.  
  10508. %@NL@%
  10509. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10510. %@NL@%
  10511. The %@AB@%_dos_getdate%@AE@% routine uses system call 0x2A to obtain the current system
  10512. date. The date is returned in a %@AB@%dosdate_t%@AE@% structure, defined in DOS.H.  %@NL@%
  10513. %@NL@%
  10514. The %@AB@%dosdate_t%@AE@% structure contains the following elements:  %@NL@%
  10515. %@NL@%
  10516. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  10517. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10518. %@AB@%unsigned char day%@AE@%                 1-31
  10519.  
  10520. %@AB@%unsigned char month%@AE@%               1-12
  10521.  
  10522. %@AB@%unsigned int year%@AE@%                 1980 - 2099
  10523.  
  10524. %@AB@%unsigned char dayofweek%@AE@%           0 - 6 (0 = Sunday)
  10525.  
  10526. %@NL@%
  10527. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10528. %@NL@%
  10529. None.  %@NL@%
  10530. %@NL@%
  10531. %@NL@%
  10532. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10533. %@NL@%
  10534.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10535. %@NL@%
  10536. %@NL@%
  10537. %@NL@%
  10538. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10539. %@NL@%
  10540. %@AB@%_dos_gettime%@AE@%, %@AB@% _dos_setdate%@AE@%, %@AB@% _dos_settime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%mktime%@AE@%, %@AB@%
  10541. %@AB@%_strdate%@AE@%, %@AB@%_strtime%@AE@%, %@AB@%time%@AE@%  %@NL@%
  10542. %@NL@%
  10543. %@NL@%
  10544. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10545. %@NL@%
  10546. %@AS@%  /* DGTIME.C: This program gets and displays current date and time values.
  10547. %@AS@%  */
  10548. %@AS@%  
  10549. %@AS@%  #include <stdio.h>
  10550. %@AS@%  #include <dos.h>
  10551. %@AS@%  
  10552. %@AS@%  void main()
  10553. %@AS@%  {
  10554. %@AS@%     struct dosdate_t date;
  10555. %@AS@%     struct dostime_t time;%@AE@%%@NL@%
  10556. %@NL@%
  10557. %@AS@%  /* Get current date and time values */
  10558. %@AS@%  
  10559. %@AS@%     _dos_getdate( &date );
  10560. %@AS@%     _dos_gettime( &time );
  10561. %@AS@%  
  10562. %@AS@%     printf( "Today's date is %d-%d-%d\n", date.month, date.day, date.year
  10563. %@AS@%);
  10564. %@AS@%     printf( "The time is %02d:%02d\n", time.hour, time.minute );
  10565. %@AS@%  }%@AE@%%@NL@%
  10566. %@NL@%
  10567. %@NL@%
  10568. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10569. %@NL@%
  10570. %@AS@%  
  10571. %@AS@%  
  10572. %@AS@%  Today's date is 6-15-1989
  10573. %@AS@%  The time is 18:07 %@AE@%%@NL@%
  10574. %@NL@%
  10575. %@NL@%
  10576. %@NL@%
  10577. %@NL@%
  10578. %@QR:_dos_getdiskfree@%%@NL@%
  10579. %@2@%%@CR:C6A00630364 @%%@AB@%_dos_getdiskfree%@AE@%%@EH@%%@NL@%
  10580. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10581. %@NL@%
  10582. %@NL@%
  10583. %@3@%%@AB@%Description%@CR:C6A00630365 @% %@CR:C6A00630366 @%%@AE@%%@EH@%%@NL@%
  10584. %@NL@%
  10585. Gets disk information using system call INT 0x36.  %@NL@%
  10586. %@NL@%
  10587. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10588. %@NL@%
  10589. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  10590. %@NL@%
  10591. %@AS@%  unsigned _dos_getdiskfree( unsigned drive, struct diskfree_t *diskspace );%@AE@%%@NL@%
  10592. %@NL@%
  10593. %@AI@%drive%@AE@%                             Drive number (default is 0)
  10594.  
  10595. %@AI@%diskspace%@AE@%                         Buffer to hold disk information
  10596.  
  10597. %@NL@%
  10598. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10599. %@NL@%
  10600. The %@AB@%_dos_getdiskfree%@AE@% routine uses system call 0x36 to obtain information on
  10601. the disk drive specified by %@AI@%drive%@AE@%. The default drive is 0, drive A is 1,
  10602. drive B is 2, and so on. Information is returned in the %@AB@%diskfree_t%@AE@% structure
  10603. (defined in DOS.H) pointed to by %@AI@%diskspace%@AE@%.  %@NL@%
  10604. %@NL@%
  10605. The %@AB@%struct diskfree_t%@AE@% structure contains the following elements:  %@NL@%
  10606. %@NL@%
  10607. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  10608. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10609. %@AB@%unsigned total_clusters%@AE@%           Total clusters on disk
  10610.  
  10611. %@AB@%unsigned avail_clusters%@AE@%           Available clusters on disk
  10612.  
  10613. %@AB@%unsigned sectors_per_cluster%@AE@%      Sectors per cluster
  10614.  
  10615. %@AB@%unsigned bytes_per_sector%@AE@%         Bytes per sector
  10616.  
  10617. %@NL@%
  10618. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10619. %@NL@%
  10620. If successful, the function returns 0. Otherwise, it returns a nonzero value
  10621. and sets %@AB@%errno%@AE@% to %@AB@%EINVAL%@AE@%, indicating that an invalid drive was specified.  %@NL@%
  10622. %@NL@%
  10623. %@NL@%
  10624. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10625. %@NL@%
  10626.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10627. %@NL@%
  10628. %@NL@%
  10629. %@NL@%
  10630. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10631. %@NL@%
  10632. %@AB@%_dos_getdrive%@AE@%, %@AB@%_dos_setdrive%@AE@%  %@NL@%
  10633. %@NL@%
  10634. %@NL@%
  10635. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10636. %@NL@%
  10637. %@AS@%  /* DGDISKFR.C: This program displays information about the default disk
  10638. %@AS@%  drive. */
  10639. %@AS@%  
  10640. %@AS@%  #include <stdio.h>
  10641. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10642. %@NL@%
  10643. %@AS@%  main()
  10644. %@AS@%  {
  10645. %@AS@%     struct diskfree_t drive;
  10646. %@AS@%  
  10647. %@AS@%     /* Get information on default disk drive 0 */
  10648. %@AS@%  
  10649. %@AS@%     _dos_getdiskfree( 0, &drive );
  10650. %@AS@%     printf( "total clusters: %d\n", drive.total_clusters );
  10651. %@AS@%     printf( "available clusters: %d\n", drive.avail_clusters );
  10652. %@AS@%     printf( "sectors per cluster: %d\n", drive.sectors_per_cluster );
  10653. %@AS@%     printf( "bytes per sector: %d\n", drive.bytes_per_sector );
  10654. %@AS@%  }%@AE@%%@NL@%
  10655. %@NL@%
  10656. %@NL@%
  10657. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10658. %@NL@%
  10659. %@AS@%  
  10660. %@AS@%  
  10661. %@AS@%  total clusters: 9013
  10662. %@AS@%  available clusters: 6030
  10663. %@AS@%  sectors per cluster: 4
  10664. %@AS@%  bytes per sector: 512%@AE@%%@NL@%
  10665. %@NL@%
  10666. %@NL@%
  10667. %@NL@%
  10668. %@NL@%
  10669. %@QR:_dos_getdrive@%%@NL@%
  10670. %@2@%%@CR:C6A00640367 @%%@AB@%_dos_getdrive%@AE@%%@EH@%%@NL@%
  10671. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10672. %@NL@%
  10673. %@NL@%
  10674. %@3@%%@AB@%Description%@CR:C6A00640368 @% %@CR:C6A00640369 @%%@AE@%%@EH@%%@NL@%
  10675. %@NL@%
  10676. Gets the current disk drive using system call INT 0x19.  %@NL@%
  10677. %@NL@%
  10678. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10679. %@NL@%
  10680. %@AS@%  void _dos_getdrive( unsigned *drive );%@AE@%%@NL@%
  10681. %@NL@%
  10682. %@AI@%drive%@AE@%                             Current-drive return buffer
  10683.  
  10684. %@NL@%
  10685. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10686. %@NL@%
  10687. The %@AB@%_dos_getdrive%@AE@% routine uses system call 0x19 to obtain the current disk
  10688. drive. The current drive is returned in the word that %@AI@%drive%@AE@% points to: 1 =
  10689. drive A, 2 = drive B, and so on.  %@NL@%
  10690. %@NL@%
  10691. %@NL@%
  10692. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10693. %@NL@%
  10694. None.  %@NL@%
  10695. %@NL@%
  10696. %@NL@%
  10697. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10698. %@NL@%
  10699.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10700. %@NL@%
  10701. %@NL@%
  10702. %@NL@%
  10703. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10704. %@NL@%
  10705. %@AB@%_dos_getdiskfree%@AE@%, %@AB@% _dos_setdrive%@AE@%, %@AB@% _getdrive%@AE@%  %@NL@%
  10706. %@NL@%
  10707. %@NL@%
  10708. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10709. %@NL@%
  10710. %@AS@%  /* DGDRIVE.C: This program prints the letter of the current drive,
  10711. %@AS@%   * changes the default drive to A, then returns the number of disk drives.
  10712. %@AS@%   */
  10713. %@AS@%  
  10714. %@AS@%  #include <stdio.h>
  10715. %@AS@%  #include <dos.h>
  10716. %@AS@%  
  10717. %@AS@%  void main()
  10718. %@AS@%  {
  10719. %@AS@%     unsigned olddrive, newdrive;
  10720. %@AS@%     unsigned number_of_drives;
  10721. %@AS@%  
  10722. %@AS@%     /* Print current default drive information */
  10723. %@AS@%     _dos_getdrive( &olddrive );
  10724. %@AS@%     printf( "The current drive is: %c\n", 'A' + olddrive1 );
  10725. %@AS@%  
  10726. %@AS@%     /* Set default drive to be drive A */
  10727. %@AS@%     printf( "Changing default drive to A\n");
  10728. %@AS@%     _dos_setdrive( 1, &number_of_drives );
  10729. %@AS@%  
  10730. %@AS@%     /* Get new default drive information and total number of drives */
  10731. %@AS@%     _dos_getdrive( &newdrive );
  10732. %@AS@%     printf( "The current drive is: %c\n", 'A' + newdrive1 );
  10733. %@AS@%     printf( "Number of logical drives: %d\n", number_of_drives );%@AE@%%@NL@%
  10734. %@NL@%
  10735. %@AS@%  /* Restore default drive */
  10736. %@AS@%     _dos_setdrive( olddrive, &number_of_drives );
  10737. %@AS@%  }%@AE@%%@NL@%
  10738. %@NL@%
  10739. %@NL@%
  10740. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10741. %@NL@%
  10742. %@AS@%  
  10743. %@AS@%  
  10744. %@AS@%  The current drive is: C
  10745. %@AS@%  Changing default drive to A
  10746. %@AS@%  The current drive is: A
  10747. %@AS@%  Number of logical drives: 26 %@AE@%%@NL@%
  10748. %@NL@%
  10749. %@NL@%
  10750. %@NL@%
  10751. %@NL@%
  10752. %@QR:_dos_getfileattr@%%@NL@%
  10753. %@2@%%@CR:C6A00650370 @%%@AB@%_dos_getfileattr%@AE@%%@EH@%%@NL@%
  10754. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10755. %@NL@%
  10756. %@NL@%
  10757. %@3@%%@AB@%Description%@CR:C6A00650371 @% %@CR:C6A00650372 @%%@AE@%%@EH@%%@NL@%
  10758. %@NL@%
  10759. Gets the current attributes of a file or directory, using system call INT
  10760. 0x43.  %@NL@%
  10761. %@NL@%
  10762. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10763. %@NL@%
  10764. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  10765. %@NL@%
  10766. %@AS@%  unsigned _dos_getfileattr( char *pathname, unsigned *attrib );%@AE@%%@NL@%
  10767. %@NL@%
  10768. %@AI@%pathname%@AE@%                          Full path of target file/directory
  10769.  
  10770. %@AI@%attrib%@AE@%                            Word to store attributes in
  10771.  
  10772. %@NL@%
  10773. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10774. %@NL@%
  10775. The %@AB@%_dos_getfileattr%@AE@% routine uses system call 0x43 to obtain the current
  10776. attributes of the file or directory pointed to by %@AI@%pathname%@AE@% . The attributes
  10777. are copied to the low-order byte of the %@AI@%attrib%@AE@% word. Attributes are
  10778. represented by manifest constants, as described below:  %@NL@%
  10779. %@NL@%
  10780. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  10781. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10782. %@AB@%_A_ARCH%@AE@%                           Archive. Set whenever the file is 
  10783.                                   changed, or cleared by the DOS BACKUP 
  10784.                                   command.
  10785.  
  10786. %@AB@%_A_HIDDEN%@AE@%                         Hidden file. Cannot be found by a 
  10787.                                   directory search.
  10788.  
  10789. %@AB@%_A_NORMAL%@AE@%                         Normal. File can be read or written 
  10790.                                   without restriction.
  10791.  
  10792. %@AB@%_A_RDONLY%@AE@%                         Read-only. File cannot be opened for a 
  10793.                                   write, and a file with the same name 
  10794.                                   cannot be created.
  10795.  
  10796. %@AB@%_A_SUBDIR%@AE@%                         Subdirectory.
  10797.  
  10798. %@AB@%_A_SYSTEM%@AE@%                         System file. Cannot be found by a 
  10799.                                   directory search.
  10800.  
  10801. %@AB@%_A_VOLID%@AE@%                          Volume ID. Only one file can have this 
  10802.                                   attribute, and it must be in the root 
  10803.                                   directory.
  10804.  
  10805. %@AB@%  %@AE@%%@NL@%
  10806. %@NL@%
  10807. %@NL@%
  10808. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10809. %@NL@%
  10810. If successful, the function returns 0. Otherwise, it returns the DOS error
  10811. code and sets %@AB@%errno%@AE@% to %@AB@%ENOENT%@AE@%, indicating that the target file or directory
  10812. could be found.  %@NL@%
  10813. %@NL@%
  10814. %@NL@%
  10815. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10816. %@NL@%
  10817.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10818. %@NL@%
  10819. %@NL@%
  10820. %@NL@%
  10821. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10822. %@NL@%
  10823. %@AB@%access%@AE@%, %@AB@%chmod%@AE@%, %@AB@%_dos_setfileattr%@AE@%, %@AB@%umask%@AE@%  %@NL@%
  10824. %@NL@%
  10825. %@NL@%
  10826. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10827. %@NL@%
  10828. %@AS@%  /* DGFILEAT.C: This program creates a file with the specified attributes,
  10829. %@AS@%   * then prints this information before changing the file attributes back 
  10830. %@AS@%   * to normal.
  10831. %@AS@%   */
  10832. %@AS@%  
  10833. %@AS@%  #include <stdio.h>
  10834. %@AS@%  #include <dos.h>
  10835. %@AS@%  
  10836. %@AS@%  void main()
  10837. %@AS@%  {
  10838. %@AS@%     unsigned oldattrib, newattrib;
  10839. %@AS@%     int fh;
  10840. %@AS@%  
  10841. %@AS@%     /* Get and display file attribute */
  10842. %@AS@%     _dos_getfileattr( "DGFILEAT.C", &oldattrib );
  10843. %@AS@%     printf( "Attribute: 0x%.4x\n", oldattrib );
  10844. %@AS@%     if( ( oldattrib & _A_RDONLY ) != 0 )
  10845. %@AS@%        printf( "Read only file\n" );
  10846. %@AS@%     else
  10847. %@AS@%        printf( "Not a read only file.\n" );
  10848. %@AS@%  
  10849. %@AS@%     /* Reset file attribute to normal file */
  10850. %@AS@%     _dos_setfileattr( "DGFILEAT.C", _A_RDONLY );
  10851. %@AS@%     _dos_getfileattr( "DGFILEAT.C", &newattrib );
  10852. %@AS@%     printf( "Attribute: 0x%.4x\n", newattrib );
  10853. %@AS@%  
  10854. %@AS@%     /* Restore file attribute */
  10855. %@AS@%     _dos_setfileattr( "DGFILEAT.C", oldattrib );
  10856. %@AS@%     _dos_getfileattr( "DGFILEAT.C", &newattrib );
  10857. %@AS@%     printf( "Attribute: 0x%.4x\n", newattrib );
  10858. %@AS@%  }%@AE@%%@NL@%
  10859. %@NL@%
  10860. %@NL@%
  10861. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10862. %@NL@%
  10863. %@AS@%  
  10864. %@AS@%  
  10865. %@AS@%  Attribute: 0x0020
  10866. %@AS@%  Not a read only file.
  10867. %@AS@%  Attribute: 0x0001
  10868. %@AS@%  Attribute: 0x0020 %@AE@%%@NL@%
  10869. %@NL@%
  10870. %@NL@%
  10871. %@NL@%
  10872. %@NL@%
  10873. %@QR:_dos_getftime@%%@NL@%
  10874. %@2@%%@CR:C6A00660373 @%%@AB@%_dos_getftime%@AE@%%@EH@%%@NL@%
  10875. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10876. %@NL@%
  10877. %@NL@%
  10878. %@3@%%@AB@%Description%@CR:C6A00660374 @% %@CR:C6A00660375 @%%@AE@%%@EH@%%@NL@%
  10879. %@NL@%
  10880. Gets the date and time a file was last written, using system call INT 0x57.
  10881. %@NL@%
  10882. %@NL@%
  10883. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  10884. %@NL@%
  10885. %@AS@%  #include <errno.h>%@AE@%%@NL@%
  10886. %@NL@%
  10887. %@AS@%  unsigned _dos_getftime( int handle, unsigned *date, unsigned *time );%@AE@%%@NL@%
  10888. %@NL@%
  10889. %@AI@%handle%@AE@%                            Target file
  10890.  
  10891. %@AI@%date%@AE@%                              Date-return buffer
  10892.  
  10893. %@AI@%time%@AE@%                              Time-return buffer
  10894.  
  10895. %@NL@%
  10896. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  10897. %@NL@%
  10898. The %@AB@%_dos_getftime%@AE@% routine uses system call 0x57 to get the date and time
  10899. that the specified file was last written. The file must have been opened
  10900. with a call to %@AB@%_dos_open%@AE@% or %@AB@%_dos_creat%@AE@% prior to calling %@AB@%_dos_getftime%@AE@%. The
  10901. date and time are returned in the words pointed to by %@AI@%date%@AE@% and %@AI@%time%@AE@%. The
  10902. values appear in the DOS date and time format:  %@NL@%
  10903. %@NL@%
  10904. %@AB@%Time Bits%@AE@%                         %@AB@%Meaning%@AE@%
  10905. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10906. 0 - 4                             Number of 2-second increments (0 -29)
  10907.  
  10908. 5 -10                             Minutes (0 -59)
  10909.  
  10910. 11-15                             Hours (0 -23)
  10911.  
  10912. %@AB@%Date Bits%@AE@%                         %@AB@%Meaning%@AE@%
  10913. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  10914. 0 - 4                             Day (1-31)
  10915.  
  10916. 5 - 8                             Month (1-12)
  10917.  
  10918. 9 -15                             Year (1980 -2099)
  10919.  
  10920. %@NL@%
  10921. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  10922. %@NL@%
  10923. If successful, the function returns 0. Otherwise, it returns the DOS error
  10924. code and sets %@AB@%errno%@AE@% to%@AB@% EBADF%@AE@%, indicating that an invalid file handle was
  10925. passed.  %@NL@%
  10926. %@NL@%
  10927. %@NL@%
  10928. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  10929. %@NL@%
  10930.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  10931. %@NL@%
  10932. %@NL@%
  10933. %@NL@%
  10934. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  10935. %@NL@%
  10936. %@AB@%_dos_setftime%@AE@%, %@AB@%fstat%@AE@%, %@AB@%stat%@AE@%  %@NL@%
  10937. %@NL@%
  10938. %@NL@%
  10939. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  10940. %@NL@%
  10941. %@AS@%  /* DGFTIME.C: This program displays and modifies the date and time
  10942. %@AS@%   * fields of a file.
  10943. %@AS@%   */
  10944. %@AS@%  
  10945. %@AS@%  #include <fcntl.h>
  10946. %@AS@%  #include <stdio.h>
  10947. %@AS@%  #include <stdlib.h>
  10948. %@AS@%  #include <dos.h>
  10949. %@AS@%  
  10950. %@AS@%  void main()
  10951. %@AS@%  {
  10952. %@AS@%                                   /* FEDC BA98 7654 3210          */
  10953. %@AS@%     unsigned new_date = 0x184f;   /* 0001 1000 0100 1111  2/15/92 */
  10954. %@AS@%     unsigned new_time = 0x48e0;   /* 0100 1000 1110 0000  9:07 AM */
  10955. %@AS@%     unsigned old_date, old_time;
  10956. %@AS@%  
  10957. %@AS@%     int fh;
  10958. %@AS@%  
  10959. %@AS@%     /* Open file with _dos_open function */
  10960. %@AS@%     if( _dos_open( "dgftime.obj", O_RDONLY, &fh ) != 0 )
  10961. %@AS@%        exit( 1 );
  10962. %@AS@%  
  10963. %@AS@%     /* Get file date and time */
  10964. %@AS@%     _dos_getftime( fh, &old_date, &old_time );
  10965. %@AS@%     printf( "Old date field: 0x%.4x\n", old_date );
  10966. %@AS@%     printf( "Old time field: 0x%.4x\n", old_time );
  10967. %@AS@%     system( "dir dgftime.obj" );
  10968. %@AS@%  
  10969. %@AS@%     /* Modify file date and time */
  10970. %@AS@%     if( !_dos_setftime( fh, new_date, new_time ) )
  10971. %@AS@%     {
  10972. %@AS@%        _dos_getftime( fh, &new_date, &new_time );
  10973. %@AS@%        printf( "New date field: 0x%.4x\n", new_date );
  10974. %@AS@%        printf( "New time field: 0x%.4x\n", new_time );
  10975. %@AS@%        system( "dir dgftime.obj" );
  10976. %@AS@%  
  10977. %@AS@%        /* Restore date and time */
  10978. %@AS@%        _dos_setftime( fh, old_date, old_time );
  10979. %@AS@%     }
  10980. %@AS@%     _dos_close( fh );
  10981. %@AS@%  }%@AE@%%@NL@%
  10982. %@NL@%
  10983. %@NL@%
  10984. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  10985. %@NL@%
  10986. %@AS@%  
  10987. %@AS@%  
  10988. %@AS@%  Old date field: 0x12cf
  10989. %@AS@%  Old time field: 0x94bb
  10990. %@AS@%  
  10991. %@AS@%   Volume in drive C is OS2
  10992. %@AS@%   Directory of  C:\LIBREF
  10993. %@AS@%  
  10994. %@AS@%  DGFTIME  OBJ     3923   6-15-89   6:37p
  10995. %@AS@%          1 File(s)  13676544 bytes free
  10996. %@AS@%  
  10997. %@AS@%  New date field: 0x184f
  10998. %@AS@%  New time field: 0x48e0
  10999. %@AS@%  
  11000. %@AS@%   Volume in drive C is OS2
  11001. %@AS@%   Directory of  C:\LIBREF
  11002. %@AS@%  
  11003. %@AS@%  DGFTIME  OBJ     3923   2-15-92   9:07a
  11004. %@AS@%          1 File(s)  13676544 bytes free %@AE@%%@NL@%
  11005. %@NL@%
  11006. %@NL@%
  11007. %@NL@%
  11008. %@NL@%
  11009. %@QR:_dos_gettime@%%@NL@%
  11010. %@2@%%@CR:C6A00670376 @%%@AB@%_dos_gettime%@AE@%%@EH@%%@NL@%
  11011. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11012. %@NL@%
  11013. %@NL@%
  11014. %@3@%%@AB@%Description%@CR:C6A00670377 @% %@CR:C6A00670378 @%%@AE@%%@EH@%%@NL@%
  11015. %@NL@%
  11016. Gets the current system time, using system call INT 0x2C.  %@NL@%
  11017. %@NL@%
  11018. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11019. %@NL@%
  11020. %@AS@%  void _dos_gettime( struct dostime_t *time );%@AE@%%@NL@%
  11021. %@NL@%
  11022. %@AI@%time%@AE@%                              Current system time
  11023.  
  11024. %@NL@%
  11025. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11026. %@NL@%
  11027. The %@AB@%_dos_gettime%@AE@% routine uses system call 0x2C to obtain the current system
  11028. time. The time is returned in a %@AB@%dostime_t%@AE@% structure, defined in DOS.H.  %@NL@%
  11029. %@NL@%
  11030. The %@AB@%dostime_t%@AE@% structure contains the following elements:  %@NL@%
  11031. %@NL@%
  11032. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  11033. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11034. %@AB@%unsigned char hour%@AE@%                0 -23
  11035.  
  11036. %@AB@%unsigned char minute%@AE@%              0 -59
  11037.  
  11038. %@AB@%unsigned char second%@AE@%              0 -59
  11039.  
  11040. %@AB@%unsigned char hsecond%@AE@%             1/100 second; 0 -99
  11041.  
  11042. %@NL@%
  11043. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11044. %@NL@%
  11045. None.  %@NL@%
  11046. %@NL@%
  11047. %@NL@%
  11048. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11049. %@NL@%
  11050.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11051. %@NL@%
  11052. %@NL@%
  11053. %@NL@%
  11054. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11055. %@NL@%
  11056. %@AB@%_dos_getdate%@AE@%, %@AB@% _dos_setdate%@AE@%, %@AB@% _dos_settime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@% _strtime%@AE@%  %@NL@%
  11057. %@NL@%
  11058. %@NL@%
  11059. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11060. %@NL@%
  11061. %@AS@%  /* DGTIME.C: This program gets and displays current date and time values.
  11062. %@AS@%  */
  11063. %@AS@%  
  11064. %@AS@%  #include <stdio.h>
  11065. %@AS@%  #include <dos.h>
  11066. %@AS@%  
  11067. %@AS@%  void main()
  11068. %@AS@%  {
  11069. %@AS@%     struct dosdate_t date;
  11070. %@AS@%     struct dostime_t time;%@AE@%%@NL@%
  11071. %@NL@%
  11072. %@AS@%  /* Get current date and time values */
  11073. %@AS@%  
  11074. %@AS@%     _dos_getdate( &date );
  11075. %@AS@%     _dos_gettime( &time );
  11076. %@AS@%  
  11077. %@AS@%     printf( "Today's date is %d-%d-%d\n", date.month, date.day, date.year
  11078. %@AS@%);
  11079. %@AS@%     printf( "The time is %02d:%02d\n", time.hour, time.minute );
  11080. %@AS@%  }%@AE@%%@NL@%
  11081. %@NL@%
  11082. %@NL@%
  11083. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11084. %@NL@%
  11085. %@AS@%  
  11086. %@AS@%  
  11087. %@AS@%  Today's date is 6-15-1989
  11088. %@AS@%  The time is 18:07 %@AE@%%@NL@%
  11089. %@NL@%
  11090. %@NL@%
  11091. %@NL@%
  11092. %@NL@%
  11093. %@QR:_dos_getvect@%%@NL@%
  11094. %@2@%%@CR:C6A00680379 @%%@AB@%_dos_getvect%@AE@%%@EH@%%@NL@%
  11095. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11096. %@NL@%
  11097. %@NL@%
  11098. %@3@%%@AB@%Description%@CR:C6A00680380 @% %@CR:C6A00680381 @%%@AE@%%@EH@%%@NL@%
  11099. %@NL@%
  11100. Gets the current value of the interrupt vector, using system call INT 0x35.
  11101. %@NL@%
  11102. %@NL@%
  11103. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11104. %@NL@%
  11105. %@AS@%  void ( _interrupt _far *_dos_getvect( unsigned intnum))();%@AE@%%@NL@%
  11106. %@NL@%
  11107. %@AI@%intnum%@AE@%                            Target interrupt vector
  11108.  
  11109. %@NL@%
  11110. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11111. %@NL@%
  11112. The %@AB@%_dos_getvect%@AE@% routine uses system call INT 0x35 to get the current value
  11113. of the interrupt vector specified by %@AI@%intnum%@AE@%.  %@NL@%
  11114. %@NL@%
  11115. This routine is typically used in conjunction with the %@AB@%_dos_setvect%@AE@%
  11116. function. To replace an interrupt vector, first save the current vector of
  11117. the interrupt using %@AB@%_dos_getvect%@AE@%. Then set the vector to your own interrupt
  11118. routine with %@AB@%_dos_setvect%@AE@%. The saved vector can later be restored, if
  11119. necessary, using %@AB@%_dos_setvect%@AE@%. The user-defined routine may also need the
  11120. original vector in order to call that vector or chain to it with
  11121. %@AB@%_chain_intr%@AE@%.  %@NL@%
  11122. %@NL@%
  11123. %@NL@%
  11124. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11125. %@NL@%
  11126. The function returns a far pointer for the %@AI@%intnum%@AE@% interrupt to the current
  11127. handler, if there is one.  %@NL@%
  11128. %@NL@%
  11129. %@NL@%
  11130. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11131. %@NL@%
  11132.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11133. %@NL@%
  11134. %@NL@%
  11135. %@NL@%
  11136. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11137. %@NL@%
  11138. %@AB@%_chain_intr%@AE@%, %@AB@% _dos_keep%@AE@%, %@AB@% _dos_setvect%@AE@%  %@NL@%
  11139. %@NL@%
  11140. %@NL@%
  11141. %@NL@%
  11142. %@NL@%
  11143. %@QR:_dos_keep@%%@NL@%
  11144. %@2@%%@CR:C6A00690382 @%%@AB@%_dos_keep%@AE@%%@EH@%%@NL@%
  11145. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11146. %@NL@%
  11147. %@NL@%
  11148. %@3@%%@AB@%Description%@CR:C6A00690383 @% %@CR:C6A00690384 @%%@AE@%%@EH@%%@NL@%
  11149. %@NL@%
  11150. Installs TSR (terminate-and-stay-resident) programs in memory, using system
  11151. call INT 0x31.  %@NL@%
  11152. %@NL@%
  11153. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11154. %@NL@%
  11155. %@AS@%  void _dos_keep( unsigned retcode, unsigned memsize );%@AE@%%@NL@%
  11156. %@NL@%
  11157. %@AI@%retcode%@AE@%                           Exit status code
  11158.  
  11159. %@AI@%memsize%@AE@%                           Allocated resident memory (in 16-byte 
  11160.                                   paragraphs)
  11161.  
  11162. %@NL@%
  11163. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11164. %@NL@%
  11165. The %@AB@%_dos_keep%@AE@% routine installs TSRs (terminate-and-stay-resident programs)
  11166. in memory, using system call INT 0x31.  %@NL@%
  11167. %@NL@%
  11168. The routine first exits the calling process, leaving it in memory. It then
  11169. returns the low-order byte of %@AI@%retcode%@AE@% to the parent of the calling process.
  11170. Before returning execution to the parent process, %@AB@%_dos_keep%@AE@% sets the
  11171. allocated memory for the now-resident process to %@AI@%memsize%@AE@% 16-byte paragraphs.
  11172. Any excess memory is returned to the system.  %@NL@%
  11173. %@NL@%
  11174. The %@AB@%_dos_keep%@AE@% function calls the same internal routines called by %@AB@%exit%@AE@%. It
  11175. therefore takes the following actions:  %@NL@%
  11176. %@NL@%
  11177. %@NL@%
  11178.   ■   Calls %@AB@%atexit%@AE@% and %@AB@%onexit%@AE@% if defined.%@NL@%
  11179. %@NL@%
  11180.   ■   Flushes all file buffers.%@NL@%
  11181. %@NL@%
  11182.   ■   Restores interrupt vectors replaced by the C start-up code. The
  11183.       primary one is interrupt 0 (divide by zero). If the emulator math
  11184.       library is used and there is no coprocessor, interrupts 0x34 through
  11185.       0x3D are restored. If there is a coprocessor, interrupt 2 is restored.%@NL@%
  11186. %@NL@%
  11187. %@NL@%
  11188. The %@AB@%_dos_keep%@AE@% function does not automatically close files; you should do
  11189. this specifically unless you want files opened by the TSR installation code
  11190. to remain open for the TSR.  %@NL@%
  11191. %@NL@%
  11192. Do not use the emulator math library in TSRs unless you are familiar with
  11193. the C start-up code and the coprocessor. Use the alternate math package (not
  11194. supplied with Microsoft QuickC) if the TSR must do floating-point math.  %@NL@%
  11195. %@NL@%
  11196. Do not run programs that use %@AB@%_dos_keep%@AE@% from inside the Microsoft
  11197. Programmer's WorkBench environment, since doing so causes subsequent memory
  11198. problems. The %@AB@%_dos_keep%@AE@% function terminates the program when executed in the
  11199. Programmer's WorkBench environment.  %@NL@%
  11200. %@NL@%
  11201. %@NL@%
  11202. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11203. %@NL@%
  11204. None.  %@NL@%
  11205. %@NL@%
  11206. %@NL@%
  11207. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11208. %@NL@%
  11209.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11210. %@NL@%
  11211. %@NL@%
  11212. %@NL@%
  11213. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11214. %@NL@%
  11215. %@AB@%_cexit%@AE@%,%@AB@%  _chain_intr%@AE@%, %@AB@% _dos_getvect%@AE@%, %@AB@% _dos_setvect%@AE@%, %@AB@% _exit %@AE@%  %@NL@%
  11216. %@NL@%
  11217. %@NL@%
  11218. %@NL@%
  11219. %@NL@%
  11220. %@QR:_dos_open@%%@NL@%
  11221. %@2@%%@CR:C6A00700385 @%%@AB@%_dos_open%@AE@%%@EH@%%@NL@%
  11222. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11223. %@NL@%
  11224. %@NL@%
  11225. %@3@%%@AB@%Description%@CR:C6A00700386 @% %@CR:C6A00700387 @%%@AE@%%@EH@%%@NL@%
  11226. %@NL@%
  11227. Opens a file, using system call INT 0x3D.  %@NL@%
  11228. %@NL@%
  11229. %@AB@%#include <dos.h>%@AE@%                  
  11230.  
  11231. %@AB@%#include <errno.h>%@AE@%                
  11232.  
  11233. %@AB@%#include <fcntl.h>%@AE@%                Access mode constants
  11234.  
  11235. %@AB@%#include <share.h>%@AE@%                Sharing mode constants
  11236.  
  11237. %@AS@%  unsigned _dos_open( char *filename, unsigned mode, int *handle );%@AE@%%@NL@%
  11238. %@NL@%
  11239. %@AI@%filename%@AE@%                          Path to an existing file
  11240.  
  11241. %@AI@%mode%@AE@%                              Permissions
  11242.  
  11243. %@AI@%handle%@AE@%                            Pointer to integer
  11244.  
  11245. %@NL@%
  11246. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11247. %@NL@%
  11248. The %@AB@%_dos_open%@AE@% routine uses system call INT 0x3D to open the existing file
  11249. pointed to by %@AI@%filename%@AE@%. The handle for the opened file is copied into the
  11250. integer pointed to by %@AI@%handle%@AE@%. The %@AI@%mode%@AE@% argument specifies the file's access,
  11251. sharing, and inheritance modes by combining (with the OR operator) manifest
  11252. constants from the three groups shown below. At most, one access mode and
  11253. one sharing mode can be specified at a time.  %@NL@%
  11254. %@NL@%
  11255. %@TH:  21   950 02 14 33 33 @%
  11256. %@AB@%Constant%@AE@%      %@AB@%Mode%@AE@%                             %@AB@%Meaning%@AE@%
  11257. %@AB@%────────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11258. %@AB@%O_RDONLY%@AE@%      Access                           Read-only
  11259.  
  11260. %@AB@%O_WRONLY%@AE@%      Access                           Write-only
  11261.  
  11262. %@AB@%O_RDWR%@AE@%        Access                           Both read and write
  11263.  
  11264. %@AB@%SH_COMPAT%@AE@%     Sharing                          Compatibility
  11265.  
  11266. %@AB@%SH_DENYRW%@AE@%     Sharing                          Deny reading and writing
  11267.  
  11268. %@AB@%SH_DENYWR%@AE@%     Sharing                          Deny writing
  11269.  
  11270. %@AB@%SH_DENYRD%@AE@%     Sharing                          Deny reading
  11271.  
  11272. %@AB@%SH_DENYNO%@AE@%     Sharing                          Deny neither
  11273.  
  11274. %@AB@%O_NOINHERIT%@AE@%   Inheritance by the child         File is not inherited
  11275.               process                          
  11276.  
  11277. %@TE:  21   950 02 14 33 33 @%
  11278.  
  11279. Do not use the DOS interface I/O routines in conjunction with the console,
  11280. low-level, or stream I/O routines.  %@NL@%
  11281. %@NL@%
  11282. %@NL@%
  11283. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11284. %@NL@%
  11285. If successful, the function returns 0. Otherwise, it returns the DOS error
  11286. code and sets %@AB@%errno%@AE@% to one of the following manifest constants:  %@NL@%
  11287. %@NL@%
  11288. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  11289. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11290. %@AB@%EACCES%@AE@%                            Access denied (possible reasons include 
  11291.                                   specifying a directory or volume ID for %@AI@%%@AE@%
  11292.                                   %@AI@%filename%@AE@%, or opening a read-only file 
  11293.                                   for write access)
  11294.  
  11295. %@AB@%EINVAL%@AE@%                            Sharing mode specified when file sharing
  11296.                                   not installed, or
  11297.                                   access-mode value is invalid
  11298.  
  11299. %@AB@%%@AE@%%@AB@%EMFILE%@AE@%                            Too many open file handles
  11300.  
  11301. %@AB@%%@AE@%%@AB@%ENOENT%@AE@%                            Path or file not found
  11302.  
  11303. %@NL@%
  11304. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11305. %@NL@%
  11306.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11307. %@NL@%
  11308. %@NL@%
  11309. %@NL@%
  11310. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11311. %@NL@%
  11312. %@AB@%_dos_close%@AE@%, %@AB@% _dos_read%@AE@%,  %@AB@%_dos_write%@AE@%  %@NL@%
  11313. %@NL@%
  11314. %@NL@%
  11315. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11316. %@NL@%
  11317. %@AS@%  /* DOPEN.C: This program uses DOS I/O functions to open and close a file.
  11318. %@AS@%  */
  11319. %@AS@%  
  11320. %@AS@%  #include <fcntl.h>
  11321. %@AS@%  #include <stdio.h>
  11322. %@AS@%  #include <dos.h>
  11323. %@AS@%  
  11324. %@AS@%  void main()
  11325. %@AS@%  {
  11326. %@AS@%     int fh;
  11327. %@AS@%  
  11328. %@AS@%     /* Open file with _dos_open function */
  11329. %@AS@%     if( _dos_open( "data1", O_RDONLY, &fh ) != 0 )
  11330. %@AS@%        perror( "Open failed on input file\n" );
  11331. %@AS@%     else
  11332. %@AS@%        printf( "Open succeeded on input file\n" );
  11333. %@AS@%  
  11334. %@AS@%     /* Close file with _dos_close function */
  11335. %@AS@%     if( _dos_close( fh ) != 0 )
  11336. %@AS@%        perror( "Close failed\n" );
  11337. %@AS@%     else
  11338. %@AS@%        printf( "File successfully closed\n" );
  11339. %@AS@%  }%@AE@%%@NL@%
  11340. %@NL@%
  11341. %@NL@%
  11342. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11343. %@NL@%
  11344. %@AS@%  
  11345. %@AS@%  
  11346. %@AS@%  Open succeeded on input file
  11347. %@AS@%  File successfully closed %@AE@%%@NL@%
  11348. %@NL@%
  11349. %@NL@%
  11350. %@NL@%
  11351. %@NL@%
  11352. %@QR:_dos_read@%%@NL@%
  11353. %@2@%%@CR:C6A00710388 @%%@AB@%_dos_read%@AE@%%@EH@%%@NL@%
  11354. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11355. %@NL@%
  11356. %@NL@%
  11357. %@3@%%@AB@%Description%@CR:C6A00710389 @% %@CR:C6A00710390 @%%@AE@%%@EH@%%@NL@%
  11358. %@NL@%
  11359. Reads data from a file, using system call INT 0x3F.  %@NL@%
  11360. %@NL@%
  11361. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11362. %@NL@%
  11363. %@AS@%  unsigned _dos_read( int handle, void _far *buffer, unsigned count, 
  11364. %@AS@%  unsigned *numread );%@AE@%%@NL@%
  11365. %@NL@%
  11366. %@AI@%handle%@AE@%                            File to read
  11367.  
  11368. %@AI@%buffer%@AE@%                            Buffer to write to
  11369.  
  11370. %@AI@%count%@AE@%                             Number of bytes to read
  11371.  
  11372. %@AI@%numread%@AE@%                           Number of bytes actually read
  11373.  
  11374. %@NL@%
  11375. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11376. %@NL@%
  11377. The %@AB@%_dos_read%@AE@% routine uses system call INT 0x3F to read %@AI@%count%@AE@% bytes of data
  11378. from the file specified by %@AI@%handle%@AE@%. The routine then copies the data to the
  11379. buffer pointed to by %@AI@%buffer%@AE@%. The integer pointed to by %@AI@%numread%@AE@% will show the
  11380. number of bytes actually read, which may be less than the number requested
  11381. in %@AI@%count%@AE@%. If the number of bytes actually read is 0, it means the routine
  11382. tried to read at end-of-file.  %@NL@%
  11383. %@NL@%
  11384. Do not use the DOS interface I/O routines in conjunction with the console,
  11385. low-level, or stream I/O routines.  %@NL@%
  11386. %@NL@%
  11387. %@NL@%
  11388. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11389. %@NL@%
  11390. If successful, the function returns 0. Otherwise, it returns the DOS error
  11391. code and sets %@AB@%errno%@AE@% to one of the following constants:  %@NL@%
  11392. %@NL@%
  11393. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  11394. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11395. %@AB@%EACCES%@AE@%                            Access denied (%@AI@%handle%@AE@% is not open for 
  11396.                                   read access)
  11397.  
  11398. %@AB@%EBADF%@AE@%                             File handle is invalid
  11399.  
  11400. %@NL@%
  11401. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11402. %@NL@%
  11403.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11404. %@NL@%
  11405. %@NL@%
  11406. %@NL@%
  11407. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11408. %@NL@%
  11409. %@AB@%_dos_close%@AE@%, %@AB@% _dos_open%@AE@%, %@AB@% _dos_write%@AE@%, %@AB@%read%@AE@%  %@NL@%
  11410. %@NL@%
  11411. %@NL@%
  11412. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11413. %@NL@%
  11414. %@AS@%  /* DREAD.C: This program uses the DOS I/O operations to read the contents
  11415. %@AS@%   * of a file.
  11416. %@AS@%   */%@AE@%%@NL@%
  11417. %@NL@%
  11418. %@AS@%  #include <fcntl.h>
  11419. %@AS@%  #include <stdlib.h>
  11420. %@AS@%  #include <stdio.h>
  11421. %@AS@%  #include <dos.h>
  11422. %@AS@%  
  11423. %@AS@%  void main()
  11424. %@AS@%  {
  11425. %@AS@%     int fh;
  11426. %@AS@%     char buffer[50];
  11427. %@AS@%     unsigned number_read;
  11428. %@AS@%  
  11429. %@AS@%     /* Open file with _dos_open function */
  11430. %@AS@%     if( _dos_open( "dread.c", O_RDONLY, &fh ) != 0 )
  11431. %@AS@%        perror( "Open failed on input file\n" );
  11432. %@AS@%     else
  11433. %@AS@%        printf( "Open succeeded on input file\n" );
  11434. %@AS@%  
  11435. %@AS@%     /* Read data with _dos_read function */
  11436. %@AS@%     _dos_read( fh, buffer, 50, &number_read );
  11437. %@AS@%     printf( "First 40 characters are: %.40s\n\n", buffer );
  11438. %@AS@%  
  11439. %@AS@%     /* Close file with _dos_close function */
  11440. %@AS@%     _dos_close( fh );
  11441. %@AS@%  }%@AE@%%@NL@%
  11442. %@NL@%
  11443. %@NL@%
  11444. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11445. %@NL@%
  11446. %@AS@%  
  11447. %@AS@%  
  11448. %@AS@%  Open succeeded on input file
  11449. %@AS@%  First 40 characters are: /* DREAD.C: This program uses the DOS I/ %@AE@%%@NL@%
  11450. %@NL@%
  11451. %@NL@%
  11452. %@NL@%
  11453. %@NL@%
  11454. %@QR:_dos_setblock@%%@NL@%
  11455. %@2@%%@CR:C6A00720391 @%%@AB@%_dos_setblock%@AE@%%@EH@%%@NL@%
  11456. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11457. %@NL@%
  11458. %@NL@%
  11459. %@3@%%@AB@%Description%@CR:C6A00720392 @% %@CR:C6A00720393 @%%@AE@%%@EH@%%@NL@%
  11460. %@NL@%
  11461. Changes the size of a memory segment, using system call INT 0x4A.  %@NL@%
  11462. %@NL@%
  11463. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11464. %@NL@%
  11465. %@AS@%  unsigned _dos_setblock( unsigned size, unsigned seg, unsigned *maxsize );%@AE@%%@NL@%
  11466. %@NL@%
  11467. %@AI@%size%@AE@%                              New segment size
  11468.  
  11469. %@AI@%seg%@AE@%                               Target segment
  11470.  
  11471. %@AI@%maxsize%@AE@%                           Maximum-size buffer
  11472.  
  11473. %@NL@%
  11474. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11475. %@NL@%
  11476. The %@AB@%_dos_setblock%@AE@% routine uses system call INT 0x4A to change the size of
  11477. %@AI@%seg%@AE@%, previously allocated by %@AB@%_dos_allocmem%@AE@%, to %@AI@%size%@AE@% paragraphs. If the
  11478. request cannot be satisfied, the maximum possible segment size is copied to
  11479. the buffer pointed to by %@AI@%maxsize%@AE@%.  %@NL@%
  11480. %@NL@%
  11481. %@NL@%
  11482. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11483. %@NL@%
  11484. The function returns 0 if successful. If the call fails, it returns the DOS
  11485. error code and sets %@AB@%errno%@AE@% to %@AB@%ENOMEM%@AE@%, indicating a bad segment value was
  11486. passed. A bad segment value is one that does not correspond to a segment
  11487. returned from a previous %@AB@%_dos_allocmem%@AE@% call, or one that contains invalid
  11488. arena headers.  %@NL@%
  11489. %@NL@%
  11490. %@NL@%
  11491. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11492. %@NL@%
  11493.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11494. %@NL@%
  11495. %@NL@%
  11496. %@NL@%
  11497. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11498. %@NL@%
  11499. %@AB@%_dos_allocmem%@AE@%, %@AB@% _dos_freemem%@AE@%, %@AB@%realloc%@AE@% functions  %@NL@%
  11500. %@NL@%
  11501. %@NL@%
  11502. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11503. %@NL@%
  11504. %@AS@%  /* DALOCMEM.C: This program allocates 20 paragraphs of memory, increases
  11505. %@AS@%   * the allocation to 40 paragraphs, and then frees the memory space.
  11506. %@AS@%   */
  11507. %@AS@%  
  11508. %@AS@%  #include <dos.h>
  11509. %@AS@%  #include <stdio.h>
  11510. %@AS@%  
  11511. %@AS@%  void main()
  11512. %@AS@%  {
  11513. %@AS@%     unsigned segment;
  11514. %@AS@%     unsigned maxsize;%@AE@%%@NL@%
  11515. %@NL@%
  11516. %@AS@%  /* Allocate 20 paragraphs */
  11517. %@AS@%     if( _dos_allocmem( 20, &segment ) != 0 )
  11518. %@AS@%        printf( "allocation failed\n" );
  11519. %@AS@%     else
  11520. %@AS@%        printf( "allocation successful\n" );
  11521. %@AS@%  
  11522. %@AS@%     /* Increase allocation to 40 paragraphs */
  11523. %@AS@%     if( _dos_setblock( 40, segment, &maxsize ) != 0 )
  11524. %@AS@%        printf( "allocation increase failed\n" );
  11525. %@AS@%     else
  11526. %@AS@%        printf( "allocation increase successful\n" );
  11527. %@AS@%  
  11528. %@AS@%     /* Free memory */
  11529. %@AS@%     if( _dos_freemem( segment ) != 0 )
  11530. %@AS@%        printf( "free memory failed\n" );
  11531. %@AS@%     else
  11532. %@AS@%        printf( "free memory successful\n" );
  11533. %@AS@%  }%@AE@%%@NL@%
  11534. %@NL@%
  11535. %@NL@%
  11536. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11537. %@NL@%
  11538. %@AS@%  
  11539. %@AS@%  
  11540. %@AS@%  allocation successful
  11541. %@AS@%  allocation increase successful
  11542. %@AS@%  free memory successful %@AE@%%@NL@%
  11543. %@NL@%
  11544. %@NL@%
  11545. %@NL@%
  11546. %@NL@%
  11547. %@QR:_dos_setdate@%%@NL@%
  11548. %@2@%%@CR:C6A00730394 @%%@AB@%_dos_setdate%@AE@%%@EH@%%@NL@%
  11549. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11550. %@NL@%
  11551. %@NL@%
  11552. %@3@%%@AB@%Description%@CR:C6A00730395 @% %@CR:C6A00730396 @%%@AE@%%@EH@%%@NL@%
  11553. %@NL@%
  11554. Sets the current system date, using system call INT 0x2B.  %@NL@%
  11555. %@NL@%
  11556. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11557. %@NL@%
  11558. %@AS@%  unsigned _dos_setdate( struct dosdate_t *date );%@AE@%%@NL@%
  11559. %@NL@%
  11560. %@AI@%date%@AE@%                              New system date
  11561.  
  11562. %@NL@%
  11563. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11564. %@NL@%
  11565. The %@AB@%_dos_setdate%@AE@% routine uses system call INT 0x2B to set the current system
  11566. date. The date is stored in the %@AB@%dosdate_t%@AE@% structure pointed to by %@AI@%date%@AE@%,
  11567. defined in DOS.H. The %@AB@%dosdate_t%@AE@% structure contains the following elements:  %@NL@%
  11568. %@NL@%
  11569. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  11570. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11571. %@AB@%unsigned char day%@AE@%                 1 -31
  11572.  
  11573. %@AB@%unsigned char month%@AE@%               1 -12
  11574.  
  11575. %@AB@%unsigned int year%@AE@%                 1980 - 2099
  11576.  
  11577. %@AB@%unsigned char dayofweek%@AE@%           0 - 6 (0 = Sunday)
  11578.  
  11579. %@NL@%
  11580. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11581. %@NL@%
  11582. If successful, the function returns 0. Otherwise, it returns a nonzero value
  11583. and sets %@AB@%errno%@AE@% to %@AB@%EINVAL%@AE@%, indicating an invalid date was specified.  %@NL@%
  11584. %@NL@%
  11585. %@NL@%
  11586. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11587. %@NL@%
  11588.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11589. %@NL@%
  11590. %@NL@%
  11591. %@NL@%
  11592. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11593. %@NL@%
  11594. %@AB@%_dos_gettime%@AE@%, %@AB@% _dos_setdate%@AE@%, %@AB@% _dos_settime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%mktime%@AE@%, %@AB@%
  11595. %@AB@%_strdate%@AE@%, %@AB@%_strtime%@AE@%, %@AB@%time%@AE@%  %@NL@%
  11596. %@NL@%
  11597. %@NL@%
  11598. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11599. %@NL@%
  11600. %@AS@%  /* DSTIME.C: This program changes the time and date values and displays
  11601. %@AS@%  the
  11602. %@AS@%   * new date and time values.
  11603. %@AS@%   */
  11604. %@AS@%  
  11605. %@AS@%  #include <dos.h>
  11606. %@AS@%  #include <conio.h>
  11607. %@AS@%  #include <stdio.h>
  11608. %@AS@%  #include <time.h>%@AE@%%@NL@%
  11609. %@NL@%
  11610. %@AS@%  void main()
  11611. %@AS@%  {
  11612. %@AS@%     struct dosdate_t olddate, newdate = { { 4 }, { 7 }, { 1984 } };
  11613. %@AS@%     struct dostime_t oldtime, newtime = { { 3 }, { 45 }, { 30 }, { 0 } };
  11614. %@AS@%     char   datebuf[40], timebuf[40];
  11615. %@AS@%  
  11616. %@AS@%     /* Get current date and time values */
  11617. %@AS@%     _dos_getdate( &olddate );
  11618. %@AS@%     _dos_gettime( &oldtime );
  11619. %@AS@%     printf( "%s    %s\n" , _strdate( datebuf ), _strtime( timebuf ) );
  11620. %@AS@%  
  11621. %@AS@%     /* Modify date and time structures */
  11622. %@AS@%     _dos_setdate( &newdate );
  11623. %@AS@%     _dos_settime( &newtime );
  11624. %@AS@%     printf( "%s    %s\n" , _strdate( datebuf ), _strtime( timebuf ) );
  11625. %@AS@%  
  11626. %@AS@%     /* Restore old date and time */
  11627. %@AS@%     _dos_setdate( &olddate );
  11628. %@AS@%     _dos_settime( &oldtime );
  11629. %@AS@%  }%@AE@%%@NL@%
  11630. %@NL@%
  11631. %@NL@%
  11632. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11633. %@NL@%
  11634. %@AS@%  
  11635. %@AS@%  
  11636. %@AS@%  06/15/89    18:26:09
  11637. %@AS@%  07/04/84    03:45:30 %@AE@%%@NL@%
  11638. %@NL@%
  11639. %@NL@%
  11640. %@NL@%
  11641. %@NL@%
  11642. %@QR:_dos_setdrive@%%@NL@%
  11643. %@2@%%@CR:C6A00740397 @%%@AB@%_dos_setdrive%@AE@%%@EH@%%@NL@%
  11644. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11645. %@NL@%
  11646. %@NL@%
  11647. %@3@%%@AB@%Description%@CR:C6A00740398 @% %@CR:C6A00740399 @%%@AE@%%@EH@%%@NL@%
  11648. %@NL@%
  11649. Sets the default drive, using system call INT 0x0E.  %@NL@%
  11650. %@NL@%
  11651. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11652. %@NL@%
  11653. %@AS@%  void _dos_setdrive( unsigned drive, unsigned *numdrives );%@AE@%%@NL@%
  11654. %@NL@%
  11655. %@AI@%drive%@AE@%                             New default drive
  11656.  
  11657. %@AI@%numdrives%@AE@%                         Total drives available
  11658.  
  11659. %@NL@%
  11660. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11661. %@NL@%
  11662. The %@AB@%_dos_setdrive%@AE@% routine uses system call INT 0x0E to set the current
  11663. default drive to the %@AI@%drive%@AE@% argument: 1 = drive A, 2 = drive B, and so on.
  11664. The %@AI@%numdrives%@AE@% argument indicates the total number of drives in the system.
  11665. If this value is 4, for example, it does not mean the drives are designated
  11666. A, B, C, and D; it means only that four drives are in the system.  %@NL@%
  11667. %@NL@%
  11668. %@NL@%
  11669. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11670. %@NL@%
  11671. There is no return value. If an invalid drive number is passed, the function
  11672. fails without indication. Use the %@AB@%_dos_getdrive%@AE@% routine to verify whether
  11673. the desired drive has been set.  %@NL@%
  11674. %@NL@%
  11675. %@NL@%
  11676. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11677. %@NL@%
  11678.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11679. %@NL@%
  11680. %@NL@%
  11681. %@NL@%
  11682. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11683. %@NL@%
  11684. %@AB@%_dos_getdiskfree%@AE@%, %@AB@% _dos_getdrive%@AE@%  %@NL@%
  11685. %@NL@%
  11686. %@NL@%
  11687. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11688. %@NL@%
  11689. %@AS@%  /* DGDRIVE.C: This program prints the letter of the current drive,
  11690. %@AS@%   * changes the default drive to A, then returns the number of disk drives.
  11691. %@AS@%   */
  11692. %@AS@%  
  11693. %@AS@%  #include <stdio.h>
  11694. %@AS@%  #include <dos.h>
  11695. %@AS@%  
  11696. %@AS@%  void main()
  11697. %@AS@%  {
  11698. %@AS@%     unsigned olddrive, newdrive;
  11699. %@AS@%     unsigned number_of_drives;
  11700. %@AS@%  
  11701. %@AS@%     /* Print current default drive information */
  11702. %@AS@%     _dos_getdrive( &olddrive );
  11703. %@AS@%     printf( "The current drive is: %c\n", 'A' + olddrive1 );
  11704. %@AS@%  
  11705. %@AS@%     /* Set default drive to be drive A */
  11706. %@AS@%     printf( "Changing default drive to A\n");
  11707. %@AS@%     _dos_setdrive( 1, &number_of_drives );
  11708. %@AS@%  
  11709. %@AS@%     /* Get new default drive information and total number of drives */
  11710. %@AS@%     _dos_getdrive( &newdrive );
  11711. %@AS@%     printf( "The current drive is: %c\n", 'A' + newdrive1 );
  11712. %@AS@%     printf( "Number of logical drives: %d\n", number_of_drives );
  11713. %@AS@%  
  11714. %@AS@%     /* Restore default drive */
  11715. %@AS@%     _dos_setdrive( olddrive, &number_of_drives );
  11716. %@AS@%  }%@AE@%%@NL@%
  11717. %@NL@%
  11718. %@NL@%
  11719. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11720. %@NL@%
  11721. %@AS@%  
  11722. %@AS@%  
  11723. %@AS@%  The current drive is: C
  11724. %@AS@%  Changing default drive to A
  11725. %@AS@%  The current drive is: A
  11726. %@AS@%  Number of logical drives: 26 %@AE@%%@NL@%
  11727. %@NL@%
  11728. %@NL@%
  11729. %@NL@%
  11730. %@NL@%
  11731. %@QR:_dos_setfileattr@%%@NL@%
  11732. %@2@%%@CR:C6A00750400 @%%@AB@%_dos_setfileattr%@AE@%%@EH@%%@NL@%
  11733. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11734. %@NL@%
  11735. %@NL@%
  11736. %@3@%%@AB@%Description%@CR:C6A00750401 @% %@CR:C6A00750402 @%%@AE@%%@EH@%%@NL@%
  11737. %@NL@%
  11738. Sets the attributes of the file or directory, using system call INT 0x43.  %@NL@%
  11739. %@NL@%
  11740. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11741. %@NL@%
  11742. %@AS@%  unsigned _dos_setfileattr( char *pathname, unsigned attrib );%@AE@%%@NL@%
  11743. %@NL@%
  11744. %@AI@%pathname%@AE@%                          Full path of target file/directory
  11745.  
  11746. %@AI@%attrib%@AE@%                            New attributes
  11747.  
  11748. %@NL@%
  11749. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11750. %@NL@%
  11751. The %@AB@%_dos_setfileattr%@AE@% routine uses system call INT 0x43 to set the attributes
  11752. of the file or directory pointed to by %@AI@%pathname%@AE@%. The actual attributes are
  11753. contained in the low-order byte of the %@AI@%attrib%@AE@% word. Attributes are
  11754. represented by manifest constants, as described below:  %@NL@%
  11755. %@NL@%
  11756. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  11757. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11758. %@AB@%_A_ARCH%@AE@%                           Archive. Set whenever the file is 
  11759.                                   changed, or cleared by the DOS BACKUP 
  11760.                                   command.
  11761.  
  11762. %@AB@%_A_HIDDEN%@AE@%                         Hidden file. Cannot be found by a 
  11763.                                   directory search.
  11764.  
  11765. %@AB@%_A_NORMAL%@AE@%                         Normal. File can be read or written to 
  11766.                                   without restriction.
  11767.  
  11768. %@AB@%_A_RDONLY%@AE@%                         Read-only. File cannot be opened for 
  11769.                                   writing, and a file with the same name 
  11770.                                   cannot be created.
  11771.  
  11772. %@AB@%_A_SUBDIR%@AE@%                         Subdirectory.
  11773.  
  11774. %@AB@%_A_SYSTEM%@AE@%                         System file. Cannot be found by a 
  11775.                                   directory search.
  11776.  
  11777. %@AB@%_A_VOLID%@AE@%                          Volume ID. Only one file can have this 
  11778.                                   attribute, and it must be in the root 
  11779.                                   directory.
  11780.  
  11781. %@NL@%
  11782. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11783. %@NL@%
  11784. The function returns 0 if successful. Otherwise, it returns the DOS error
  11785. code and sets %@AB@%errno%@AE@% to one of the following:  %@NL@%
  11786. %@NL@%
  11787. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  11788. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11789. %@AB@%EACCES%@AE@%                            Access denied; cannot change the volume 
  11790.                                   ID or the
  11791.                                   subdirectory.
  11792.  
  11793. %@AB@%ENOENT%@AE@%                            No file or directory matching the target
  11794.                                   was found.
  11795.  
  11796. %@NL@%
  11797. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11798. %@NL@%
  11799.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11800. %@NL@%
  11801. %@NL@%
  11802. %@NL@%
  11803. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11804. %@NL@%
  11805. %@AB@%_dos_getfileattr%@AE@%  %@NL@%
  11806. %@NL@%
  11807. %@NL@%
  11808. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11809. %@NL@%
  11810. %@AS@%  /* DGFILEAT.C: This program creates a file with the specified attributes,
  11811. %@AS@%   * then prints this information before changing the file attributes back 
  11812. %@AS@%   * to normal.
  11813. %@AS@%   */
  11814. %@AS@%  
  11815. %@AS@%  #include <stdio.h>
  11816. %@AS@%  #include <dos.h>
  11817. %@AS@%  
  11818. %@AS@%  void main()
  11819. %@AS@%  {
  11820. %@AS@%     unsigned oldattrib, newattrib;
  11821. %@AS@%     int fh;
  11822. %@AS@%  
  11823. %@AS@%     /* Get and display file attribute */
  11824. %@AS@%     _dos_getfileattr( "DGFILEAT.C", &oldattrib );
  11825. %@AS@%     printf( "Attribute: 0x%.4x\n", oldattrib );
  11826. %@AS@%     if( ( oldattrib & _A_RDONLY ) != 0 )
  11827. %@AS@%        printf( "Read only file\n" );
  11828. %@AS@%     else
  11829. %@AS@%        printf( "Not a read only file.\n" );
  11830. %@AS@%  
  11831. %@AS@%     /* Reset file attribute to normal file */
  11832. %@AS@%     _dos_setfileattr( "DGFILEAT.C", _A_RDONLY );
  11833. %@AS@%     _dos_getfileattr( "DGFILEAT.C", &newattrib );
  11834. %@AS@%     printf( "Attribute: 0x%.4x\n", newattrib );
  11835. %@AS@%  
  11836. %@AS@%     /* Restore file attribute */
  11837. %@AS@%     _dos_setfileattr( "DGFILEAT.C", oldattrib );
  11838. %@AS@%     _dos_getfileattr( "DGFILEAT.C", &newattrib );
  11839. %@AS@%     printf( "Attribute: 0x%.4x\n", newattrib );
  11840. %@AS@%  }%@AE@%%@NL@%
  11841. %@NL@%
  11842. %@NL@%
  11843. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11844. %@NL@%
  11845. %@AS@%  
  11846. %@AS@%  
  11847. %@AS@%  Attribute: 0x0020
  11848. %@AS@%  Not a read only file.
  11849. %@AS@%  Attribute: 0x0001
  11850. %@AS@%  Attribute: 0x0020 %@AE@%%@NL@%
  11851. %@NL@%
  11852. %@NL@%
  11853. %@NL@%
  11854. %@NL@%
  11855. %@QR:_dos_setftime@%%@NL@%
  11856. %@2@%%@CR:C6A00760403 @%%@AB@%_dos_setftime%@AE@%%@EH@%%@NL@%
  11857. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11858. %@NL@%
  11859. %@NL@%
  11860. %@3@%%@AB@%Description%@CR:C6A00760404 @% %@CR:C6A00760405 @%%@AE@%%@EH@%%@NL@%
  11861. %@NL@%
  11862. Sets the date and time for a file, using system call INT 0x57.  %@NL@%
  11863. %@NL@%
  11864. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11865. %@NL@%
  11866. %@AS@%  unsigned _dos_setftime( int handle, unsigned date, unsigned time );%@AE@%%@NL@%
  11867. %@NL@%
  11868. %@AI@%handle%@AE@%                            Target file
  11869.  
  11870. %@AI@%date%@AE@%                              Date of last write
  11871.  
  11872. %@AI@%time%@AE@%                              Time of last write
  11873.  
  11874. %@NL@%
  11875. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  11876. %@NL@%
  11877. The %@AB@%_dos_setftime%@AE@% routine uses system call INT 0x57 to set the %@AI@%date%@AE@% and %@AI@%time%@AE@%
  11878. at which the file identified by %@AI@%handle%@AE@% was last written to. These values
  11879. appear in the DOS date and time format, described in the following lists:  %@NL@%
  11880. %@NL@%
  11881. %@AB@%Time Bits%@AE@%                         %@AB@%Meaning%@AE@%
  11882. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11883. 0 - 4                             Number of two-second increments (0 -29)
  11884.  
  11885. 5 - 10                            Minutes (0 -59)
  11886.  
  11887. 11-15                             Hours (0 -23)
  11888.  
  11889. %@AB@%Date Bits%@AE@%                         %@AB@%Meaning%@AE@%
  11890. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11891. 0 - 4                             Day (1-31)
  11892.  
  11893. 5 -8                              Month (1-12)
  11894.  
  11895. 9 -15                             Year since 1980 (for example, 1989 is 
  11896.                                   stored as 9)
  11897.  
  11898. %@NL@%
  11899. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  11900. %@NL@%
  11901. If successful, the function returns 0. Otherwise, it returns the DOS error
  11902. code and sets %@AB@%errno%@AE@% to %@AB@%EBADF%@AE@%, indicating that an invalid file handle was
  11903. passed.  %@NL@%
  11904. %@NL@%
  11905. %@NL@%
  11906. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  11907. %@NL@%
  11908.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  11909. %@NL@%
  11910. %@NL@%
  11911. %@NL@%
  11912. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  11913. %@NL@%
  11914. %@AB@%_dos_getftime%@AE@%, %@AB@%fstat%@AE@%, %@AB@%stat%@AE@%  %@NL@%
  11915. %@NL@%
  11916. %@NL@%
  11917. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  11918. %@NL@%
  11919. %@AS@%  /* DGFTIME.C: This program displays and modifies the date and time
  11920. %@AS@%   * fields of a file.
  11921. %@AS@%   */
  11922. %@AS@%  
  11923. %@AS@%  #include <fcntl.h>
  11924. %@AS@%  #include <stdio.h>
  11925. %@AS@%  #include <stdlib.h>
  11926. %@AS@%  #include <dos.h>
  11927. %@AS@%  
  11928. %@AS@%  void main()
  11929. %@AS@%  {
  11930. %@AS@%                                   /* FEDC BA98 7654 3210          */
  11931. %@AS@%     unsigned new_date = 0x184f;   /* 0001 1000 0100 1111  2/15/92 */
  11932. %@AS@%     unsigned new_time = 0x48e0;   /* 0100 1000 1110 0000  9:07 AM */
  11933. %@AS@%     unsigned old_date, old_time;
  11934. %@AS@%  
  11935. %@AS@%     int fh;
  11936. %@AS@%  
  11937. %@AS@%     /* Open file with _dos_open function */
  11938. %@AS@%     if( _dos_open( "dgftime.obj", O_RDONLY, &fh ) != 0 )
  11939. %@AS@%        exit( 1 );
  11940. %@AS@%  
  11941. %@AS@%     /* Get file date and time */
  11942. %@AS@%     _dos_getftime( fh, &old_date, &old_time );
  11943. %@AS@%     printf( "Old date field: 0x%.4x\n", old_date );
  11944. %@AS@%     printf( "Old time field: 0x%.4x\n", old_time );
  11945. %@AS@%     system( "dir dgftime.obj" );
  11946. %@AS@%  
  11947. %@AS@%     /* Modify file date and time */
  11948. %@AS@%     if( !_dos_setftime( fh, new_date, new_time ) )
  11949. %@AS@%     {
  11950. %@AS@%        _dos_getftime( fh, &new_date, &new_time );
  11951. %@AS@%        printf( "New date field: 0x%.4x\n", new_date );
  11952. %@AS@%        printf( "New time field: 0x%.4x\n", new_time );
  11953. %@AS@%        system( "dir dgftime.obj" );
  11954. %@AS@%  
  11955. %@AS@%        /* Restore date and time */
  11956. %@AS@%        _dos_setftime( fh, old_date, old_time );
  11957. %@AS@%     }
  11958. %@AS@%     _dos_close( fh );
  11959. %@AS@%  }%@AE@%%@NL@%
  11960. %@NL@%
  11961. %@NL@%
  11962. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  11963. %@NL@%
  11964. %@AS@%  
  11965. %@AS@%  
  11966. %@AS@%  Old date field: 0x12cf
  11967. %@AS@%  Old time field: 0x94bb
  11968. %@AS@%  
  11969. %@AS@%   Volume in drive C is OS2
  11970. %@AS@%   Directory of  C:\LIBREF
  11971. %@AS@%  
  11972. %@AS@%  DGFTIME  OBJ     3923   6-15-89   6:37p
  11973. %@AS@%          1 File(s)  13676544 bytes free
  11974. %@AS@%  
  11975. %@AS@%  New date field: 0x184f
  11976. %@AS@%  New time field: 0x48e0
  11977. %@AS@%  
  11978. %@AS@%   Volume in drive C is OS2
  11979. %@AS@%   Directory of  C:\LIBREF
  11980. %@AS@%  
  11981. %@AS@%  DGFTIME  OBJ     3923   2-15-92   9:07a
  11982. %@AS@%          1 File(s)  13676544 bytes free %@AE@%%@NL@%
  11983. %@NL@%
  11984. %@NL@%
  11985. %@NL@%
  11986. %@NL@%
  11987. %@QR:_dos_settime@%%@NL@%
  11988. %@2@%%@CR:C6A00770406 @%%@AB@%_dos_settime%@AE@%%@EH@%%@NL@%
  11989. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  11990. %@NL@%
  11991. %@NL@%
  11992. %@3@%%@AB@%Description%@CR:C6A00770407 @% %@CR:C6A00770408 @%%@AE@%%@EH@%%@NL@%
  11993. %@NL@%
  11994. Sets the current system time, using system call INT 0x2D.  %@NL@%
  11995. %@NL@%
  11996. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  11997. %@NL@%
  11998. %@AS@%  unsigned _dos_settime( struct dostime_t *time );%@AE@%%@NL@%
  11999. %@NL@%
  12000. %@AI@%time%@AE@%                              New system time
  12001.  
  12002. %@NL@%
  12003. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12004. %@NL@%
  12005. The %@AB@%_dos_settime%@AE@% routine uses system call INT 0x2D to set the current system
  12006. time to the value stored in the %@AB@%dostime_t%@AE@% structure that %@AI@%time%@AE@% points to, as
  12007. defined in DOS.H. The %@AB@%dostime_t%@AE@% structure contains the following elements:  %@NL@%
  12008. %@NL@%
  12009. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  12010. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12011. %@AB@%unsigned char hour%@AE@%                0 -23
  12012.  
  12013. %@AB@%unsigned char minute%@AE@%              0 -59
  12014.  
  12015. %@AB@%unsigned char second%@AE@%              0 -59
  12016.  
  12017. %@AB@%unsigned char hsecond%@AE@%             Hundredths of a second; 0 -99
  12018.  
  12019. %@NL@%
  12020. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12021. %@NL@%
  12022. If successful, the function returns 0. Otherwise, it returns a nonzero value
  12023. and sets %@AB@%errno%@AE@% to %@AB@%EINVAL%@AE@%, indicating an invalid time was specified.  %@NL@%
  12024. %@NL@%
  12025. %@NL@%
  12026. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12027. %@NL@%
  12028.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  12029. %@NL@%
  12030. %@NL@%
  12031. %@NL@%
  12032. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12033. %@NL@%
  12034. %@AB@%_dos_getdate%@AE@%, %@AB@% _dos_gettime%@AE@%, %@AB@% _dos_setdate%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%mktime%@AE@%,
  12035. %@AB@%_strdate%@AE@%, %@AB@% _strtime%@AE@%  %@NL@%
  12036. %@NL@%
  12037. %@NL@%
  12038. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12039. %@NL@%
  12040. %@AS@%  /* DSTIME.C: This program changes the time and date values and displays
  12041. %@AS@%  the
  12042. %@AS@%   * new date and time values.
  12043. %@AS@%   */
  12044. %@AS@%  
  12045. %@AS@%  #include <dos.h>
  12046. %@AS@%  #include <conio.h>
  12047. %@AS@%  #include <stdio.h>
  12048. %@AS@%  #include <time.h>%@AE@%%@NL@%
  12049. %@NL@%
  12050. %@AS@%  void main()
  12051. %@AS@%  {
  12052. %@AS@%     struct dosdate_t olddate, newdate = { { 4 }, { 7 }, { 1984 } };
  12053. %@AS@%     struct dostime_t oldtime, newtime = { { 3 }, { 45 }, { 30 }, { 0 } };
  12054. %@AS@%     char   datebuf[40], timebuf[40];
  12055. %@AS@%  
  12056. %@AS@%     /* Get current date and time values */
  12057. %@AS@%     _dos_getdate( &olddate );
  12058. %@AS@%     _dos_gettime( &oldtime );
  12059. %@AS@%     printf( "%s    %s\n" , _strdate( datebuf ), _strtime( timebuf ) );
  12060. %@AS@%  
  12061. %@AS@%     /* Modify date and time structures */
  12062. %@AS@%     _dos_setdate( &newdate );
  12063. %@AS@%     _dos_settime( &newtime );
  12064. %@AS@%     printf( "%s    %s\n" , _strdate( datebuf ), _strtime( timebuf ) );
  12065. %@AS@%  
  12066. %@AS@%     /* Restore old date and time */
  12067. %@AS@%     _dos_setdate( &olddate );
  12068. %@AS@%     _dos_settime( &oldtime );
  12069. %@AS@%  }%@AE@%%@NL@%
  12070. %@NL@%
  12071. %@NL@%
  12072. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  12073. %@NL@%
  12074. %@AS@%  
  12075. %@AS@%  
  12076. %@AS@%  06/15/89    18:26:09
  12077. %@AS@%  07/04/84    03:45:30 %@AE@%%@NL@%
  12078. %@NL@%
  12079. %@NL@%
  12080. %@NL@%
  12081. %@NL@%
  12082. %@QR:_dos_setvect@%%@NL@%
  12083. %@2@%%@CR:C6A00780409 @%%@AB@%_dos_setvect%@AE@%%@EH@%%@NL@%
  12084. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12085. %@NL@%
  12086. %@NL@%
  12087. %@3@%%@AB@%Description%@CR:C6A00780410 @% %@CR:C6A00780411 @%%@AE@%%@EH@%%@NL@%
  12088. %@NL@%
  12089. Sets the current value of the interrupt vector, using system call INT 0x25.
  12090. %@NL@%
  12091. %@NL@%
  12092. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  12093. %@NL@%
  12094. %@AS@%  void _dos_setvect( unsigned intnum, void( _interrupt _far *handler)( ));%@AE@%%@NL@%
  12095. %@NL@%
  12096. %@AI@%intnum%@AE@%                            Target-interrupt vector
  12097.  
  12098. %@AI@%handler%@AE@%                           Interrupt handler for which to assign %@AI@%%@AE@%
  12099.                                   %@AI@%intnum%@AE@%
  12100.  
  12101. %@NL@%
  12102. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12103. %@NL@%
  12104. The %@AB@%_dos_setvect%@AE@% routine uses system call INT 0x25 to set the current value
  12105. of the interrupt vector %@AI@%intnum%@AE@% to the function pointed to by %@AI@%handler%@AE@%.
  12106. Subsequently, whenever the %@AI@%intnum%@AE@% interrupt is generated, the %@AI@%handler%@AE@%
  12107. routine will be called. If %@AI@%handler%@AE@% is a C function, it must have been
  12108. previously declared with the %@AB@%interrupt%@AE@% attribute. Otherwise, you must make
  12109. sure that the function satisfies the requirements for an interrupt-handling
  12110. routine. For example, if %@AI@%handler%@AE@% is an assembler function, it must be a %@AB@%far%@AE@%
  12111. routine that returns with an %@AB@%IRET %@AE@%instead of a%@AB@% RET%@AE@%.  %@NL@%
  12112. %@NL@%
  12113. The %@AB@%interrupt%@AE@% attribute indicates that the function is an interrupt handler.
  12114. The compiler generates appropriate entry and exit sequences for the
  12115. interrupt-handling function, including saving and restoring all registers
  12116. and executing an %@AB@%IRET%@AE@% instruction to return.  %@NL@%
  12117. %@NL@%
  12118. The %@AB@%_dos_setvect%@AE@% routine is generally used with the %@AB@%_dos_getvect%@AE@% function.
  12119. To replace an interrupt vector, first save the current vector of the
  12120. interrupt using %@AB@%_dos_getvect%@AE@%. Then set the vector to your own interrupt
  12121. routine with %@AB@%_dos_setvect%@AE@%. The saved vector can later be restored, if
  12122. necessary, using %@AB@%_dos_setvect%@AE@%. The user-defined routine may also need the
  12123. original vector in order to call it or to chain to it with %@AB@%_chain_intr%@AE@%.  %@NL@%
  12124. %@NL@%
  12125. %@NL@%
  12126. %@4@%%@AB@%Registers and Interrupt Functions%@AE@%%@EH@%%@NL@%
  12127. %@NL@%
  12128. When you call an interrupt function, the DS register is initialized to the C
  12129. data segment. This allows you to access global variables from within an
  12130. interrupt function.  %@NL@%
  12131. %@NL@%
  12132. In addition, all registers except SS are saved on the stack. You can access
  12133. these registers within the function if you declare a function parameter list
  12134. containing a formal parameter for each saved register. The following example
  12135. illustrates such a declaration:  %@NL@%
  12136. %@NL@%
  12137. %@AS@%  void _interrupt _far int_handler( unsigned _es, unsigned _ds,
  12138. %@AS@%                                    unsigned _di, unsigned _si, 
  12139. %@AS@%                                    unsigned _bp, unsigned _sp,
  12140. %@AS@%                                    unsigned _bx, unsigned _dx, 
  12141. %@AS@%                                   unsigned _cx, unsigned _ax,
  12142. %@AS@%                                    unsigned _ip, unsigned _cs, 
  12143. %@AS@%                                   unsigned _flags )
  12144. %@AS@%  {
  12145. %@AS@%  .
  12146. %@AS@%  .
  12147. %@AS@%  .
  12148. %@AS@%  }%@AE@%%@NL@%
  12149. %@NL@%
  12150. The formal parameters must appear in the opposite order from which they are
  12151. pushed onto the stack. You can omit parameters from the end of the list in a
  12152. declaration, but not from the beginning. For example, if your handler needs
  12153. to use only DI and SI, you must still provide ES and DS, but not necessarily
  12154. BX or DX.  %@NL@%
  12155. %@NL@%
  12156. You can pass additional arguments if your interrupt handler will be called
  12157. directly from C rather than by an INT instruction. To do this, you must
  12158. declare all register parameters and then declare your parameter at the end
  12159. of the list.  %@NL@%
  12160. %@NL@%
  12161. The compiler always saves and restores registers in the same, fixed order.
  12162. Thus, no matter what names you use in the formal parameter list, the first
  12163. parameter in the list refers to ES, the second refers to DS, and so on. If
  12164. your interrupt routines will use in-line assembler, you should distinguish
  12165. the parameter names so that they will not be the same as the real register
  12166. names.  %@NL@%
  12167. %@NL@%
  12168. If you change any of the register parameters of an interrupt function while
  12169. the function is executing, the corresponding register contains the changed
  12170. value when the function returns. For example:  %@NL@%
  12171. %@NL@%
  12172. %@AS@%  void _interrupt _far int_handler( unsigned _es, unsigned _ds,
  12173. %@AS@%                                   unsigned _di, unsigned _si )
  12174. %@AS@%  {
  12175. %@AS@%      _di = -1;
  12176. %@AS@%  }%@AE@%%@NL@%
  12177. %@NL@%
  12178. This code causes the DI register to contain -1 when the %@AI@%handler%@AE@% function
  12179. returns. It is not a good idea to modify the values of the parameters
  12180. representing the IP and CS registers in interrupt functions. If you must
  12181. modify a particular flag (such as the carry flag for certain DOS and BIOS
  12182. interrupt routines), use the OR operator ( | ) so that other bits in the
  12183. flag register are not changed.  %@NL@%
  12184. %@NL@%
  12185. When an interrupt function is called by an INT instruction, the
  12186. interrupt-enable flag is cleared. If your interrupt function needs to do
  12187. significant processing, you should use the %@AB@%_enable%@AE@% function to set the
  12188. interrupt flag so that interrupts can be handled.  %@NL@%
  12189. %@NL@%
  12190. %@NL@%
  12191. %@4@%%@AB@%Precautions for Interrupt Functions%@AE@%%@EH@%%@NL@%
  12192. %@NL@%
  12193. Since DOS is not reentrant (a DOS interrupt cannot be called from inside a
  12194. DOS interrupt), it is usually not safe to call from inside an interrupt
  12195. function any standard library function that calls DOS INT 21H. Similar
  12196. precautions apply to many BIOS functions. Functions that rely on INT 21H
  12197. calls include I/O functions and the %@AB@%_dos%@AE@% family of functions. Functions that
  12198. rely on the machine's BIOS include graphics functions and the %@AB@%_bios%@AE@% family
  12199. of functions. It is usually safe to use functions that do not rely on INT
  12200. 21H or BIOS, such as string-handling functions. Before using a standard
  12201. library function in an interrupt function, be sure that you are familiar
  12202. with the action of the library function.  %@NL@%
  12203. %@NL@%
  12204. %@NL@%
  12205. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12206. %@NL@%
  12207. None.  %@NL@%
  12208. %@NL@%
  12209. %@NL@%
  12210. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12211. %@NL@%
  12212.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  12213. %@NL@%
  12214. %@NL@%
  12215. %@NL@%
  12216. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12217. %@NL@%
  12218. %@AB@%_chain_intr%@AE@%, %@AB@% _dos_getvect%@AE@%, %@AB@% _dos_keep%@AE@%  %@NL@%
  12219. %@NL@%
  12220. %@NL@%
  12221. %@NL@%
  12222. %@NL@%
  12223. %@QR:_dos_write@%%@NL@%
  12224. %@2@%%@CR:C6A00790412 @%%@AB@%_dos_write%@AE@%%@EH@%%@NL@%
  12225. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12226. %@NL@%
  12227. %@NL@%
  12228. %@3@%%@AB@%Description%@CR:C6A00790413 @% %@CR:C6A00790414 @%%@AE@%%@EH@%%@NL@%
  12229. %@NL@%
  12230. Writes a buffer to a file, using system call INT 0x40.  %@NL@%
  12231. %@NL@%
  12232. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  12233. %@NL@%
  12234. %@AS@%  unsigned _dos_write( int handle, void _far *buffer, unsigned count, 
  12235. %@AS@%  unsigned *numwrt );%@AE@%%@NL@%
  12236. %@NL@%
  12237. %@AI@%handle%@AE@%                            File to write to
  12238.  
  12239. %@AI@%buffer%@AE@%                            Buffer to write from
  12240.  
  12241. %@AI@%count%@AE@%                             Number of bytes to write
  12242.  
  12243. %@AI@%numwrt%@AE@%                            Number of bytes actually written
  12244.  
  12245. %@NL@%
  12246. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12247. %@NL@%
  12248. The %@AB@%_dos_write%@AE@% routine uses system call INT 0x40 to write data to the file
  12249. that %@AI@%handle%@AE@% references; %@AI@%count%@AE@% bytes of data from the buffer to which %@AI@%buffer%@AE@%
  12250. points are written to the file. The integer pointed to by %@AI@%numwrt %@AE@%will be the
  12251. number of bytes actually written, which may be less than the number
  12252. requested.%@AI@%  %@AE@%%@NL@%
  12253. %@NL@%
  12254. Do not use the DOS interface routines with the console, low-level, or stream
  12255. I/O routines.  %@NL@%
  12256. %@NL@%
  12257. %@NL@%
  12258. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12259. %@NL@%
  12260. If successful, the function returns 0. Otherwise, it returns the DOS error
  12261. code and sets %@AB@%errno%@AE@% to one of the following manifest constants:  %@NL@%
  12262. %@NL@%
  12263. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  12264. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12265. %@AB@%EACCES%@AE@%                            Access denied (%@AI@%handle%@AE@% references a file 
  12266.                                   not open for write
  12267.                                   access)
  12268.  
  12269. %@AB@%EBADF%@AE@%                             Invalid file handle
  12270.  
  12271. %@NL@%
  12272. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12273. %@NL@%
  12274.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  12275. %@NL@%
  12276. %@NL@%
  12277. %@NL@%
  12278. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12279. %@NL@%
  12280. %@AB@%_dos_close%@AE@%, %@AB@% _dos_open%@AE@%, %@AB@% _dos_read%@AE@%, %@AB@%write%@AE@%  %@NL@%
  12281. %@NL@%
  12282. %@NL@%
  12283. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12284. %@NL@%
  12285. %@AS@%  /* DWRITE.C: This program uses DOS I/O functions to write to a file. */
  12286. %@AS@%  
  12287. %@AS@%  #include <fcntl.h>
  12288. %@AS@%  #include <stdio.h>
  12289. %@AS@%  #include <stdlib.h>
  12290. %@AS@%  #include <dos.h>
  12291. %@AS@%  
  12292. %@AS@%  void main()
  12293. %@AS@%  {
  12294. %@AS@%     char out_buffer[] = "Hello";
  12295. %@AS@%     int  fh;
  12296. %@AS@%     unsigned n_written;
  12297. %@AS@%  
  12298. %@AS@%     /* Open file with _dos_creat function */
  12299. %@AS@%     if( _dos_creat( "data", _A_NORMAL, &fh ) == 0 )
  12300. %@AS@%     {
  12301. %@AS@%        /* Write data with _dos_write function */
  12302. %@AS@%        _dos_write( fh, out_buffer, 5, &n_written );
  12303. %@AS@%        printf( "Number of characters written: %d\n", n_written );
  12304. %@AS@%  
  12305. %@AS@%        _dos_close( fh );
  12306. %@AS@%        printf( "Contents of file are:\n" );
  12307. %@AS@%        system( "type data" );
  12308. %@AS@%     }
  12309. %@AS@%  }%@AE@%%@NL@%
  12310. %@NL@%
  12311. %@NL@%
  12312. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  12313. %@NL@%
  12314. %@AS@%  
  12315. %@AS@%  
  12316. %@AS@%  Number of characters written: 5
  12317. %@AS@%  Contents of file are:
  12318. %@AS@%  Hello %@AE@%%@NL@%
  12319. %@NL@%
  12320. %@NL@%
  12321. %@NL@%
  12322. %@NL@%
  12323. %@QR:dosexterr@%%@NL@%
  12324. %@2@%%@CR:C6A00800415 @%%@AB@%dosexterr%@AE@%%@EH@%%@NL@%
  12325. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12326. %@NL@%
  12327. %@NL@%
  12328. %@3@%%@AB@%Description%@CR:C6A00800416 @%%@CR:C6A00800417 @% %@CR:C6A00800418 @%%@AE@%%@EH@%%@NL@%
  12329. %@NL@%
  12330. Gets register values returned by INT 0x59.  %@NL@%
  12331. %@NL@%
  12332. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  12333. %@NL@%
  12334. %@AS@%  int dosexterr( struct DOSERROR *errorinfo );%@AE@%%@NL@%
  12335. %@NL@%
  12336. %@AI@%errorinfo%@AE@%                         Extended DOS error information
  12337.  
  12338. %@NL@%
  12339. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12340. %@NL@%
  12341. The %@AB@%dosexterr%@AE@% function obtains the extended error information returned by
  12342. the DOS system call INT 0x59 and stores the values in the structure pointed
  12343. to by %@AI@%errorinfo%@AE@%. This function is useful when making system calls under DOS
  12344. versions 3.0 or later, which offer extended error handling. %@CR:C6A00800419 @%%@CR:C6A00800420 @%  %@NL@%
  12345. %@NL@%
  12346. The structure type %@AB@%DOSERROR %@AE@%is defined in DOS.H. The %@AB@%DOSERROR%@AE@% structure
  12347. contains the following elements:%@CR:C6A00800421 @%%@CR:C6A00800422 @%  %@NL@%
  12348. %@NL@%
  12349. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  12350. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12351. %@AB@%int exterror%@AE@%                      AX register contents
  12352.  
  12353. %@AB@%char class%@AE@%                        BH register contents
  12354.  
  12355. %@AB@%char action%@AE@%                       BL register contents
  12356.  
  12357. %@AB@%char locus%@AE@%                        CH register contents
  12358.  
  12359. Giving a %@AB@%NULL%@AE@% pointer argument causes %@AB@%dosexterr%@AE@% to return the value in AX
  12360. without filling in the structure fields. See %@AI@%MS-DOS Encyclopedia %@AE@% (Duncan,
  12361. ed.; Redmond, WA: Microsoft Press, 1988) or %@AI@%Programmer's PC Sourcebook%@AE@%
  12362. (Hogan; Redmond, WA: Microsoft Press, 1988) for more information on the
  12363. register contents.  %@NL@%
  12364. %@NL@%
  12365. %@NL@%
  12366. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12367. %@NL@%
  12368. The %@AB@%dosexterr%@AE@% function returns the value in the AX register (identical to
  12369. the value in the %@AB@%exterror%@AE@% structure field).  %@NL@%
  12370. %@NL@%
  12371. %@NL@%
  12372. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12373. %@NL@%
  12374.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  12375. %@NL@%
  12376. %@NL@%
  12377. The %@AB@%dosexterr%@AE@% function should be used only under DOS versions 3.0 or later.
  12378. %@NL@%
  12379. %@NL@%
  12380. %@NL@%
  12381. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12382. %@NL@%
  12383. %@AB@%perror%@AE@%  %@NL@%
  12384. %@NL@%
  12385. %@NL@%
  12386. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12387. %@NL@%
  12388. %@AS@%  /* DOSEXERR.C: This program tries to open the file test.dat. If the
  12389. %@AS@%   * attempted open operation fails, the program uses dosexterr to display
  12390. %@AS@%   * extended error information.
  12391. %@AS@%   */
  12392. %@AS@%  
  12393. %@AS@%  #include <dos.h>
  12394. %@AS@%  #include <io.h>
  12395. %@AS@%  #include <fcntl.h>
  12396. %@AS@%  #include <stdio.h>
  12397. %@AS@%  
  12398. %@AS@%  void main()
  12399. %@AS@%  {
  12400. %@AS@%     struct DOSERROR doserror;
  12401. %@AS@%     int fd;
  12402. %@AS@%  
  12403. %@AS@%     /* Attempt to open a non-existent file */
  12404. %@AS@%     if( (fd = open( "NOSUCHF.ILE", O_RDONLY )) == -1 )
  12405. %@AS@%     {
  12406. %@AS@%        dosexterr( &doserror );
  12407. %@AS@%        printf( "Error: %d  Class: %d  Action: %d  Locus: %d\n",
  12408. %@AS@%                doserror.exterror, doserror.class,
  12409. %@AS@%                doserror.action,   doserror.locus );
  12410. %@AS@%     }
  12411. %@AS@%     else
  12412. %@AS@%     {
  12413. %@AS@%        printf( "Open succeeded so no extended information printed\n" );
  12414. %@AS@%        close( fd );
  12415. %@AS@%     }
  12416. %@AS@%  }%@AE@%%@NL@%
  12417. %@NL@%
  12418. %@NL@%
  12419. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  12420. %@NL@%
  12421. %@AS@%  
  12422. %@AS@%  
  12423. %@AS@%  Error: 2  Class: 8  Action: 3  Locus: 2 %@AE@%%@NL@%
  12424. %@NL@%
  12425. %@NL@%
  12426. %@NL@%
  12427. %@NL@%
  12428. %@QR:dup@%%@QR:dup2@%%@NL@%
  12429. %@2@%%@CR:C6A00810423 @%%@AB@%dup, dup2%@AE@%%@EH@%%@NL@%
  12430. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12431. %@NL@%
  12432. %@NL@%
  12433. %@3@%%@AB@%Description%@CR:C6A00810424 @%%@CR:C6A00810425 @%%@AE@%%@EH@%%@NL@%
  12434. %@NL@%
  12435. Create a second handle for an open file (%@AB@%dup%@AE@%), or reassign a file handle
  12436. (%@AB@%dup2%@AE@%).  %@NL@%
  12437. %@NL@%
  12438. %@AB@%#include <io.h%@AE@%                    Required only for function declarations
  12439.  
  12440. %@AS@%  int dup( int handle );%@AE@%%@NL@%
  12441. %@NL@%
  12442. %@AS@%  int dup2( int handle1, int handle2 );%@AE@%%@NL@%
  12443. %@NL@%
  12444. %@AI@%handle%@AE@%, %@AI@%handle1%@AE@%                   Handle referring to open file
  12445.  
  12446. %@AI@%handle2%@AE@%                           Any handle value
  12447.  
  12448. %@NL@%
  12449. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12450. %@NL@%
  12451. The %@AB@%dup%@AE@% and %@AB@%dup2%@AE@% functions cause a second file handle to be associated with
  12452. a currently open file. Operations on the file can be carried out using
  12453. either file handle. The type of access allowed for the file is unaffected by
  12454. the creation of a new handle.%@CR:C6A00810426 @%  %@NL@%
  12455. %@NL@%
  12456. The %@AB@%dup%@AE@% function returns the next available file handle for the given file.
  12457. The %@AB@%dup2%@AE@% function forces %@AI@%handle2%@AE@% to refer to the same file as %@AI@%handle1%@AE@%. If
  12458. %@AI@%handle2%@AE@% is associated with an open file at the time of the call, that file
  12459. is closed.  %@NL@%
  12460. %@NL@%
  12461. %@NL@%
  12462. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12463. %@NL@%
  12464. The %@AB@%dup%@AE@% function returns a new file handle. The %@AB@%dup2%@AE@% function returns 0 to
  12465. indicate success. Both functions return -1 if an error occurs and set %@AB@%errno%@AE@%
  12466. to one of the following values:  %@NL@%
  12467. %@NL@%
  12468. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  12469. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12470. %@AB@%EBADF%@AE@%                             Invalid file handle
  12471.  
  12472. %@AB@%EMFILE%@AE@%                            No more file handles available (too many
  12473.                                   open files)
  12474.  
  12475. %@NL@%
  12476. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12477. %@NL@%
  12478.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  12479. %@NL@%
  12480. %@NL@%
  12481. %@NL@%
  12482. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12483. %@NL@%
  12484. %@AB@%close%@AE@%, %@AB@%creat%@AE@%, %@AB@%open%@AE@%  %@NL@%
  12485. %@NL@%
  12486. %@NL@%
  12487. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12488. %@NL@%
  12489. %@AS@%  /* DUP.C: This program uses the variable old to save the original stdout.
  12490. %@AS@%   * It then opens a new file named new and forces stdout to refer
  12491. %@AS@%   * to it. Finally, it restores stdout to its original state.
  12492. %@AS@%   */
  12493. %@AS@%  
  12494. %@AS@%  #include <io.h>
  12495. %@AS@%  #include <stdlib.h>
  12496. %@AS@%  #include <stdio.h>
  12497. %@AS@%  void main()
  12498. %@AS@%  {
  12499. %@AS@%     int old;
  12500. %@AS@%     FILE *new;
  12501. %@AS@%  
  12502. %@AS@%     old = dup( 1 );   /* "old" now refers to "stdout" */
  12503. %@AS@%                       /* Note:  file handle 1 == "stdout" */
  12504. %@AS@%     if( old == -1 )
  12505. %@AS@%     {
  12506. %@AS@%        perror( "dup( 1 ) failure" );
  12507. %@AS@%        exit( 1 );
  12508. %@AS@%     }
  12509. %@AS@%     write( old, "This goes to stdout first\r\n", 27 );
  12510. %@AS@%     if( ( new = fopen( "data", "w" ) ) == NULL )
  12511. %@AS@%     {
  12512. %@AS@%        puts( "Can't open file 'data'\n" );
  12513. %@AS@%        exit( 1 );
  12514. %@AS@%     }
  12515. %@AS@%  
  12516. %@AS@%     /* stdout now refers to file "data" */
  12517. %@AS@%     if( -1 == dup2( fileno( new ), 1 ) )
  12518. %@AS@%     {
  12519. %@AS@%        perror( "Can't dup2 stdout" );
  12520. %@AS@%        exit( 1 );
  12521. %@AS@%     }
  12522. %@AS@%     puts( "This goes to file 'data'\r\n" );
  12523. %@AS@%  
  12524. %@AS@%     /* Flush stdout stream buffer so it goes to correct file */
  12525. %@AS@%     fflush( stdout );
  12526. %@AS@%     fclose( new );
  12527. %@AS@%  
  12528. %@AS@%     /* Restore original stdout */
  12529. %@AS@%     dup2( old, 1 );
  12530. %@AS@%     puts( "This goes to stdout\n" );
  12531. %@AS@%     puts( "The file 'data' contains:" );
  12532. %@AS@%     system( "type data" );
  12533. %@AS@%  }%@AE@%%@NL@%
  12534. %@NL@%
  12535. %@NL@%
  12536. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  12537. %@NL@%
  12538. %@AS@%  
  12539. %@AS@%  
  12540. %@AS@%  This goes to stdout first
  12541. %@AS@%  This goes to stdout
  12542. %@AS@%  
  12543. %@AS@%  The file 'data' contains:
  12544. %@AS@%  This goes to file 'data' %@AE@%%@NL@%
  12545. %@NL@%
  12546. %@NL@%
  12547. %@NL@%
  12548. %@NL@%
  12549. %@QR:ecvt@%%@NL@%
  12550. %@2@%%@CR:C6A00820427 @%%@AB@%ecvt%@AE@%%@EH@%%@NL@%
  12551. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12552. %@NL@%
  12553. %@NL@%
  12554. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  12555. %@NL@%
  12556. Converts a %@AB@%double%@AE@% number to a string.  %@NL@%
  12557. %@NL@%
  12558. %@CR:C6A00820428 @%%@CR:C6A00820429 @%%@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  12559.  
  12560. %@AS@%  char *ecvt( double value, int count, int *dec, int *sign );%@AE@%%@NL@%
  12561. %@NL@%
  12562. %@AI@%value%@AE@%                             Number to be converted
  12563.  
  12564. %@AI@%count%@AE@%                             Number of digits stored
  12565.  
  12566. %@AI@%dec%@AE@%                               Stored decimal-point position
  12567.  
  12568. %@AI@%sign%@AE@%                              Sign of converted number
  12569.  
  12570. %@NL@%
  12571. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12572. %@NL@%
  12573. The %@AB@%ecvt%@AE@% function converts a floating-point number to a character string.
  12574. The %@AI@%value%@AE@% argument is the floating-point number to be converted. The %@AB@%ecvt%@AE@%
  12575. function stores up to %@AI@%count%@AE@% digits of %@AI@%value%@AE@% as a string and appends a null
  12576. character (%@AB@%'\0'%@AE@%). If the number of digits in %@AI@%value%@AE@% exceeds %@AI@%count,%@AE@% the
  12577. low-order digit is rounded. If there are fewer than %@AI@%count%@AE@% digits, the string
  12578. is padded with zeros. %@CR:C6A00820430 @%%@CR:C6A00820431 @%  %@NL@%
  12579. %@NL@%
  12580. Only digits are stored in the string. The position of the decimal point and
  12581. the sign of %@AI@%value%@AE@% can be obtained from %@AI@%dec%@AE@% and %@AI@%sign%@AE@% after the call. The %@AI@%dec%@AE@%
  12582. argument points to an integer value giving the position of the decimal point
  12583. with respect to the beginning of the string. A 0 or negative integer value
  12584. indicates that the decimal point lies to the left of the first digit. The
  12585. %@AI@%sign%@AE@% argument points to an integer indicating the sign of the converted
  12586. number. If the integer value is 0, the number is positive. Otherwise, the
  12587. number is negative.  %@NL@%
  12588. %@NL@%
  12589. The %@AB@%ecvt%@AE@% and %@AB@%fcvt%@AE@% functions use a single statically allocated buffer for the
  12590. conversion. Each call to one of these routines destroys the result of the
  12591. previous call.  %@NL@%
  12592. %@NL@%
  12593. %@NL@%
  12594. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12595. %@NL@%
  12596. The %@AB@%ecvt%@AE@% function returns a pointer to the string of digits. There is no
  12597. error return.  %@NL@%
  12598. %@NL@%
  12599. %@NL@%
  12600. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12601. %@NL@%
  12602.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  12603. %@NL@%
  12604. %@NL@%
  12605. %@NL@%
  12606. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12607. %@NL@%
  12608. %@AB@%atof%@AE@%, %@AB@%atoi%@AE@%, %@AB@%atol%@AE@%, %@AB@%fcvt%@AE@%, %@AB@%gcvt%@AE@%  %@NL@%
  12609. %@NL@%
  12610. %@NL@%
  12611. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12612. %@NL@%
  12613. %@AS@%  /* ECVT.C: This program uses ecvt to convert a floating-point
  12614. %@AS@%   * number to a character string.
  12615. %@AS@%   */
  12616. %@AS@%  
  12617. %@AS@%  #include <stdlib.h>
  12618. %@AS@%  #include <stdio.h>
  12619. %@AS@%  
  12620. %@AS@%  void main()
  12621. %@AS@%  {
  12622. %@AS@%     int     decimal, sign;
  12623. %@AS@%     char    *buffer;
  12624. %@AS@%     int     precision = 10;
  12625. %@AS@%     double  source = 3.1415926535;
  12626. %@AS@%  
  12627. %@AS@%     buffer = ecvt( source, precision, &decimal, &sign );
  12628. %@AS@%     printf( "source: %2.10f   buffer: '%s'  decimal: %d   sign: %d\n",
  12629. %@AS@%             source, buffer, decimal, sign );
  12630. %@AS@%  }%@AE@%%@NL@%
  12631. %@NL@%
  12632. %@NL@%
  12633. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  12634. %@NL@%
  12635. %@AS@%  
  12636. %@AS@%  
  12637. %@AS@%  source: 3.1415926535   buffer: '3141592654'  decimal: 1   sign: 0 %@AE@%%@NL@%
  12638. %@NL@%
  12639. %@NL@%
  12640. %@NL@%
  12641. %@NL@%
  12642. %@QR:_ellipse@%%@NL@%
  12643. %@2@%%@CR:C6A00830432 @%%@AB@%_ellipse Functions%@AE@%%@EH@%%@NL@%
  12644. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12645. %@NL@%
  12646. %@NL@%
  12647. %@3@%%@AB@%Description%@CR:C6A00830433 @% %@CR:C6A00830434 @% %@CR:C6A00830435 @%%@AE@%%@EH@%%@NL@%
  12648. %@NL@%
  12649. Draw ellipses.  %@NL@%
  12650. %@NL@%
  12651. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  12652. %@NL@%
  12653. %@AS@%  short _far _ellipse( short control, short x1, short y1, short x2, short y2
  12654. %@AS@%  );%@AE@%%@NL@%
  12655. %@NL@%
  12656. %@AS@%  short _far _ellipse_w( short control, double wx1, double wy1, double wx2, 
  12657. %@AS@%  double wy2 );%@AE@%%@NL@%
  12658. %@NL@%
  12659. %@AS@%  short _far _ellipse_wxy( short control, struct _wxycoord _far *pwxy1, 
  12660. %@AS@%  struct _wxycoord _far *pwxy2 );%@AE@%%@NL@%
  12661. %@NL@%
  12662. %@AI@%control%@AE@%                           Fill flag
  12663.  
  12664. %@AI@%x1%@AE@%, %@AI@%y1%@AE@%                            Upper-left corner of bounding rectangle
  12665.  
  12666. %@AI@%x2%@AE@%, %@AI@%y2%@AE@%                            Lower-right corner of bounding rectangle
  12667.  
  12668. %@AI@%wx1%@AE@%, %@AI@%wy1%@AE@%                          Upper-left corner of bounding rectangle
  12669.  
  12670. %@AI@%wx2%@AE@%, %@AI@%wy2%@AE@%                          Lower-right corner of bounding rectangle
  12671.  
  12672. %@AI@%pwxy1%@AE@%                             Upper-left corner of bounding rectangle
  12673.  
  12674. %@AI@%pwxy2%@AE@%                             Lower-right corner of bounding rectangle
  12675.  
  12676. %@NL@%
  12677. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12678. %@NL@%
  12679. The %@AB@%_ellipse%@AE@% functions draw ellipses or circles. The borders are drawn in
  12680. the current color. In the %@AB@%_ellipse%@AE@% function, the center of the ellipse is
  12681. the center of the bounding rectangle defined by the view-coordinate points
  12682. (%@AI@%x1%@AE@%, %@AI@%y1%@AE@%) and (%@AI@%x2%@AE@%, %@AI@%y2%@AE@%).  %@NL@%
  12683. %@NL@%
  12684. In the %@AB@%_ellipse_w%@AE@% function, the center of the ellipse is the center of the
  12685. bounding rectangle defined by the window-coordinate points (%@AI@%wx1%@AE@%, %@AI@%wy1%@AE@%) and
  12686. (%@AI@%wx2%@AE@%, %@AI@%wy2%@AE@%).  %@NL@%
  12687. %@NL@%
  12688. In the %@AB@%_ellipse_wxy%@AE@% function, the center of the ellipse is the center of the
  12689. bounding rectangle defined by the window-coordinate pairs (%@AI@%pwxy1%@AE@%) and
  12690. (%@AI@%pwxy2%@AE@%).  %@NL@%
  12691. %@NL@%
  12692. If the bounding-rectangle arguments define a point or a vertical or
  12693. horizontal line, no figure is drawn.  %@NL@%
  12694. %@NL@%
  12695. The %@AI@%control%@AE@% argument can be one of the following manifest constants:  %@NL@%
  12696. %@NL@%
  12697. %@AB@%Constant%@AE@%                          %@AB@%Action%@AE@%
  12698. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12699. %@AB@%_GFILLINTERIOR%@AE@%                    Fills the ellipse using the current fill
  12700.                                   mask
  12701.  
  12702. %@AB@%_GBORDER%@AE@%                          Does not fill the ellipse
  12703.  
  12704. The control option given by %@AB@%_GFILLINTERIOR%@AE@% is equivalent to a subsequent
  12705. call to the %@AB@%_floodfill%@AE@% function, using the center of the ellipse as the
  12706. starting point and the current color (set by %@AB@%_setcolor%@AE@%) as the boundary
  12707. color.  %@NL@%
  12708. %@NL@%
  12709. %@NL@%
  12710. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12711. %@NL@%
  12712. The %@AB@%_ellipse%@AE@% functions return a nonzero value if the ellipse is drawn
  12713. successfully; otherwise, they return 0.  %@NL@%
  12714. %@NL@%
  12715. %@NL@%
  12716. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12717. %@NL@%
  12718.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  12719. %@NL@%
  12720. %@NL@%
  12721. %@NL@%
  12722. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12723. %@NL@%
  12724. %@AB@%_arc%@AE@% functions,  %@AB@%_floodfill%@AE@%,  %@AB@%_grstatus%@AE@%,  %@AB@%_lineto%@AE@% functions,  %@AB@%_pie%@AE@%
  12725. functions, %@AB@%_polygon%@AE@% functions,  %@AB@%_rectangle%@AE@% functions,  %@AB@%_setcolor%@AE@%,%@AB@% %@AE@%
  12726. %@AB@%_setfillmask%@AE@%  %@NL@%
  12727. %@NL@%
  12728. %@NL@%
  12729. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12730. %@NL@%
  12731. %@AS@%  /* ELLIPSE.C: This program draws a simple ellipse. */
  12732. %@AS@%  
  12733. %@AS@%  #include <conio.h>
  12734. %@AS@%  #include <stdlib.h>
  12735. %@AS@%  #include <graph.h>
  12736. %@AS@%  
  12737. %@AS@%  void main()
  12738. %@AS@%  {
  12739. %@AS@%     /* Find a valid graphics mode. */
  12740. %@AS@%     if( !_setvideomode( _MAXRESMODE ) )
  12741. %@AS@%        exit( 1 );
  12742. %@AS@%  
  12743. %@AS@%     _ellipse( _GFILLINTERIOR, 80, 50, 240, 150 );
  12744. %@AS@%  
  12745. %@AS@%     /* Strike any key to clear screen. */
  12746. %@AS@%     getch();
  12747. %@AS@%     _setvideomode( _DEFAULTMODE );
  12748. %@AS@%  } %@AE@%%@NL@%
  12749. %@NL@%
  12750. %@NL@%
  12751. %@NL@%
  12752. %@NL@%
  12753. %@QR:_enable@%%@NL@%
  12754. %@2@%%@CR:C6A00840436 @%%@AB@%_enable%@AE@%%@EH@%%@NL@%
  12755. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12756. %@NL@%
  12757. %@NL@%
  12758. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  12759. %@NL@%
  12760. Enables interrupts.  %@NL@%
  12761. %@NL@%
  12762. %@CR:C6A00840437 @%%@CR:C6A00840438 @%%@AS@%  #include <dos.h>%@AE@%%@NL@%
  12763. %@NL@%
  12764. %@AS@%  void _enable( void );%@AE@%%@NL@%
  12765. %@NL@%
  12766. %@NL@%
  12767. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12768. %@NL@%
  12769. The %@AB@%_enable%@AE@% routine enables interrupts by executing an 8086 %@AB@%STI%@AE@% machine
  12770. instruction.  %@NL@%
  12771. %@NL@%
  12772. %@NL@%
  12773. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12774. %@NL@%
  12775. None.  %@NL@%
  12776. %@NL@%
  12777. %@NL@%
  12778. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12779. %@NL@%
  12780.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  12781. %@NL@%
  12782. %@NL@%
  12783. %@NL@%
  12784. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12785. %@NL@%
  12786. %@AB@%_disable%@AE@%  %@NL@%
  12787. %@NL@%
  12788. %@NL@%
  12789. %@NL@%
  12790. %@NL@%
  12791. %@QR:_endthread@%%@NL@%
  12792. %@2@%%@CR:C6A00850439 @%%@AB@%_endthread%@AE@%%@EH@%%@NL@%
  12793. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12794. %@NL@%
  12795. %@NL@%
  12796. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  12797. %@NL@%
  12798. Terminates an OS/2 thread.  %@NL@%
  12799. %@NL@%
  12800. %@CR:C6A00850440 @%%@CR:C6A00850441 @%%@AB@%#include <process.h>%@AE@%              Multithread version of PROCESS.H
  12801.  
  12802. %@AS@%  void _far _endthread( void );%@AE@%%@NL@%
  12803. %@NL@%
  12804. %@NL@%
  12805. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  12806. %@NL@%
  12807. The %@AB@%_endthread%@AE@% function terminates a thread created by %@AB@%_beginthread%@AE@%.  %@NL@%
  12808. %@NL@%
  12809. Because threads terminate automatically, the%@AB@% _endthread%@AE@% function is normally
  12810. not required. It is used to terminate a thread conditionally.  %@NL@%
  12811. %@NL@%
  12812. The OS/2 function %@AB@%DosExit%@AE@% should not be used to terminate threads created by
  12813. the %@AB@%_beginthread%@AE@% function. If %@AB@%DosExit%@AE@% is used, the results are
  12814. unpredictable.%@CR:C6A00850442 @%%@CR:C6A00850443 @%  %@NL@%
  12815. %@NL@%
  12816. %@NL@%
  12817. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12818. %@NL@%
  12819. None.  %@NL@%
  12820. %@NL@%
  12821. %@NL@%
  12822. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12823. %@NL@%
  12824.  ANSI   DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  12825. %@NL@%
  12826. %@NL@%
  12827. %@NL@%
  12828. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12829. %@NL@%
  12830. %@AB@%_beginthread%@AE@%  %@NL@%
  12831. %@NL@%
  12832. %@NL@%
  12833. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12834. %@NL@%
  12835. See the example for %@AB@%_beginthread%@AE@%.  %@NL@%
  12836. %@NL@%
  12837. %@NL@%
  12838. %@NL@%
  12839. %@NL@%
  12840. %@QR:eof@%%@NL@%
  12841. %@2@%%@CR:C6A00860444 @%%@AB@%eof%@AE@%%@EH@%%@NL@%
  12842. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12843. %@NL@%
  12844. %@NL@%
  12845. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  12846. %@NL@%
  12847. Tests for end-of-file.  %@NL@%
  12848. %@NL@%
  12849. %@CR:C6A00860445 @%%@CR:C6A00860446 @%%@CR:C6A00860447 @%%@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  12850.  
  12851. %@AS@%  int eof( int handle );%@AE@%%@NL@%
  12852. %@NL@%
  12853. %@AI@%handle%@AE@%                            Handle referring to open file
  12854.  
  12855. %@NL@%
  12856. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12857. %@NL@%
  12858. The %@AB@%eof%@AE@% function determines whether the end of the file associated with
  12859. %@AI@%handle%@AE@% has been reached.  %@NL@%
  12860. %@NL@%
  12861. %@NL@%
  12862. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  12863. %@NL@%
  12864. The %@AB@%eof%@AE@% function returns the value 1 if the current position is end-of-file,
  12865. or 0 if it is not. A return value of -1 indicates an error; in this case,
  12866. %@AB@%errno%@AE@% is set to %@AB@%EBADF%@AE@%, indicating an invalid file handle.  %@NL@%
  12867. %@NL@%
  12868. %@NL@%
  12869. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  12870. %@NL@%
  12871.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  12872. %@NL@%
  12873. %@NL@%
  12874. %@NL@%
  12875. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  12876. %@NL@%
  12877. %@AB@%clearerr%@AE@%, %@AB@%feof%@AE@%, %@AB@%ferror%@AE@%, %@AB@%perror%@AE@%  %@NL@%
  12878. %@NL@%
  12879. %@NL@%
  12880. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  12881. %@NL@%
  12882. %@AS@%  /* EOF.C: This program reads data from a file ten bytes at a time
  12883. %@AS@%   * until the end of the file is reached or an error is encountered.
  12884. %@AS@%   */
  12885. %@AS@%  
  12886. %@AS@%  #include <io.h>
  12887. %@AS@%  #include <fcntl.h>
  12888. %@AS@%  #include <stdio.h>
  12889. %@AS@%  #include <stdlib.h>
  12890. %@AS@%  
  12891. %@AS@%  void main()
  12892. %@AS@%  {
  12893. %@AS@%     int  fh, count, total = 0;
  12894. %@AS@%     char buf[10];
  12895. %@AS@%  
  12896. %@AS@%     if( (fh = open( "eof.c", O_RDONLY )) == - 1 )
  12897. %@AS@%        exit( 1 );%@AE@%%@NL@%
  12898. %@NL@%
  12899. %@AS@%  /* Cycle until end of file reached: */
  12900. %@AS@%     while( !eof( fh ) )
  12901. %@AS@%     {
  12902. %@AS@%        /* Attempt to read in 10 bytes: */
  12903. %@AS@%        if( (count = read( fh, buf, 10 )) == -1 )
  12904. %@AS@%        {
  12905. %@AS@%           perror( "Read error" );
  12906. %@AS@%           break;
  12907. %@AS@%        }
  12908. %@AS@%  
  12909. %@AS@%        /* Total up actual bytes read */
  12910. %@AS@%        total += count;
  12911. %@AS@%     }
  12912. %@AS@%     printf( "Number of bytes read = %d\n", total );
  12913. %@AS@%     close( fh );
  12914. %@AS@%  }%@AE@%%@NL@%
  12915. %@NL@%
  12916. %@NL@%
  12917. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  12918. %@NL@%
  12919. %@AS@%  
  12920. %@AS@%  
  12921. %@AS@%  Number of bytes read = 715 %@AE@%%@NL@%
  12922. %@NL@%
  12923. %@NL@%
  12924. %@NL@%
  12925. %@NL@%
  12926. %@QR:exec@%%@NL@%
  12927. %@2@%%@CR:C6A00870448 @%%@AB@%exec Functions%@AE@%%@EH@%%@NL@%
  12928. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12929. %@NL@%
  12930. %@NL@%
  12931. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  12932. %@NL@%
  12933. Load and execute new child processes.  %@NL@%
  12934. %@NL@%
  12935. %@CR:C6A00870449 @%%@CR:C6A00870450 @%%@CR:C6A00870451 @%%@AB@%#include <process.h>%@AE@%              Required only for function declarations
  12936.  
  12937. %@AS@%  int execl( char *cmdname, char *arg0, ... char *argn, NULL );%@AE@%%@NL@%
  12938. %@NL@%
  12939. %@AS@%  int execle( char *cmdname, char *arg0, ... char *argn, NULL, 
  12940. %@AS@%  char **envp );%@AE@%%@NL@%
  12941. %@NL@%
  12942. %@AS@%  int execlp( char *cmdname, char *arg0, ... char *argn, NULL  );%@AE@%%@NL@%
  12943. %@NL@%
  12944. %@AS@%  int execlpe( char *cmdname, char *arg0, ... char *argn, NULL, 
  12945. %@AS@%  char **envp  );%@AE@%%@NL@%
  12946. %@NL@%
  12947. %@AS@%  int execv( char *cmdname, char **argv );%@AE@%%@NL@%
  12948. %@NL@%
  12949. %@AS@%  int execve( char *cmdname, char **argv, char **envp );%@AE@%%@NL@%
  12950. %@NL@%
  12951. %@AS@%  int execvp( char *cmdname, char **argv );%@AE@%%@NL@%
  12952. %@NL@%
  12953. %@AS@%  int execvpe( char *cmdname, char **argv, char **envp );%@AE@%%@NL@%
  12954. %@NL@%
  12955. %@AI@%cmdname%@AE@%                           Path name of file to be executed
  12956.  
  12957. %@AI@%arg0, ... argn%@AE@%                    List of pointers to arguments
  12958.  
  12959. %@AI@%argv%@AE@%                              Array of pointers to arguments
  12960.  
  12961. %@AI@%envp%@AE@%                              Array of pointers to environment 
  12962.                                   settings
  12963.  
  12964. %@NL@%
  12965. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  12966. %@NL@%
  12967. The %@AB@%exec%@AE@% functions load and execute new child processes. When the call is
  12968. successful in DOS, the child process is placed in the memory previously
  12969. occupied by the calling process. Under OS/2, calling an %@AB@%exec%@AE@% function is
  12970. equivalent to calling the corresponding function with the %@AB@%P_NOWAITO%@AE@% argument
  12971. specified, followed by a call to the %@AB@%exit%@AE@% function. Sufficient memory must
  12972. be available for loading and executing the child process.  %@NL@%
  12973. %@NL@%
  12974. All of the %@AB@%exec%@AE@% functions use the same operating system function. The
  12975. letter(s) at the end of the function name determine the specific variation,
  12976. as shown in the following list:  %@NL@%
  12977. %@NL@%
  12978. %@AB@%Letter%@AE@%                            %@AB@%Variation%@AE@%
  12979. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  12980. %@AB@%e%@AE@%                                 An array of pointers to environment 
  12981.                                   arguments is explicitly passed to the 
  12982.                                   child process.
  12983.  
  12984. %@AB@%l%@AE@%                                 Command-line arguments are passed 
  12985.                                   individually to the %@AB@%exec%@AE@% function.
  12986.  
  12987. %@AB@%p%@AE@%                                 Uses the PATH environment variable to 
  12988.                                   find the file to be 
  12989.                                   executed.
  12990.  
  12991. %@AB@%v%@AE@%                                 Command-line arguments are passed to the
  12992.                                   %@AB@%exec%@AE@% function as an array of pointers.
  12993.  
  12994. The %@AI@%cmdname%@AE@% argument specifies the file to be executed as the child process.
  12995. It can specify a full path (from the root), a partial path (from the current
  12996. working directory), or just a file name. If %@AI@%cmdname%@AE@% does not have a
  12997. file-name extension or does not end with a period (.), the %@AB@%exec%@AE@% function
  12998. searches for the named file; if the search is unsuccessful, it tries the
  12999. same base name, first with the extension .COM, then with the extension .EXE.
  13000. If %@AI@%cmdname%@AE@% has an extension, only that extension is used in the search. If
  13001. %@AI@%cmdname%@AE@% ends with a period, the %@AB@%exec%@AE@% calls search for %@AI@%cmdname%@AE@% with no
  13002. extension. The %@AB@%execlp%@AE@%, %@AB@%execlpe%@AE@%, %@AB@%execvp%@AE@%, and %@AB@%execvpe%@AE@% routines search for
  13003. %@AI@%cmdname%@AE@% (using the same procedures) in the directories specified by the PATH
  13004. environment variable.  %@NL@%
  13005. %@NL@%
  13006. If %@AI@%cmdname%@AE@% contains a drive specifier or any slashes (i.e., if it is a
  13007. relative path name), the %@AB@%exec%@AE@% call searches only for the specified file and
  13008. no path searching is done.  %@NL@%
  13009. %@NL@%
  13010. Arguments are passed to the new process by giving one or more pointers to
  13011. character strings as arguments in the %@AB@%exec%@AE@% call. These character strings
  13012. form the argument list for the child process. The combined length of the
  13013. strings forming the argument list for the new process must not exceed 128
  13014. bytes (in real mode only). The terminating null character (%@AB@%'\0'%@AE@%) for each
  13015. string is not included in the count, but space characters (inserted
  13016. automatically to separate the arguments) are counted.  %@NL@%
  13017. %@NL@%
  13018. The argument pointers can be passed as separate arguments (%@AB@%execl%@AE@%, %@AB@%execle%@AE@%,
  13019. %@AB@%execlp%@AE@%, and %@AB@%execlpe%@AE@%) or as an array of pointers (%@AB@%execv%@AE@%, %@AB@%execve%@AE@%, %@AB@%execvp%@AE@%, and
  13020. %@AB@%execvpe%@AE@%). At least one argument, %@AI@%arg0%@AE@%, must be passed to the child process;
  13021. this argument is %@AI@%argv%@AE@%[0] of the child process. Usually, this argument is a
  13022. copy of the %@AI@%cmdname%@AE@% argument. (A different value will not produce an error.)
  13023. Under versions of DOS earlier than 3.0, the passed value of %@AI@%arg0%@AE@% is not
  13024. available for use in the child process. However, under OS/2 and under DOS
  13025. versions 3.0 and later, %@AI@%cmdname%@AE@% is available as %@AI@%arg0%@AE@%.  %@NL@%
  13026. %@NL@%
  13027. The %@AB@%execl%@AE@%, %@AB@%execle%@AE@%, %@AB@%execlp%@AE@%, and %@AB@%execlpe%@AE@% calls are typically used when the
  13028. number of arguments is known in advance. The argument %@AI@%arg0%@AE@% is usually a
  13029. pointer to %@AI@%cmdname%@AE@%. The arguments %@AI@%arg1%@AE@% through %@AI@%argn%@AE@% point to the character
  13030. strings forming the new argument list. A null pointer must follow %@AI@%argn%@AE@% to
  13031. mark the end of the argument list.  %@NL@%
  13032. %@NL@%
  13033. The %@AB@%execv%@AE@%, %@AB@%execve%@AE@%, %@AB@%execvp%@AE@%, and %@AB@%execvpe%@AE@% calls are useful when the number of
  13034. arguments to the new process is variable. Pointers to the arguments are
  13035. passed as an array, %@AI@%argv%@AE@%. The argument %@AI@%argv%@AE@%[0] is usually a pointer to
  13036. %@AI@%cmdname%@AE@%. The arguments %@AI@%argv%@AE@%[1] through %@AI@%argv%@AE@%[%@AI@%n%@AE@%] point to the character
  13037. strings forming the new argument list. The argument %@AI@%argv%@AE@%[%@AI@%n%@AE@%+1] must be a %@AB@%NULL
  13038. %@AB@%%@AE@%pointer to mark the end of the argument list.  %@NL@%
  13039. %@NL@%
  13040. Files that are open when an %@AB@%exec%@AE@% call is made remain open in the new
  13041. process. In the %@AB@%execl%@AE@%, %@AB@%execlp%@AE@%, %@AB@%execv%@AE@%, and %@AB@%execvp%@AE@% calls, the child process
  13042. inherits the environment of the parent. The %@AB@%execle%@AE@%, %@AB@%execlpe%@AE@%, %@AB@%execve%@AE@%, and
  13043. %@AB@%execvpe%@AE@% calls allow the user to alter the environment for the child process
  13044. by passing a list of environment settings through the %@AI@%envp%@AE@% argument. The
  13045. argument %@AI@%envp%@AE@% is an array of character pointers, each element of which
  13046. (except for the final element) points to a null-terminated string defining
  13047. an environment variable. Such a string usually has the form  %@NL@%
  13048. %@NL@%
  13049. %@AB@%NAME%@AE@%=%@AI@%value%@AE@%  %@NL@%
  13050. %@NL@%
  13051. where %@AB@%NAME%@AE@% is the name of an environment variable and %@AI@%value%@AE@% is the string
  13052. value to which that variable is set. (Note that %@AI@%value%@AE@% is not enclosed in
  13053. double quotation marks.) The final element of the %@AI@%envp%@AE@% array should be %@AB@%NULL%@AE@%.
  13054. When %@AI@%envp%@AE@% itself is %@AB@%NULL%@AE@%, the child process inherits the environment
  13055. settings of the parent process.  %@NL@%
  13056. %@NL@%
  13057. A program executed with one of the %@AB@%exec%@AE@% family of functions is always loaded
  13058. into memory as if the "maximum allocation" field in the program's .EXE file
  13059. header is set to the default value of 0FFFFH. You can use the EXEMOD utility
  13060. to change the maximum allocation field of a program; however, such a program
  13061. invoked with one of the %@AB@%exec%@AE@% functions may behave differently from a program
  13062. invoked directly from the operating-system command line or with one of the
  13063. %@AB@%spawn%@AE@% functions.  %@NL@%
  13064. %@NL@%
  13065. The %@AB@%exec%@AE@% calls do not preserve the translation modes of open files. If the
  13066. child process must use files inherited from the parent, the %@AB@%setmode%@AE@% routine
  13067. should be used to set the translation mode of these files to the desired
  13068. mode.  %@NL@%
  13069. %@NL@%
  13070. You must explicitly flush (using %@AB@%fflush%@AE@% or %@AB@%flushall%@AE@%) or close any stream
  13071. prior to the %@AB@%exec%@AE@% function call.  %@NL@%
  13072. %@NL@%
  13073. Signal settings are not preserved in child processes that are created by
  13074. calls to %@AB@%exec%@AE@% routines. The signal settings are reset to the default in the
  13075. child process.  %@NL@%
  13076. %@NL@%
  13077. %@NL@%
  13078. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13079. %@NL@%
  13080. The %@AB@%exec%@AE@% functions do not normally return to the calling process. If an %@AB@%exec%@AE@%
  13081. function returns, an error has occurred and the return value is -1. The
  13082. %@AB@%errno%@AE@% variable is set to one of the following values:  %@NL@%
  13083. %@NL@%
  13084. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  13085. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13086. %@AB@%E2BIG%@AE@%                             The argument list exceeds 128 bytes, or 
  13087.                                   the space required for the environment 
  13088.                                   information exceeds 32K.
  13089.  
  13090. %@AB@%EACCES%@AE@%                            The specified file has a locking or 
  13091.                                   sharing violation
  13092.                                   (OS/2, and DOS versions 3.0 or later).
  13093.  
  13094. %@AB@%EMFILE%@AE@%                            Too many files open (the specified file 
  13095.                                   must be opened to determine whether it 
  13096.                                   is executable).
  13097.  
  13098. %@AB@%ENOENT%@AE@%                            File or path name not found.
  13099.  
  13100. %@AB@%ENOEXEC%@AE@%                           The specified file is not executable or 
  13101.                                   has an invalid
  13102.                                   executable-file format.
  13103.  
  13104. %@AB@%ENOMEM%@AE@%                            Not enough memory is available to 
  13105.                                   execute the child process; or the 
  13106.                                   available memory has been corrupted; or 
  13107.                                   an invalid block exists, indicating that
  13108.                                   the parent process was not allocated 
  13109.                                   properly.
  13110.  
  13111. %@NL@%
  13112. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13113. %@NL@%
  13114.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13115. %@NL@%
  13116. %@NL@%
  13117. Because of differences in DOS versions 2.0 and 2.1, child processes
  13118. generated by the %@AB@%exec%@AE@% family of functions (or by the equivalent %@AB@%spawn%@AE@%
  13119. functions with the %@AB@%P_OVERLAY%@AE@% argument) may cause fatal system errors when
  13120. they exit. If you are running DOS 2.0 or 2.1, you must upgrade to DOS
  13121. version 3.0 or later to use these functions.  %@NL@%
  13122. %@NL@%
  13123. Bound programs cannot use the %@AB@%exec%@AE@% family of functions in real mode.  %@NL@%
  13124. %@NL@%
  13125. %@NL@%
  13126. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13127. %@NL@%
  13128. %@AB@%abort%@AE@%, %@AB@%atexit%@AE@%, %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, %@AB@%onexit%@AE@%, %@AB@%spawn%@AE@% functions, %@AB@%system%@AE@%  %@NL@%
  13129. %@NL@%
  13130. %@NL@%
  13131. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13132. %@NL@%
  13133. %@AS@%  /* EXEC.C: This program accepts a number in the range 1 through 8 from the
  13134. %@AS@%   * command line. Based on the number it receives, it executes one of the
  13135. %@AS@%   * eight different procedures that spawn the process named child. For
  13136. %@AS@%   * some of these procedures, the child.exe file must be in the same
  13137. %@AS@%   * directory; for others, it need only be in the same path.
  13138. %@AS@%   */
  13139. %@AS@%  
  13140. %@AS@%  #include <stdio.h>
  13141. %@AS@%  #include <process.h>
  13142. %@AS@%  
  13143. %@AS@%  char *my_env[] = {
  13144. %@AS@%                "THIS=environment will be",
  13145. %@AS@%                "PASSED=to child.exe by the",
  13146. %@AS@%                "EXECLE=and",
  13147. %@AS@%                "EXECLPE=and",
  13148. %@AS@%                "EXECVE=and",
  13149. %@AS@%                "EXECVPE=functions",
  13150. %@AS@%                NULL
  13151. %@AS@%                };
  13152. %@AS@%  
  13153. %@AS@%  void main( int argc, char *argv[] )
  13154. %@AS@%  {
  13155. %@AS@%     char *args[4];
  13156. %@AS@%     int result;
  13157. %@AS@%  
  13158. %@AS@%     args[0] = "child";     /* Set up parameters to send */
  13159. %@AS@%     args[1] = "execv??";
  13160. %@AS@%     args[2] = "two";
  13161. %@AS@%     args[3] = NULL;%@AE@%%@NL@%
  13162. %@NL@%
  13163. %@AS@%  switch( argv[1][0] )   /* Based on first letter of argument */
  13164. %@AS@%     {
  13165. %@AS@%        case '1':
  13166. %@AS@%           execl( argv[2], argv[2], "execl", "two", NULL );
  13167. %@AS@%           break;
  13168. %@AS@%        case '2':
  13169. %@AS@%           execle( argv[2], argv[2], "execle", "two", NULL, my_env );
  13170. %@AS@%           break;
  13171. %@AS@%        case '3':
  13172. %@AS@%           execlp( argv[2], argv[2], "execlp", "two", NULL );
  13173. %@AS@%           break;
  13174. %@AS@%        case '4':
  13175. %@AS@%           execlpe( argv[2], argv[2], "execlpe", "two", NULL, my_env );
  13176. %@AS@%           break;
  13177. %@AS@%        case '5':
  13178. %@AS@%           execv( argv[2], args );
  13179. %@AS@%           break;
  13180. %@AS@%        case '6':
  13181. %@AS@%           execve( argv[2], args, my_env );
  13182. %@AS@%           break;
  13183. %@AS@%        case '7':
  13184. %@AS@%           execvp( argv[2], args );
  13185. %@AS@%           break;
  13186. %@AS@%        case '8':
  13187. %@AS@%           execvpe( argv[2], args, my_env );
  13188. %@AS@%           break;
  13189. %@AS@%        default:
  13190. %@AS@%           printf( "SYNTAX: EXEC <1-8> <childprogram>\n" );
  13191. %@AS@%           exit( 1 );
  13192. %@AS@%     }
  13193. %@AS@%     printf( "Process was not spawned.\n" );
  13194. %@AS@%     printf( "Program 'child' was not found." );
  13195. %@AS@%  } %@AE@%%@NL@%
  13196. %@NL@%
  13197. %@NL@%
  13198. %@NL@%
  13199. %@NL@%
  13200. %@QR:exit@%%@QR:_exit@%%@NL@%
  13201. %@2@%%@CR:C6A00880452 @%%@AB@%exit, _exit%@AE@%%@EH@%%@NL@%
  13202. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13203. %@NL@%
  13204. %@NL@%
  13205. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  13206. %@NL@%
  13207. Terminate the calling process after cleanup (%@AB@%exit%@AE@%) or immediately (%@AB@% _exit%@AE@%).
  13208. %@NL@%
  13209. %@NL@%
  13210. %@CR:C6A00880453 @%%@CR:C6A00880454 @%%@AB@%#include <process.h>%@AE@%              Required only for function declarations
  13211.  
  13212. %@AB@%#include <stdlib.h>%@AE@%               Use either PROCESS.H or STDLIB.H
  13213.  
  13214. %@AS@%  void exit( int status );%@AE@%%@NL@%
  13215. %@NL@%
  13216. %@AS@%  void _exit( int status );%@AE@%%@NL@%
  13217. %@NL@%
  13218. %@AI@%status%@AE@%                            Exit status
  13219.  
  13220. %@NL@%
  13221. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13222. %@NL@%
  13223. The %@AB@%exit%@AE@% and %@AB@%_exit%@AE@% functions terminate the calling process. The %@AB@%exit%@AE@%
  13224. function first calls, in LIFO (last-in-first-out) order, the functions
  13225. registered by %@AB@%atexit%@AE@% and %@AB@%onexit%@AE@%, then flushes all file buffers before
  13226. terminating the process. The %@AB@%_exit%@AE@% function terminates the process without
  13227. processing %@AB@%atexit%@AE@% or %@AB@%onexit%@AE@% functions or flushing stream buffers. The %@AI@%status%@AE@%
  13228. value is typically set to 0 to indicate a normal exit and set to some other
  13229. value to indicate an error.%@CR:C6A00880455 @%  %@NL@%
  13230. %@NL@%
  13231. Although the %@AB@%exit%@AE@% and %@AB@%_exit%@AE@% calls do not return a value, the low-order byte
  13232. of %@AI@%status%@AE@% is made available to the waiting parent process, if one exists,
  13233. after the calling process exits. The %@AI@%status%@AE@% value is available to the
  13234. operating-system batch command ERRORLEVEL.  %@NL@%
  13235. %@NL@%
  13236. The behavior of the %@AB@%exit%@AE@%, %@AB@%_exit%@AE@%, %@AB@%_cexit%@AE@%, and %@AB@%_c_exit%@AE@% functions is as
  13237. follows:  %@NL@%
  13238. %@NL@%
  13239. %@AB@%Function%@AE@%                          %@AB@%Action%@AE@%
  13240. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13241. %@AB@%exit%@AE@%                              Performs complete C library termination 
  13242.                                   procedures, terminates the process, and 
  13243.                                   exits with the supplied status code.
  13244.  
  13245. %@AB@%_exit%@AE@%                             Performs "quick" C library termination 
  13246.                                   procedures, terminates the process, and 
  13247.                                   exits with the supplied status code.
  13248.  
  13249. %@AB@%_cexit%@AE@%                            Performs complete C library termination 
  13250.                                   procedures and returns to caller, but 
  13251.                                   does not terminate the process.
  13252.  
  13253. %@AB@%_c_exit%@AE@%                           Performs "quick" C library termination 
  13254.                                   procedures and returns to caller, but 
  13255.                                   does not terminate the process.
  13256.  
  13257. %@NL@%
  13258. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13259. %@NL@%
  13260. None.  %@NL@%
  13261. %@NL@%
  13262. %@NL@%
  13263. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13264. %@NL@%
  13265. %@AB@%exit%@AE@%  %@NL@%
  13266. %@NL@%
  13267. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13268. %@NL@%
  13269. %@NL@%
  13270. %@AB@%_exit%@AE@%  %@NL@%
  13271. %@NL@%
  13272.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  13273. %@NL@%
  13274. %@NL@%
  13275. %@NL@%
  13276. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13277. %@NL@%
  13278. %@AB@%abort%@AE@%, %@AB@%atexit%@AE@%, %@AB@%_cexit%@AE@%, %@AB@%exec%@AE@% functions, %@AB@%onexit%@AE@%, %@AB@%spawn%@AE@% functions, %@AB@%system%@AE@%  %@NL@%
  13279. %@NL@%
  13280. %@NL@%
  13281. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13282. %@NL@%
  13283. %@AS@%  /* EXITER.C: This program prompts the user for a yes or no and returns
  13284. %@AS@%   * a DOS error code of 1 if the user answers Y or y; otherwise it
  13285. %@AS@%   * returns 0. The error code could be tested in a batch file.
  13286. %@AS@%   */
  13287. %@AS@%  
  13288. %@AS@%  #include <conio.h>
  13289. %@AS@%  #include <stdlib.h>
  13290. %@AS@%  
  13291. %@AS@%  void main()
  13292. %@AS@%  {
  13293. %@AS@%     char  ch;
  13294. %@AS@%  
  13295. %@AS@%     cputs( "Yes or no? " );
  13296. %@AS@%     ch = getch();
  13297. %@AS@%     cputs( "\r\n" );
  13298. %@AS@%     if( toupper( ch ) == 'Y' )
  13299. %@AS@%        exit( 1 );
  13300. %@AS@%     else
  13301. %@AS@%        exit( 0 );
  13302. %@AS@%  }%@AE@%%@NL@%
  13303. %@NL@%
  13304. %@NL@%
  13305. %@NL@%
  13306. %@NL@%
  13307. %@QR:exp@%%@QR:expl@%%@NL@%
  13308. %@2@%%@CR:C6A00890456 @%%@AB@%exp, expl%@AE@%%@EH@%%@NL@%
  13309. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13310. %@NL@%
  13311. %@NL@%
  13312. %@3@%%@AB@%Description%@CR:C6A00890457 @%%@CR:C6A00890458 @%%@CR:C6A00890459 @% %@CR:C6A00890460 @%%@AE@%%@EH@%%@NL@%
  13313. %@NL@%
  13314. Calculate the exponential.  %@NL@%
  13315. %@NL@%
  13316. %@AS@%  #include <math.h>%@AE@%%@NL@%
  13317. %@NL@%
  13318. %@AS@%  double exp( double x );%@AE@%%@NL@%
  13319. %@NL@%
  13320. %@AS@%  long double expl( long double x );%@AE@%%@NL@%
  13321. %@NL@%
  13322. %@AI@%x%@AE@%                                 Floating-point value
  13323.  
  13324. %@NL@%
  13325. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13326. %@NL@%
  13327. The %@AB@%exp%@AE@% and %@AB@%expl%@AE@% functions return the exponential function of their
  13328. floating-point arguments (%@AI@%x%@AE@%).  %@NL@%
  13329. %@NL@%
  13330. The %@AB@%expl%@AE@% function is the 80-bit counterpart; it uses an 80-bit, 10-byte
  13331. coprocessor form of arguments and return values. See the reference page on
  13332. the long double functions for more details on this data type.  %@NL@%
  13333. %@NL@%
  13334. %@NL@%
  13335. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13336. %@NL@%
  13337. These functions return ex%@AI@%.%@AE@% The functions return %@AB@%HUGE_VAL%@AE@% on overflow and set
  13338. %@AB@%errno%@AE@% to %@AB@%ERANGE%@AE@%; on underflow, they return 0 but do not set %@AB@%errno%@AE@%.  %@NL@%
  13339. %@NL@%
  13340. %@NL@%
  13341. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13342. %@NL@%
  13343. %@AB@%exp%@AE@%  %@NL@%
  13344. %@NL@%
  13345. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13346. %@NL@%
  13347. %@NL@%
  13348. %@AB@%expl%@AE@%  %@NL@%
  13349. %@NL@%
  13350.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  13351. %@NL@%
  13352. %@NL@%
  13353. %@NL@%
  13354. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13355. %@NL@%
  13356. %@AB@%log%@AE@% functions  %@NL@%
  13357. %@NL@%
  13358. %@NL@%
  13359. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13360. %@NL@%
  13361. %@AS@%  /* EXP.C */
  13362. %@AS@%  #include <math.h>
  13363. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  13364. %@NL@%
  13365. %@AS@%  void main()
  13366. %@AS@%  {
  13367. %@AS@%     double x = 2.302585093, y;
  13368. %@AS@%  
  13369. %@AS@%     y = exp( x );
  13370. %@AS@%     printf( "exp( %f ) = %f\n", x, y );
  13371. %@AS@%  }%@AE@%%@NL@%
  13372. %@NL@%
  13373. %@NL@%
  13374. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  13375. %@NL@%
  13376. %@AS@%  
  13377. %@AS@%  
  13378. %@AS@%  exp( 2.302585 ) = 10.000000%@AE@%%@NL@%
  13379. %@NL@%
  13380. %@NL@%
  13381. %@NL@%
  13382. %@NL@%
  13383. %@QR:_expand@%%@NL@%
  13384. %@2@%%@CR:C6A00900461 @%%@AB@%_expand Functions%@AE@%%@EH@%%@NL@%
  13385. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13386. %@NL@%
  13387. %@NL@%
  13388. %@3@%%@AB@%Description%@CR:C6A00900462 @%%@CR:C6A00900463 @% %@CR:C6A00900464 @%%@CR:C6A00900465 @%%@CR:C6A00900466 @%%@CR:C6A00900467 @%%@AE@%%@EH@%%@NL@%
  13389. %@NL@%
  13390. Changes the size of a memory block.  %@NL@%
  13391. %@NL@%
  13392. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  13393.  
  13394. %@AS@%  void *_expand( void *memblock, size_t size );%@AE@%%@NL@%
  13395. %@NL@%
  13396. %@AS@%  void _based( void ) *_bexpand( _segment seg, void _based( void )
  13397. %@AS@%  *memblock, 
  13398. %@AS@%  size_t size );%@AE@%%@NL@%
  13399. %@NL@%
  13400. %@AS@%  void _far *_fexpand( void _far *memblock, size_t size );%@AE@%%@NL@%
  13401. %@NL@%
  13402. %@AS@%  void _near *_nexpand( void _near *memblock, size_t size );%@AE@%%@NL@%
  13403. %@NL@%
  13404. %@AI@%memblock%@AE@%                          Pointer to previously allocated memory 
  13405.                                   block
  13406.  
  13407. %@AI@%size%@AE@%                              New size in bytes
  13408.  
  13409. %@AI@%seg%@AE@%                               Value of base segment
  13410.  
  13411. %@NL@%
  13412. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13413. %@NL@%
  13414. The %@AB@%_expand%@AE@% family of functions changes the size of a previously allocated
  13415. memory block by attempting to expand or contract the block without moving
  13416. its location in the heap. The %@AI@%memblock%@AE@% argument points to the beginning of
  13417. the block. The %@AI@%size%@AE@% argument gives the new size of the block, in bytes. The
  13418. contents of the block are unchanged up to the shorter of the new and old
  13419. sizes.  %@NL@%
  13420. %@NL@%
  13421. The %@AI@%memblock%@AE@% argument can also point to a block that has been freed, as long
  13422. as there has been no intervening call to %@AB@%calloc%@AE@%, %@AB@%_expand%@AE@%, %@AB@%malloc%@AE@%, or
  13423. %@AB@%realloc%@AE@%. If %@AI@%memblock%@AE@% points to a freed block, the block remains free after a
  13424. call to one of the %@AB@%_expand%@AE@% functions.  %@NL@%
  13425. %@NL@%
  13426. The %@AI@%seg%@AE@% argument is the segment address of the %@AB@%_based%@AE@% heap.  %@NL@%
  13427. %@NL@%
  13428. In large data models (compact-, large-, and huge-model programs), %@AB@%_expand%@AE@%
  13429. maps to %@AB@%_fexpand%@AE@%. In small data models ( tiny-, small-, and medium-model
  13430. programs), %@AB@%expand%@AE@% maps to %@AB@%_nexpand%@AE@%.  %@NL@%
  13431. %@NL@%
  13432. The various %@AB@%_expand%@AE@% functions change the size of the storage block in the
  13433. data segments shown in the list below:  %@NL@%
  13434. %@NL@%
  13435. %@AB@%Function%@AE@%                          %@AB@%Data Segment%@AE@%
  13436. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13437. %@AB@%_expand%@AE@%                           Depends on data model of program
  13438.  
  13439. %@AB@%_bexpand%@AE@%                          Based heap specified by %@AI@%seg%@AE@%, or in all 
  13440.                                   based heaps if %@AI@%seg%@AE@%
  13441.                                   is zero
  13442.  
  13443. %@AB@%_fexpand%@AE@%                          Far heap (outside default data segment)
  13444.  
  13445. %@AB@%_nexpand%@AE@%                          Near heap (inside default data segment)
  13446.  
  13447. %@NL@%
  13448. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13449. %@NL@%
  13450. The %@AB@%_expand%@AE@% family of functions returns a %@AB@%void%@AE@% pointer to the reallocated
  13451. memory block. Unlike %@AB@%realloc%@AE@%, %@AB@%_expand%@AE@% cannot move a block to change its
  13452. size. This means the %@AI@%memblock%@AE@% argument to %@AB@%_expand%@AE@% is the same as the return
  13453. value if there is sufficient memory available to expand the block without
  13454. moving it.  %@NL@%
  13455. %@NL@%
  13456. With the exception of the %@AB@%_bexpand%@AE@% function, these functions return %@AB@%NULL%@AE@% if
  13457. there is insufficient memory available to expand the block to the given size
  13458. without moving it. The %@AB@%_bexpand%@AE@% function returns %@AB@%_NULLOFF%@AE@% if insufficient
  13459. memory is available. The item pointed to by %@AI@%memblock%@AE@% will have been expanded
  13460. as much as possible in its current location.  %@NL@%
  13461. %@NL@%
  13462. The storage space pointed to by the return value is guaranteed to be
  13463. suitably aligned for storage of any type of object. The new size of the item
  13464. can be checked with the %@AB@%_msize%@AE@% function. To get a pointer to a type other
  13465. than %@AB@%void%@AE@%, use a type cast on the return value.  %@NL@%
  13466. %@NL@%
  13467. %@NL@%
  13468. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13469. %@NL@%
  13470.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  13471. %@NL@%
  13472. %@NL@%
  13473. %@NL@%
  13474. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13475. %@NL@%
  13476. %@AB@%calloc%@AE@% functions, %@AB@%free%@AE@% functions, %@AB@%malloc%@AE@% functions, %@AB@%_msize%@AE@% functions,
  13477. %@AB@%realloc%@AE@% functions  %@NL@%
  13478. %@NL@%
  13479. %@NL@%
  13480. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13481. %@NL@%
  13482. %@AS@%  /* EXPAND.C */
  13483. %@AS@%  #include <stdio.h>
  13484. %@AS@%  #include <malloc.h>
  13485. %@AS@%  #include <stdlib.h>
  13486. %@AS@%  
  13487. %@AS@%  void main()
  13488. %@AS@%  {
  13489. %@AS@%     char *bufchar;
  13490. %@AS@%  
  13491. %@AS@%     printf( "Allocate a 512 element buffer\n" );
  13492. %@AS@%     if( (bufchar = (char *)calloc( 512, sizeof( char ) )) == NULL )
  13493. %@AS@%        exit( 1 );
  13494. %@AS@%     printf( "Allocated %d bytes at %Fp\n",
  13495. %@AS@%           _msize( bufchar ), (void _far *)bufchar );
  13496. %@AS@%  
  13497. %@AS@%     if( (bufchar = (char *)_expand( bufchar, 1024 )) == NULL )
  13498. %@AS@%        printf( "Can't expand" );
  13499. %@AS@%     else
  13500. %@AS@%        printf( "Expanded block to %d bytes at %Fp\n",
  13501. %@AS@%              _msize( bufchar ), (void _far *)bufchar );
  13502. %@AS@%  
  13503. %@AS@%     /* Free memory */
  13504. %@AS@%     free( bufchar );
  13505. %@AS@%     exit( 0 );
  13506. %@AS@%  }%@AE@%%@NL@%
  13507. %@NL@%
  13508. %@NL@%
  13509. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  13510. %@NL@%
  13511. %@AS@%  
  13512. %@AS@%  
  13513. %@AS@%  Allocate a 512 element buffer
  13514. %@AS@%  Allocated 512 bytes at 0067:142A
  13515. %@AS@%  Expanded block to 1024 bytes at 0067:142A%@AE@%%@NL@%
  13516. %@NL@%
  13517. %@NL@%
  13518. %@NL@%
  13519. %@NL@%
  13520. %@QR:fabs@%%@QR:fabsl@%%@NL@%
  13521. %@2@%%@CR:C6A00910468 @%%@AB@%fabs, fabsl%@AE@%%@EH@%%@NL@%
  13522. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13523. %@NL@%
  13524. %@NL@%
  13525. %@3@%%@AB@%Description%@CR:C6A00910469 @%%@CR:C6A00910470 @%%@CR:C6A00910471 @% %@CR:C6A00910472 @%%@AE@%%@EH@%%@NL@%
  13526. %@NL@%
  13527. Calculate the absolute value of their floating-point arguments.  %@NL@%
  13528. %@NL@%
  13529. %@AS@%  #include <math.h>%@AE@%%@NL@%
  13530. %@NL@%
  13531. %@AS@%  double fabs( double x );%@AE@%%@NL@%
  13532. %@NL@%
  13533. %@AS@%  long double fabsl( long double x );%@AE@%%@NL@%
  13534. %@NL@%
  13535. %@AI@%x%@AE@%                                 Floating-point value
  13536.  
  13537. %@NL@%
  13538. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13539. %@NL@%
  13540. The %@AB@%fabs%@AE@% and %@AB@%fabsl%@AE@% functions calculate the absolute value of their
  13541. floating-point arguments.  %@NL@%
  13542. %@NL@%
  13543. The %@AB@%fabsl%@AE@% function is the 80-bit counterpart; it uses an 80-bit, 10-byte
  13544. coprocessor form of arguments and return values. See the reference page on
  13545. the long double functions for more details on this data type.  %@NL@%
  13546. %@NL@%
  13547. %@NL@%
  13548. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13549. %@NL@%
  13550. These functions return the absolute value of their arguments. There is no
  13551. error return.  %@NL@%
  13552. %@NL@%
  13553. %@NL@%
  13554. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13555. %@NL@%
  13556. %@AB@%fabs%@AE@%  %@NL@%
  13557. %@NL@%
  13558. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13559. %@NL@%
  13560. %@NL@%
  13561. %@AB@%fabsl%@AE@%  %@NL@%
  13562. %@NL@%
  13563.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  13564. %@NL@%
  13565. %@NL@%
  13566. %@NL@%
  13567. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13568. %@NL@%
  13569. %@AB@%abs%@AE@%, %@AB@%cabs%@AE@%, %@AB@%labs%@AE@%  %@NL@%
  13570. %@NL@%
  13571. %@NL@%
  13572. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13573. %@NL@%
  13574. %@AS@%  /* ABS.C: This program computes and displays the absolute values of
  13575. %@AS@%   * several numbers.
  13576. %@AS@%   */
  13577. %@AS@%  
  13578. %@AS@%  #include <stdio.h>
  13579. %@AS@%  #include <math.h>
  13580. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  13581. %@NL@%
  13582. %@AS@%  void main()
  13583. %@AS@%  {
  13584. %@AS@%     int    ix = -4, iy;
  13585. %@AS@%     long   lx = -41567L, ly;
  13586. %@AS@%     double dx = -3.141593, dy;
  13587. %@AS@%  
  13588. %@AS@%     iy = abs( ix );
  13589. %@AS@%     printf( "The absolute value of %d is %d\n", ix, iy);
  13590. %@AS@%  
  13591. %@AS@%     ly = labs( lx );
  13592. %@AS@%     printf( "The absolute value of %ld is %ld\n", lx, ly);
  13593. %@AS@%  
  13594. %@AS@%     dy = fabs( dx );
  13595. %@AS@%     printf( "The absolute value of %f is %f\n", dx, dy );
  13596. %@AS@%  }%@AE@%%@NL@%
  13597. %@NL@%
  13598. %@NL@%
  13599. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  13600. %@NL@%
  13601. %@AS@%  
  13602. %@AS@%  
  13603. %@AS@%  The absolute value of -4 is 4
  13604. %@AS@%  The absolute value of -41567 is 41567
  13605. %@AS@%  The absolute value of -3.141593 is 3.141593%@AE@%%@NL@%
  13606. %@NL@%
  13607. %@NL@%
  13608. %@NL@%
  13609. %@NL@%
  13610. %@QR:fclose@%%@QR:fcloseall@%%@NL@%
  13611. %@2@%%@CR:C6A00920473 @%%@AB@%fclose, fcloseall%@AE@%%@EH@%%@NL@%
  13612. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13613. %@NL@%
  13614. %@NL@%
  13615. %@3@%%@AB@%Description%@CR:C6A00920474 @%%@CR:C6A00920475 @% %@CR:C6A00920476 @%%@AE@%%@EH@%%@NL@%
  13616. %@NL@%
  13617. Closes a stream (%@AB@%fclose%@AE@%) or closes all open streams (%@AB@%fcloseall%@AE@%).  %@NL@%
  13618. %@NL@%
  13619. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  13620. %@NL@%
  13621. %@AS@%  int fclose( FILE *stream );%@AE@%%@NL@%
  13622. %@NL@%
  13623. %@AS@%  int fcloseall( void );%@AE@%%@NL@%
  13624. %@NL@%
  13625. %@AI@%stream %@AE@%                           Pointer to %@AB@%FILE%@AE@% structure
  13626.  
  13627. %@NL@%
  13628. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13629. %@NL@%
  13630. The %@AB@%fclose%@AE@% function closes %@AI@%stream%@AE@%. The %@AB@%fcloseall%@AE@% function closes all open
  13631. streams except %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, %@AB@%stderr%@AE@% (and in DOS,%@AB@% stdaux%@AE@% and%@AB@% stdprn%@AE@%). It
  13632. also closes and deletes any temporary files created by %@AB@%tmpfile%@AE@%.  %@NL@%
  13633. %@NL@%
  13634. In both functions, all buffers associated with the stream are flushed prior
  13635. to closing. System-allocated buffers are released when the stream is closed.
  13636. Buffers assigned by the user with %@AB@%setbuf%@AE@% and %@AB@%setvbuf%@AE@% are not automatically
  13637. released.  %@NL@%
  13638. %@NL@%
  13639. %@NL@%
  13640. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13641. %@NL@%
  13642. The %@AB@%fclose%@AE@% function returns 0 if the stream is successfully closed. The
  13643. %@AB@%fcloseall%@AE@% function returns the total number of streams closed. Both
  13644. functions return %@AB@%EOF%@AE@% to indicate an error.  %@NL@%
  13645. %@NL@%
  13646. %@NL@%
  13647. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13648. %@NL@%
  13649. %@AB@%fclose%@AE@%  %@NL@%
  13650. %@NL@%
  13651. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13652. %@NL@%
  13653. %@NL@%
  13654. %@AB@%fcloseall  %@AE@%%@NL@%
  13655. %@NL@%
  13656.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  13657. %@NL@%
  13658. %@NL@%
  13659. %@NL@%
  13660. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13661. %@NL@%
  13662. %@AB@%close%@AE@%, %@AB@%fdopen%@AE@%, %@AB@%fflush%@AE@%, %@AB@%fopen%@AE@%, %@AB@%freopen%@AE@%  %@NL@%
  13663. %@NL@%
  13664. %@NL@%
  13665. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13666. %@NL@%
  13667. %@AS@%  /* FOPEN.C: This program opens files named "data" and "data2". It uses
  13668. %@AS@%   * fclose to close "data" and fcloseall to close all remaining files.
  13669. %@AS@%   */
  13670. %@AS@%  
  13671. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  13672. %@NL@%
  13673. %@AS@%  FILE *stream, *stream2;
  13674. %@AS@%  
  13675. %@AS@%  void main()
  13676. %@AS@%  {
  13677. %@AS@%     int numclosed;
  13678. %@AS@%  
  13679. %@AS@%     /* Open for read (will fail if 'data does not exist) */
  13680. %@AS@%     if( (stream  = fopen( "data", "r" )) == NULL )
  13681. %@AS@%        printf( "The file 'data' was not opened\n" );
  13682. %@AS@%     else
  13683. %@AS@%        printf( "The file 'data' was opened\n" );
  13684. %@AS@%  
  13685. %@AS@%     /* Open for write */
  13686. %@AS@%     if( (stream2 = fopen( "data2", "w+" )) == NULL )
  13687. %@AS@%        printf( "The file 'data2' was not opened\n" );
  13688. %@AS@%     else
  13689. %@AS@%        printf( "The file 'data2' was opened\n" );
  13690. %@AS@%  
  13691. %@AS@%     /* Close stream */
  13692. %@AS@%     if( fclose( stream ) )
  13693. %@AS@%        printf( "The file 'data' was not closed\n" );
  13694. %@AS@%  
  13695. %@AS@%     /* All other files are closed: */
  13696. %@AS@%     numclosed = fcloseall( );
  13697. %@AS@%     printf( "Number of files closed by fcloseall: %u\n", numclosed );
  13698. %@AS@%  }%@AE@%%@NL@%
  13699. %@NL@%
  13700. %@NL@%
  13701. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  13702. %@NL@%
  13703. %@AS@%  
  13704. %@AS@%  
  13705. %@AS@%  The file 'data' was opened
  13706. %@AS@%  The file 'data2' was opened
  13707. %@AS@%  Number of files closed by fcloseall: 1%@AE@%%@NL@%
  13708. %@NL@%
  13709. %@NL@%
  13710. %@NL@%
  13711. %@NL@%
  13712. %@QR:fcvt@%%@NL@%
  13713. %@2@%%@CR:C6A00930477 @%%@AB@%fcvt%@AE@%%@EH@%%@NL@%
  13714. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13715. %@NL@%
  13716. %@NL@%
  13717. %@3@%%@AB@%Description%@CR:C6A00930478 @%%@CR:C6A00930479 @% %@CR:C6A00930480 @% %@CR:C6A00930481 @%%@AE@%%@EH@%%@NL@%
  13718. %@NL@%
  13719. Converts a floating-point number to a string.  %@NL@%
  13720. %@NL@%
  13721. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  13722.  
  13723. %@AS@%  char *fcvt( double value, int count, int *dec, int *sign );%@AE@%%@NL@%
  13724. %@NL@%
  13725. %@AI@%value%@AE@%                             Number to be converted
  13726.  
  13727. %@AI@%count%@AE@%                             Number of digits after decimal point
  13728.  
  13729. %@AI@%dec%@AE@%                               Pointer to stored decimal-point position
  13730.  
  13731. %@AI@%sign%@AE@%                              Pointer to stored sign indicator
  13732.  
  13733. %@NL@%
  13734. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13735. %@NL@%
  13736. The %@AB@%fcvt%@AE@% function converts a floating-point number to a null-terminated
  13737. character string. The %@AI@%value%@AE@% argument is the floating-point number to be
  13738. converted. The %@AB@%fcvt%@AE@% function stores the digits of %@AI@%value%@AE@% as a string and
  13739. appends a null character (%@AB@%'\0'%@AE@%). The %@AI@%count%@AE@% argument specifies the number of
  13740. digits to be stored after the decimal point. Excess digits are rounded off
  13741. to %@AI@%count%@AE@% places. If there are fewer than %@AI@%count%@AE@% digits of precision, the
  13742. string is padded with zeros.  %@NL@%
  13743. %@NL@%
  13744. Only digits are stored in the string. The position of the decimal point and
  13745. the sign of %@AI@%value%@AE@% can be obtained from %@AI@%dec%@AE@% and %@AI@%sign %@AE@%after the call. The %@AI@%dec
  13746. %@AI@%%@AE@%argument points to an integer value; this integer value gives the position
  13747. of the decimal point with respect to the beginning of the string. A zero or
  13748. negative integer value indicates that the decimal point lies to the left of
  13749. the first digit. The argument %@AI@%sign%@AE@% points to an integer indicating the sign
  13750. of %@AI@%value%@AE@%. The integer is set to 0 if %@AI@%value%@AE@% is positive and is set to a
  13751. nonzero number if %@AI@%value%@AE@% is negative.  %@NL@%
  13752. %@NL@%
  13753. The %@AB@%ecvt %@AE@%and %@AB@%fcvt %@AE@%functions use a single statically allocated buffer for the
  13754. conversion. Each call to one of these routines destroys the results of the
  13755. previous call.  %@NL@%
  13756. %@NL@%
  13757. %@NL@%
  13758. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13759. %@NL@%
  13760. The %@AB@%fcvt%@AE@% function returns a pointer to the string of digits. There is no
  13761. error return.  %@NL@%
  13762. %@NL@%
  13763. %@NL@%
  13764. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13765. %@NL@%
  13766.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13767. %@NL@%
  13768. %@NL@%
  13769. %@NL@%
  13770. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13771. %@NL@%
  13772. %@AB@%atof%@AE@%, %@AB@%atoi%@AE@%, %@AB@%atol%@AE@%, %@AB@%ecvt%@AE@%, %@AB@%gcvt%@AE@%  %@NL@%
  13773. %@NL@%
  13774. %@NL@%
  13775. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13776. %@NL@%
  13777. %@AS@%  /* FCVT.C: This program converts the constant 3.1415926535 to a string and
  13778. %@AS@%   * sets the pointer *buffer to point to that string.
  13779. %@AS@%   */%@AE@%%@NL@%
  13780. %@NL@%
  13781. %@AS@%  #include <stdlib.h>
  13782. %@AS@%  #include <stdio.h>
  13783. %@AS@%  
  13784. %@AS@%  void main()
  13785. %@AS@%  {
  13786. %@AS@%     int  decimal, sign;
  13787. %@AS@%     char *buffer;
  13788. %@AS@%     double source = 3.1415926535;
  13789. %@AS@%  
  13790. %@AS@%     buffer = fcvt( source, 7, &decimal, &sign );
  13791. %@AS@%     printf( "source: %2.10f   buffer: '%s'   decimal: %d   sign: %d\n",
  13792. %@AS@%             source, buffer, decimal, sign );
  13793. %@AS@%  }%@AE@%%@NL@%
  13794. %@NL@%
  13795. %@NL@%
  13796. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  13797. %@NL@%
  13798. %@AS@%  
  13799. %@AS@%  
  13800. %@AS@%  source: 3.1415926535   buffer: '31415927'   decimal: 1   sign: 0%@AE@%%@NL@%
  13801. %@NL@%
  13802. %@NL@%
  13803. %@NL@%
  13804. %@NL@%
  13805. %@QR:fdopen@%%@NL@%
  13806. %@2@%%@CR:C6A00940482 @%%@AB@%fdopen%@AE@%%@EH@%%@NL@%
  13807. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13808. %@NL@%
  13809. %@NL@%
  13810. %@3@%%@AB@%Description%@CR:C6A00940483 @%%@CR:C6A00940484 @%%@CR:C6A00940485 @%%@AE@%%@EH@%%@NL@%
  13811. %@NL@%
  13812. Opens a stream using a handle.  %@NL@%
  13813. %@NL@%
  13814. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  13815. %@NL@%
  13816. %@AS@%  FILE *fdopen( int handle, char *mode );%@AE@%%@NL@%
  13817. %@NL@%
  13818. %@AI@%handle%@AE@%                            Handle referring to open file
  13819.  
  13820. %@AI@%mode%@AE@%                              Type of access permitted
  13821.  
  13822. %@NL@%
  13823. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13824. %@NL@%
  13825. The %@AB@%fdopen%@AE@% function associates an input/output stream with the file
  13826. identified by %@AI@%handle%@AE@%, thus allowing a file opened for "low-level" I/O to be
  13827. buffered and formatted. (See Section 2.7, "Input and Output," for an
  13828. explanation of stream I/O and low-level I/O.) The %@AI@%mode%@AE@% character string
  13829. specifies the type of access requested for the file, as shown below. The
  13830. following list gives the %@AI@%mode %@AE@%string used in the %@AB@%fopen%@AE@% and %@AB@%fdopen%@AE@% functions
  13831. and the corresponding %@AI@%oflag%@AE@% arguments used in the %@AB@%open%@AE@% and %@AB@%sopen%@AE@% functions.
  13832. A complete description of the %@AI@%mode%@AE@% string argument is given in the remarks
  13833. section of the %@AB@%fopen%@AE@% function. %@CR:C6A00940486 @%  %@NL@%
  13834. %@NL@%
  13835. %@AB@%Type String%@AE@%                       %@AB@%Equivalent Value for open/sopen%@AE@%
  13836. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13837. %@AB@%"r"%@AE@%                               %@AB@%O_RDONLY%@AE@%
  13838.  
  13839. %@AB@%"w"%@AE@%                               %@AB@%O_WRONLY%@AE@% (usually %@AB@%O_WRONLY | O_CREAT | %@AE@%
  13840.                                   %@AB@%O_TRUNC%@AE@%)
  13841.  
  13842. %@AB@%"a"%@AE@%                               %@AB@%O_WRONLY | O_APPEND%@AE@% (usually %@AB@%O_WRONLY | %@AE@%
  13843.                                   %@AB@%O_CREAT | O_APPEND%@AE@%)
  13844.  
  13845. %@AB@%"r+"%@AE@%                              %@AB@%O_RDWR%@AE@%
  13846.  
  13847. %@AB@%"w+"%@AE@%                              %@AB@%O_RDWR%@AE@% (usually %@AB@%O_RDWR | O_CREAT | %@AE@%
  13848.                                   %@AB@%O_TRUNC%@AE@%)
  13849.  
  13850. %@AB@%"a+"%@AE@%                              %@AB@%O_RDWR | O_APPEND%@AE@% (usually %@AB@%O_RDWR | %@AE@%
  13851.                                   %@AB@%O_APPEND | O_CREAT %@AE@%)
  13852.  
  13853. In addition to the values listed above, one of the following characters can
  13854. be included in the %@AI@%mode%@AE@% string to specify the translation mode for newlines.
  13855. These characters correspond to the constants used in the %@AB@%open%@AE@% and %@AB@%sopen%@AE@%
  13856. functions, as shown below: %@CR:C6A00940487 @%%@CR:C6A00940488 @%   %@NL@%
  13857. %@NL@%
  13858. %@AB@%Mode%@AE@%                              %@AB@%Equivalent Value for open/sopen%@AE@%
  13859. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13860. %@AB@%t%@AE@%                                 %@AB@%O_TEXT%@AE@%
  13861.  
  13862. %@AB@%b%@AE@%                                 %@AB@%O_BINARY%@AE@%
  13863.  
  13864. If %@AB@%t%@AE@% or %@AB@%b%@AE@% is not given in the %@AI@%mode%@AE@% string, the translation mode is defined
  13865. by the default-mode variable %@AB@%_fmode%@AE@%.  %@NL@%
  13866. %@NL@%
  13867. The %@AB@%t%@AE@% option is not part of the ANSI standard for %@AB@%fopen%@AE@% and %@AB@%fpopen%@AE@%, but is
  13868. instead a Microsoft extension and should not be used where ANSI portability
  13869. is desired.  %@NL@%
  13870. %@NL@%
  13871. %@NL@%
  13872. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13873. %@NL@%
  13874. The %@AB@%fdopen%@AE@% function returns a pointer to the open stream. A null pointer
  13875. value indicates an error.  %@NL@%
  13876. %@NL@%
  13877. %@NL@%
  13878. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13879. %@NL@%
  13880.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13881. %@NL@%
  13882. %@NL@%
  13883. %@NL@%
  13884. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13885. %@NL@%
  13886. %@AB@%dup%@AE@%, %@AB@%dup2%@AE@%, %@AB@%fclose%@AE@%, %@AB@%fcloseall%@AE@%, %@AB@%fopen%@AE@%, %@AB@%freopen%@AE@%, %@AB@%open%@AE@%  %@NL@%
  13887. %@NL@%
  13888. %@NL@%
  13889. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13890. %@NL@%
  13891. %@AS@%  /* FDOPEN.C: This program opens a file using low-level I/O, then uses
  13892. %@AS@%   * fdopen to switch to stream access. It counts the lines in the file.
  13893. %@AS@%   */
  13894. %@AS@%  
  13895. %@AS@%  #include <stdlib.h>
  13896. %@AS@%  #include <stdio.h>
  13897. %@AS@%  #include <fcntl.h>
  13898. %@AS@%  #include <io.h>
  13899. %@AS@%  
  13900. %@AS@%  void main()
  13901. %@AS@%  {
  13902. %@AS@%     FILE *stream;
  13903. %@AS@%     int  fh, count = 0;
  13904. %@AS@%     char inbuf[128];
  13905. %@AS@%  
  13906. %@AS@%     /* Open a file handle. */
  13907. %@AS@%     if( (fh = open( "fdopen.c", O_RDONLY )) == -1 )
  13908. %@AS@%        exit( 1 );
  13909. %@AS@%  
  13910. %@AS@%     /* Change handle access to stream access. */
  13911. %@AS@%     if( (stream = fdopen( fh, "r" )) == NULL )
  13912. %@AS@%        exit( 1 );
  13913. %@AS@%  
  13914. %@AS@%     while( fgets( inbuf, 128, stream ) != NULL )
  13915. %@AS@%        count++;%@AE@%%@NL@%
  13916. %@NL@%
  13917. %@AS@%  /* After fdopen, close with fclose, not close. */
  13918. %@AS@%     fclose( stream );
  13919. %@AS@%  
  13920. %@AS@%     printf( "Lines in file: %d\n", count );
  13921. %@AS@%  }%@AE@%%@NL@%
  13922. %@NL@%
  13923. %@NL@%
  13924. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  13925. %@NL@%
  13926. %@AS@%  
  13927. %@AS@%  
  13928. %@AS@%  Lines in file: 31%@AE@%%@NL@%
  13929. %@NL@%
  13930. %@NL@%
  13931. %@NL@%
  13932. %@NL@%
  13933. %@QR:feof@%%@NL@%
  13934. %@2@%%@CR:C6A00950489 @%%@AB@%feof%@AE@%%@EH@%%@NL@%
  13935. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  13936. %@NL@%
  13937. %@NL@%
  13938. %@3@%%@AB@%Description%@CR:C6A00950490 @%%@CR:C6A00950491 @% %@CR:C6A00950492 @%%@AE@%%@EH@%%@NL@%
  13939. %@NL@%
  13940. Tests for end-of-file on a stream.  %@NL@%
  13941. %@NL@%
  13942. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  13943. %@NL@%
  13944. %@AS@%  int feof( FILE *stream );%@AE@%%@NL@%
  13945. %@NL@%
  13946. %@AI@%stream%@AE@%                            Pointer to%@AB@% FILE structure%@AE@%
  13947.  
  13948. %@NL@%
  13949. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  13950. %@NL@%
  13951. The %@AB@%feof%@AE@% routine (implemented as a macro) determines whether the end of
  13952. %@AI@%stream%@AE@% has been reached. Once the end of the file is reached, read
  13953. operations return an end-of-file indicator until the stream is closed or
  13954. until %@AB@%rewind%@AE@%, %@AB@%fsetpos%@AE@%, %@AB@%fseek%@AE@%, or %@AB@%clearerr%@AE@% is called against it.  %@NL@%
  13955. %@NL@%
  13956. %@NL@%
  13957. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  13958. %@NL@%
  13959. The %@AB@%feof%@AE@% function returns a nonzero value after the first read operation
  13960. that attempts to read past the end of the file. It returns 0 if the current
  13961. position is not end-of-file. There is no error return.  %@NL@%
  13962. %@NL@%
  13963. %@NL@%
  13964. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  13965. %@NL@%
  13966. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  13967. %@NL@%
  13968. %@NL@%
  13969. %@NL@%
  13970. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  13971. %@NL@%
  13972. %@AB@%clearerr%@AE@%, %@AB@%eof%@AE@%, %@AB@%ferror%@AE@%, %@AB@%perror%@AE@%  %@NL@%
  13973. %@NL@%
  13974. %@NL@%
  13975. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  13976. %@NL@%
  13977. %@AS@%  /* FEOF.C: This program uses feof to indicate when it reaches the end
  13978. %@AS@%   * of the file FEOF.C. It also checks for errors with ferror.
  13979. %@AS@%   */
  13980. %@AS@%  
  13981. %@AS@%  #include <stdio.h>
  13982. %@AS@%  #include <stdlib.h>
  13983. %@AS@%  
  13984. %@AS@%  void main()
  13985. %@AS@%  {
  13986. %@AS@%     int  count, total = 0;
  13987. %@AS@%     char buffer[100];
  13988. %@AS@%     FILE *stream;
  13989. %@AS@%  
  13990. %@AS@%     if( (stream = fopen( "feof.c", "r" )) == NULL )
  13991. %@AS@%        exit( 1 );%@AE@%%@NL@%
  13992. %@NL@%
  13993. %@AS@%  /* Cycle until end of file reached: */
  13994. %@AS@%     while( !feof( stream ) )
  13995. %@AS@%     {
  13996. %@AS@%        /* Attempt to read in 10 bytes: */
  13997. %@AS@%        count = fread( buffer, sizeof( char ), 100, stream );
  13998. %@AS@%        if( ferror( stream ) )
  13999. %@AS@%        {
  14000. %@AS@%           perror( "Read error" );
  14001. %@AS@%           break;
  14002. %@AS@%        }
  14003. %@AS@%  
  14004. %@AS@%        /* Total up actual bytes read */
  14005. %@AS@%        total += count;
  14006. %@AS@%     }
  14007. %@AS@%     printf( "Number of bytes read = %d\n", total );
  14008. %@AS@%     fclose( stream );
  14009. %@AS@%  }%@AE@%%@NL@%
  14010. %@NL@%
  14011. %@NL@%
  14012. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14013. %@NL@%
  14014. %@AS@%  
  14015. %@AS@%  
  14016. %@AS@%  Number of bytes read = 697%@AE@%%@NL@%
  14017. %@NL@%
  14018. %@NL@%
  14019. %@NL@%
  14020. %@NL@%
  14021. %@QR:ferror@%%@NL@%
  14022. %@2@%%@CR:C6A00960493 @%%@AB@%ferror%@AE@%%@EH@%%@NL@%
  14023. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14024. %@NL@%
  14025. %@NL@%
  14026. %@3@%%@AB@%Description%@CR:C6A00960494 @%%@CR:C6A00960495 @%%@AE@%%@EH@%%@NL@%
  14027. %@NL@%
  14028. Tests for an error on a stream.  %@NL@%
  14029. %@NL@%
  14030. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14031. %@NL@%
  14032. %@AS@%  int ferror( FILE *stream );%@AE@%%@NL@%
  14033. %@NL@%
  14034. %@AI@%stream%@AE@%                            Pointer to%@AB@% FILE structure%@AE@%
  14035.  
  14036. %@NL@%
  14037. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14038. %@NL@%
  14039. The %@AB@%ferror%@AE@% routine (implemented as a macro) tests for a reading or writing
  14040. error on the file associated with %@AI@%stream%@AE@%. If an error has occurred, the
  14041. error indicator for the stream remains set until the stream is closed or
  14042. rewound, or until %@AB@%clearerr%@AE@% is called against it. %@CR:C6A00960496 @%  %@NL@%
  14043. %@NL@%
  14044. %@NL@%
  14045. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14046. %@NL@%
  14047. If no error has occurred on %@AI@%stream%@AE@%, %@AB@%ferror%@AE@% returns 0. Otherwise, it returns
  14048. a nonzero value.  %@NL@%
  14049. %@NL@%
  14050. %@NL@%
  14051. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14052. %@NL@%
  14053. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14054. %@NL@%
  14055. %@NL@%
  14056. %@NL@%
  14057. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14058. %@NL@%
  14059. %@AB@%clearerr%@AE@%, %@AB@%eof%@AE@%, %@AB@%feof%@AE@%, %@AB@%fopen%@AE@%, %@AB@%perror%@AE@%  %@NL@%
  14060. %@NL@%
  14061. %@NL@%
  14062. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14063. %@NL@%
  14064. %@AS@%  /* FEOF.C: This program uses feof to indicate when it reaches the end
  14065. %@AS@%   * of the file FEOF.C. It also checks for errors with ferror.
  14066. %@AS@%   */
  14067. %@AS@%  
  14068. %@AS@%  #include <stdio.h>
  14069. %@AS@%  #include <stdlib.h>
  14070. %@AS@%  
  14071. %@AS@%  void main()
  14072. %@AS@%  {
  14073. %@AS@%     int  count, total = 0;
  14074. %@AS@%     char buffer[100];
  14075. %@AS@%     FILE *stream;
  14076. %@AS@%  
  14077. %@AS@%     if( (stream = fopen( "feof.c", "r" )) == NULL )
  14078. %@AS@%        exit( 1 );%@AE@%%@NL@%
  14079. %@NL@%
  14080. %@AS@%  /* Cycle until end of file reached: */
  14081. %@AS@%     while( !feof( stream ) )
  14082. %@AS@%     {
  14083. %@AS@%        /* Attempt to read in 10 bytes: */
  14084. %@AS@%        count = fread( buffer, sizeof( char ), 100, stream );
  14085. %@AS@%        if( ferror( stream ) )
  14086. %@AS@%        {
  14087. %@AS@%           perror( "Read error" );
  14088. %@AS@%           break;
  14089. %@AS@%        }
  14090. %@AS@%  
  14091. %@AS@%        /* Total up actual bytes read */
  14092. %@AS@%        total += count;
  14093. %@AS@%     }
  14094. %@AS@%     printf( "Number of bytes read = %d\n", total );
  14095. %@AS@%     fclose( stream );
  14096. %@AS@%  }%@AE@%%@NL@%
  14097. %@NL@%
  14098. %@NL@%
  14099. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14100. %@NL@%
  14101. %@AS@%  
  14102. %@AS@%  
  14103. %@AS@%  Number of bytes read = 697%@AE@%%@NL@%
  14104. %@NL@%
  14105. %@NL@%
  14106. %@NL@%
  14107. %@NL@%
  14108. %@QR:fflush@%%@NL@%
  14109. %@2@%%@CR:C6A00970497 @%%@AB@%fflush%@AE@%%@EH@%%@NL@%
  14110. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14111. %@NL@%
  14112. %@NL@%
  14113. %@3@%%@AB@%Description%@CR:C6A00970498 @%%@CR:C6A00970499 @%%@CR:C6A00970500 @% %@CR:C6A00970501 @%%@AE@%%@EH@%%@NL@%
  14114. %@NL@%
  14115. Flushes a stream.  %@NL@%
  14116. %@NL@%
  14117. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14118. %@NL@%
  14119. %@AS@%  int fflush( FILE *stream );%@AE@%%@NL@%
  14120. %@NL@%
  14121. %@AI@%stream%@AE@%                            Pointer to%@AB@% FILE structure%@AE@%
  14122.  
  14123. %@NL@%
  14124. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14125. %@NL@%
  14126. If the file associated with %@AI@%stream%@AE@% is open for output, %@AB@%fflush%@AE@% writes to that
  14127. file the contents of the buffer associated with the stream. If the stream is
  14128. open for input, %@AB@%fflush%@AE@% clears the contents of the buffer. The %@AB@%fflush%@AE@%
  14129. function negates the effect of any prior call to %@AB@%ungetc%@AE@% against %@AI@%stream%@AE@%.  %@NL@%
  14130. %@NL@%
  14131. Buffers are automatically flushed when they are full, when the stream is
  14132. closed, or when a program terminates normally without closing the stream.  %@NL@%
  14133. %@NL@%
  14134. The stream remains open after the call. The %@AB@%fflush%@AE@% function has no effect on
  14135. an unbuffered stream.  %@NL@%
  14136. %@NL@%
  14137. %@NL@%
  14138. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14139. %@NL@%
  14140. The %@AB@%fflush%@AE@% function returns the value 0 if the buffer was successfully
  14141. flushed. The value 0 is also returned in cases in which the specified stream
  14142. has no buffer or is open for reading only. A return value of %@AB@%EOF%@AE@% indicates
  14143. an error.  %@NL@%
  14144. %@NL@%
  14145. %@NL@%
  14146. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14147. %@NL@%
  14148. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14149. %@NL@%
  14150. %@NL@%
  14151. %@NL@%
  14152. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14153. %@NL@%
  14154. %@AB@%fclose%@AE@%, %@AB@%flushall%@AE@%, %@AB@%setbuf%@AE@%  %@NL@%
  14155. %@NL@%
  14156. %@NL@%
  14157. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14158. %@NL@%
  14159. %@AS@%  /* FFLUSH.C */
  14160. %@AS@%  #include <stdio.h>
  14161. %@AS@%  #include <conio.h>
  14162. %@AS@%  
  14163. %@AS@%  void main()
  14164. %@AS@%  {
  14165. %@AS@%     int integer;
  14166. %@AS@%     char string[81];%@AE@%%@NL@%
  14167. %@NL@%
  14168. %@AS@%  /* Read each word as a string. */
  14169. %@AS@%     printf( "Enter a sentence of four words with scanf: " );
  14170. %@AS@%     for( integer = 0; integer < 4; integer++ )
  14171. %@AS@%     {
  14172. %@AS@%        scanf( "%s", string );
  14173. %@AS@%        printf( "%s\n", string );
  14174. %@AS@%     }
  14175. %@AS@%  
  14176. %@AS@%     /* You must flush the input buffer before using gets. */
  14177. %@AS@%     fflush( stdin );
  14178. %@AS@%     printf( "Enter the same sentence with gets: " );
  14179. %@AS@%     gets( string );
  14180. %@AS@%     printf( "%s\n", string );
  14181. %@AS@%  }%@AE@%%@NL@%
  14182. %@NL@%
  14183. %@NL@%
  14184. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14185. %@NL@%
  14186. %@AS@%  
  14187. %@AS@%  
  14188. %@AS@%  Enter a sentence of four words with scanf: This is a test
  14189. %@AS@%  This
  14190. %@AS@%  is
  14191. %@AS@%  a
  14192. %@AS@%  test
  14193. %@AS@%  Enter the same sentence with gets: This is a test
  14194. %@AS@%  This is a test%@AE@%%@NL@%
  14195. %@NL@%
  14196. %@NL@%
  14197. %@NL@%
  14198. %@NL@%
  14199. %@QR:fgetc@%%@QR:fgetchar@%%@NL@%
  14200. %@2@%%@CR:C6A00980502 @%%@AB@%fgetc, fgetchar%@AE@%%@EH@%%@NL@%
  14201. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14202. %@NL@%
  14203. %@NL@%
  14204. %@3@%%@AB@%Description%@CR:C6A00980503 @%%@CR:C6A00980504 @% %@CR:C6A00980505 @% %@CR:C6A00980506 @% %@CR:C6A00980507 @%%@CR:C6A00980508 @%%@AE@%%@EH@%%@NL@%
  14205. %@NL@%
  14206. Read a character from a stream (%@AB@%fgetc%@AE@%) or %@AB@%stdin (fgetchar%@AE@%).  %@NL@%
  14207. %@NL@%
  14208. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14209. %@NL@%
  14210. %@AS@%  int fgetc( FILE *stream );%@AE@%%@NL@%
  14211. %@NL@%
  14212. %@AS@%  int fgetchar( void ); %@AE@%%@NL@%
  14213. %@NL@%
  14214. %@AI@%stream %@AE@%                           Pointer to %@AB@%FILE%@AE@% structure
  14215.  
  14216. %@NL@%
  14217. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14218. %@NL@%
  14219. The %@AB@%fgetc%@AE@% function reads a single character from the current position of the
  14220. file associated with %@AI@%stream%@AE@%. The character is converted and returned as an%@AB@%
  14221. %@AB@%int%@AE@%. The function then increments the associated file pointer (if any) to
  14222. point to the next character. The %@AB@%fgetchar%@AE@% function is equivalent to
  14223. %@AB@%fgetc(stdin)%@AE@%.  %@NL@%
  14224. %@NL@%
  14225. The %@AB@%fgetc%@AE@% and %@AB@%fgetchar%@AE@% routines are identical to %@AB@%getc%@AE@% and %@AB@%getchar%@AE@%, but they
  14226. are functions rather than macros.  %@NL@%
  14227. %@NL@%
  14228. %@NL@%
  14229. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14230. %@NL@%
  14231. The %@AB@%fgetc%@AE@% and %@AB@%fgetchar%@AE@% functions return the character read. They return %@AB@%EOF%@AE@%
  14232. to indicate an error or end-of-file. Use %@AB@%feof%@AE@% or %@AB@%ferror%@AE@% to distinguish
  14233. between an error and an end-of-file condition.  %@NL@%
  14234. %@NL@%
  14235. %@NL@%
  14236. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14237. %@NL@%
  14238. %@AB@%fgetc%@AE@%  %@NL@%
  14239. %@NL@%
  14240. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14241. %@NL@%
  14242. %@NL@%
  14243. %@AB@%fgetchar%@AE@%  %@NL@%
  14244. %@NL@%
  14245.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14246. %@NL@%
  14247. %@NL@%
  14248. %@NL@%
  14249. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14250. %@NL@%
  14251. %@AB@%fputc%@AE@%, %@AB@%fputchar%@AE@%, %@AB@%getc%@AE@%, %@AB@%getchar%@AE@%  %@NL@%
  14252. %@NL@%
  14253. %@NL@%
  14254. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14255. %@NL@%
  14256. %@AS@%  /* FGETC.C: This program uses getc to read the first 80 input characters
  14257. %@AS@%   * (or until the end of input) and place them into a string named buffer.
  14258. %@AS@%   */
  14259. %@AS@%  
  14260. %@AS@%  #include <stdio.h>
  14261. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  14262. %@NL@%
  14263. %@AS@%  void main()
  14264. %@AS@%  {
  14265. %@AS@%     FILE *stream;
  14266. %@AS@%     char buffer[81];
  14267. %@AS@%     int  i, ch;
  14268. %@AS@%  
  14269. %@AS@%     /* Open file to read line from: */
  14270. %@AS@%     if( (stream = fopen( "fgetc.c", "r" )) == NULL )
  14271. %@AS@%        exit( 0 );
  14272. %@AS@%  
  14273. %@AS@%     /* Read in first 80 characters and place them in "buffer": */
  14274. %@AS@%     ch = fgetc( stream );
  14275. %@AS@%     for( i=0; (i < 80 ) && ( feof( stream ) == 0 ); i++ )
  14276. %@AS@%     {
  14277. %@AS@%        buffer[i] = ch;
  14278. %@AS@%        ch = fgetc( stream );
  14279. %@AS@%     }
  14280. %@AS@%     /* Add null to end string */
  14281. %@AS@%     buffer[i] = '\0';
  14282. %@AS@%     printf( "%s\n", buffer );
  14283. %@AS@%     fclose( stream );
  14284. %@AS@%  }%@AE@%%@NL@%
  14285. %@NL@%
  14286. %@NL@%
  14287. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14288. %@NL@%
  14289. %@AS@%  
  14290. %@AS@%  
  14291. %@AS@%  /* FGETC.C: This program uses getc to read the first 80 input characters
  14292. %@AS@%  /* (or%@AE@%%@NL@%
  14293. %@NL@%
  14294. %@AS@%  %@AE@%%@NL@%
  14295. %@NL@%
  14296. %@NL@%
  14297. %@NL@%
  14298. %@NL@%
  14299. %@QR:fgetpos@%%@NL@%
  14300. %@2@%%@CR:C6A00990509 @%%@AB@%fgetpos%@AE@%%@EH@%%@NL@%
  14301. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14302. %@NL@%
  14303. %@NL@%
  14304. %@3@%%@AB@%Description%@CR:C6A00990510 @%%@CR:C6A00990511 @% %@CR:C6A00990512 @%%@CR:C6A00990513 @% %@CR:C6A00990514 @%%@CR:C6A00990515 @%%@AE@%%@EH@%%@NL@%
  14305. %@NL@%
  14306. Gets a stream's file-position indicator.  %@NL@%
  14307. %@NL@%
  14308. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14309. %@NL@%
  14310. %@AS@%  int fgetpos( FILE *stream, fpos_t *pos );%@AE@%%@NL@%
  14311. %@NL@%
  14312. %@AI@%stream%@AE@%                            Target stream
  14313.  
  14314. %@AI@%pos%@AE@%                               Position-indicator storage
  14315.  
  14316. %@NL@%
  14317. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14318. %@NL@%
  14319. The %@AB@%fgetpos%@AE@% function gets the current value of the %@AI@%stream%@AE@% argument's
  14320. file-position indicator and stores it in the object pointed to by %@AI@%pos%@AE@%. The
  14321. %@AB@%fsetpos%@AE@% function can later use information stored in %@AI@%pos%@AE@% to reset the %@AI@%stream%@AE@%
  14322. argument's pointer to its position at the time %@AB@%fgetpos%@AE@% was called.  %@NL@%
  14323. %@NL@%
  14324. The %@AI@%pos %@AE@%value is stored in an internal format and is intended for use only
  14325. by the %@AB@%fgetpos%@AE@% and %@AB@%fsetpos%@AE@% functions.  %@NL@%
  14326. %@NL@%
  14327. %@NL@%
  14328. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14329. %@NL@%
  14330. If successful, the %@AB@%fgetpos%@AE@% function returns 0. On failure, it returns a
  14331. nonzero value and sets %@AB@%errno%@AE@% to one of the following manifest constants
  14332. (defined in STDIO.H):  %@NL@%
  14333. %@NL@%
  14334. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  14335. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14336. %@AB@%EBADF%@AE@%                             The specified stream is not a valid file
  14337.                                   handle or is not 
  14338.                                   accessible.
  14339.  
  14340. %@AB@%EINVAL%@AE@%                            The %@AI@%stream%@AE@% value is invalid.
  14341.  
  14342. %@NL@%
  14343. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14344. %@NL@%
  14345. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14346. %@NL@%
  14347. %@NL@%
  14348. %@NL@%
  14349. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14350. %@NL@%
  14351. %@AB@%fsetpos%@AE@%  %@NL@%
  14352. %@NL@%
  14353. %@NL@%
  14354. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14355. %@NL@%
  14356. %@AS@%  /* FGETPOS.C: This program opens a file and reads bytes at several
  14357. %@AS@%   * different locations.
  14358. %@AS@%   */
  14359. %@AS@%  
  14360. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14361. %@NL@%
  14362. %@AS@%  void main()
  14363. %@AS@%  {
  14364. %@AS@%     FILE   *stream;
  14365. %@AS@%     fpos_t pos;
  14366. %@AS@%     int    val;
  14367. %@AS@%     char   buffer[20];
  14368. %@AS@%  
  14369. %@AS@%     if( (stream = fopen( "fgetpos.c", "rb" )) == NULL )
  14370. %@AS@%        printf( "Trouble opening file\n" );
  14371. %@AS@%     else
  14372. %@AS@%     {
  14373. %@AS@%        /* Read some data and then check the position. */
  14374. %@AS@%        fread( buffer, sizeof( char ), 10, stream );
  14375. %@AS@%        if( fgetpos( stream, &pos ) != 0 )
  14376. %@AS@%           perror( "fgetpos error" );
  14377. %@AS@%        else
  14378. %@AS@%        {
  14379. %@AS@%           fread( buffer, sizeof( char ), 10, stream );
  14380. %@AS@%           printf( "10 bytes at byte %ld: %.10s\n", pos, buffer );
  14381. %@AS@%        }
  14382. %@AS@%  
  14383. %@AS@%        /* Set a new position and read more data */
  14384. %@AS@%        pos = 140;
  14385. %@AS@%        if( fsetpos( stream, &pos ) != 0 )
  14386. %@AS@%           perror( "fsetpos error" );
  14387. %@AS@%  
  14388. %@AS@%        fread( buffer, sizeof( char ), 10, stream );
  14389. %@AS@%           printf( "10 bytes at byte %ld: %.10s\n", pos, buffer );
  14390. %@AS@%  
  14391. %@AS@%        fclose( stream );
  14392. %@AS@%     }
  14393. %@AS@%  }%@AE@%%@NL@%
  14394. %@NL@%
  14395. %@NL@%
  14396. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14397. %@NL@%
  14398. %@AS@%  
  14399. %@AS@%  
  14400. %@AS@%  10 bytes at byte 10: .C: This p
  14401. %@AS@%  10 bytes at byte 140:   FILE   *%@AE@%%@NL@%
  14402. %@NL@%
  14403. %@NL@%
  14404. %@NL@%
  14405. %@NL@%
  14406. %@QR:fgets@%%@NL@%
  14407. %@2@%%@CR:C6A01000516 @%%@AB@%fgets%@AE@%%@EH@%%@NL@%
  14408. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14409. %@NL@%
  14410. %@NL@%
  14411. %@3@%%@AB@%Description%@CR:C6A01000517 @%%@CR:C6A01000518 @% %@CR:C6A01000519 @%%@CR:C6A01000520 @%%@CR:C6A01000521 @%%@AE@%%@EH@%%@NL@%
  14412. %@NL@%
  14413. Gets a string from a stream.  %@NL@%
  14414. %@NL@%
  14415. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14416. %@NL@%
  14417. %@AS@%  char *fgets( char *string, int n, FILE *stream );%@AE@%%@NL@%
  14418. %@NL@%
  14419. %@AI@%string%@AE@%                            Storage location for data
  14420.  
  14421. %@AI@%n%@AE@%                                 Number of characters stored
  14422.  
  14423. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE %@AE@%structure
  14424.  
  14425. %@NL@%
  14426. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14427. %@NL@%
  14428. The %@AB@%fgets%@AE@% function reads a string from the input %@AI@%stream%@AE@% argument and stores
  14429. it in %@AI@%string%@AE@%. Characters are read from the current stream position up to and
  14430. including the first newline character (%@AB@%'\n'%@AE@%), up to the end of the stream,
  14431. or until the number of characters read is equal to %@AI@%n%@AE@% - 1, whichever comes
  14432. first. The result is stored in %@AI@%string%@AE@%, and a null character (%@AB@%'\0'%@AE@%) is
  14433. appended. The newline character, if read, is included in the string. If %@AI@%n%@AE@% is
  14434. equal to 1, %@AI@%string%@AE@% is empty (""). The %@AB@%fgets%@AE@% function is similar to the %@AB@%gets%@AE@%
  14435. function; however, %@AB@%gets%@AE@% replaces the newline character with %@AB@%NULL%@AE@%.  %@NL@%
  14436. %@NL@%
  14437. %@NL@%
  14438. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14439. %@NL@%
  14440. If successful, the %@AB@%fgets%@AE@% function returns %@AI@%string%@AE@%. It returns %@AB@%NULL%@AE@% to
  14441. indicate either an error or end-of-file condition. Use %@AB@%feof%@AE@% or %@AB@%ferror%@AE@% to
  14442. determine whether an error occurred.  %@NL@%
  14443. %@NL@%
  14444. %@NL@%
  14445. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14446. %@NL@%
  14447. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14448. %@NL@%
  14449. %@NL@%
  14450. %@NL@%
  14451. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14452. %@NL@%
  14453. %@AB@%fputs%@AE@%, %@AB@%gets%@AE@%, %@AB@%puts%@AE@%  %@NL@%
  14454. %@NL@%
  14455. %@NL@%
  14456. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14457. %@NL@%
  14458. %@AS@%  /* FGETS.C: This program uses fgets to display a line from a file on the
  14459. %@AS@%   * screen.
  14460. %@AS@%   */
  14461. %@AS@%  
  14462. %@AS@%  #include <stdio.h>
  14463. %@AS@%  
  14464. %@AS@%  FILE *stream;
  14465. %@AS@%  
  14466. %@AS@%  void main()
  14467. %@AS@%  {
  14468. %@AS@%     char line[100], *result;%@AE@%%@NL@%
  14469. %@NL@%
  14470. %@AS@%  if( (stream = fopen( "fgets.c", "r" )) != NULL )
  14471. %@AS@%     {
  14472. %@AS@%        if( fgets( line, 100, stream ) == NULL)
  14473. %@AS@%           printf( "fgets error\n" );
  14474. %@AS@%        else
  14475. %@AS@%           printf( "%s", line);
  14476. %@AS@%        fclose( stream );
  14477. %@AS@%     }
  14478. %@AS@%  }%@AE@%%@NL@%
  14479. %@NL@%
  14480. %@NL@%
  14481. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14482. %@NL@%
  14483. %@AS@%  
  14484. %@AS@%  
  14485. %@AS@%  /* FGETS.C: This program uses fgets to display a line from a file on the%@AE@%%@NL@%
  14486. %@NL@%
  14487. %@NL@%
  14488. %@NL@%
  14489. %@NL@%
  14490. %@QR:fieeetomsbin@%%@QR:fmsbintoieee@%%@NL@%
  14491. %@2@%%@CR:C6A01010522 @%%@AB@%fieeetomsbin, fmsbintoieee%@AE@%%@EH@%%@NL@%
  14492. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14493. %@NL@%
  14494. %@NL@%
  14495. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  14496. %@NL@%
  14497. Convert floating-point numbers between IEEE and Microsoft binary formats.  %@NL@%
  14498. %@NL@%
  14499. %@AS@%  #include <math.h>%@AE@%%@NL@%
  14500. %@NL@%
  14501. %@AS@%  int fieeetomsbin( float *src4,  float *dst4 );%@AE@%%@NL@%
  14502. %@NL@%
  14503. %@AS@%  int fmsbintoieee(  float *src4,  float *dst4 );%@AE@%%@NL@%
  14504. %@NL@%
  14505. %@AI@%scr4 %@AE@%                             Value to be converted
  14506.  
  14507. %@AI@%dst4 %@AE@%                             Converted value
  14508.  
  14509. %@NL@%
  14510. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14511. %@NL@%
  14512. The %@AB@%fieeetomsbin%@AE@% routine converts a single-precision floating-point number
  14513. in IEEE (Institute of Electrical and Electronic Engineers) format to
  14514. Microsoft (MS) binary format.  %@NL@%
  14515. %@NL@%
  14516. The %@AB@%fmsbintoieee%@AE@% routine converts a floating-point number in Microsoft
  14517. binary format to IEEE format.  %@NL@%
  14518. %@NL@%
  14519. These routines allow C programs (which store floating-point numbers in the
  14520. IEEE format) to use numeric data in random-access data files created with
  14521. Microsoft BASIC (which stores floating-point numbers in the Microsoft binary
  14522. format), and vice versa.  %@NL@%
  14523. %@NL@%
  14524. The argument %@AI@%src4%@AE@% points to the %@AB@%float%@AE@% value to be converted. The result is
  14525. stored at the location given by %@AI@%dst4%@AE@%.  %@NL@%
  14526. %@NL@%
  14527. These routines do not handle IEEE NANs ("not a number") and infinities. IEEE
  14528. denormals are treated as 0 in the conversions.  %@NL@%
  14529. %@NL@%
  14530. %@NL@%
  14531. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14532. %@NL@%
  14533. These functions return 0 if the conversion is successful and 1 if the
  14534. conversion causes an overflow.  %@NL@%
  14535. %@NL@%
  14536. %@NL@%
  14537. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14538. %@NL@%
  14539.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14540. %@NL@%
  14541. %@NL@%
  14542. %@NL@%
  14543. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14544. %@NL@%
  14545. %@AB@%dieeetomsbin%@AE@%, %@AB@%dmsbintoieee%@AE@%  %@NL@%
  14546. %@NL@%
  14547. %@NL@%
  14548. %@NL@%
  14549. %@NL@%
  14550. %@QR:filelength@%%@NL@%
  14551. %@2@%%@CR:C6A01020523 @%%@AB@%filelength%@AE@%%@EH@%%@NL@%
  14552. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14553. %@NL@%
  14554. %@NL@%
  14555. %@3@%%@AB@%Description%@CR:C6A01020524 @%%@CR:C6A01020525 @% %@CR:C6A01020526 @%%@AE@%%@EH@%%@NL@%
  14556. %@NL@%
  14557. Gets the length of a file.  %@NL@%
  14558. %@NL@%
  14559. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  14560.  
  14561. %@AS@%  long filelength( int handle );%@AE@%%@NL@%
  14562. %@NL@%
  14563. %@AI@%handle%@AE@%                            Target file handle
  14564.  
  14565. %@NL@%
  14566. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14567. %@NL@%
  14568. The %@AB@%filelength%@AE@% function returns the length, in bytes, of the target file
  14569. associated with %@AI@%handle.%@AE@%  %@NL@%
  14570. %@NL@%
  14571. %@NL@%
  14572. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14573. %@NL@%
  14574. The %@AB@%filelength%@AE@% function returns the file length in bytes. A return value of
  14575. -1L indicates an error, and an invalid handle sets %@AB@%errno%@AE@% to %@AB@%EBADF%@AE@%.  %@NL@%
  14576. %@NL@%
  14577. %@NL@%
  14578. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14579. %@NL@%
  14580.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14581. %@NL@%
  14582. %@NL@%
  14583. %@NL@%
  14584. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14585. %@NL@%
  14586. %@AB@%chsize%@AE@%, %@AB@%fileno%@AE@%, %@AB@%fstat%@AE@%, %@AB@%stat%@AE@%  %@NL@%
  14587. %@NL@%
  14588. %@NL@%
  14589. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14590. %@NL@%
  14591. %@AS@%  /* CHSIZE.C: This program uses filelength to report the size of a
  14592. %@AS@%   * file before and after modifying it with chsize.
  14593. %@AS@%   */
  14594. %@AS@%  
  14595. %@AS@%  #include <io.h>
  14596. %@AS@%  #include <fcntl.h>
  14597. %@AS@%  #include <sys\types.h>
  14598. %@AS@%  #include <sys\stat.h>
  14599. %@AS@%  #include <stdio.h>
  14600. %@AS@%  
  14601. %@AS@%  void main()
  14602. %@AS@%  {
  14603. %@AS@%     int fh, result;
  14604. %@AS@%     unsigned int nbytes = BUFSIZ;%@AE@%%@NL@%
  14605. %@NL@%
  14606. %@AS@%  /* Open a file */
  14607. %@AS@%     if( (fh = open( "data", O_RDWR | O_CREAT, S_IREAD | S_IWRITE )) != -1 )
  14608. %@AS@%     {
  14609. %@AS@%        printf( "File length before: %ld\n", filelength( fh ) );
  14610. %@AS@%        if( chsize( fh, 329678 ) == 0 )
  14611. %@AS@%           printf( "Size successfully changed\n" );
  14612. %@AS@%        else
  14613. %@AS@%           printf( "Problem in changing the size\n" );
  14614. %@AS@%        printf( "File length after:  %ld\n", filelength( fh ) );
  14615. %@AS@%        close( fh );
  14616. %@AS@%     }
  14617. %@AS@%  }%@AE@%%@NL@%
  14618. %@NL@%
  14619. %@NL@%
  14620. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14621. %@NL@%
  14622. %@AS@%  
  14623. %@AS@%  
  14624. %@AS@%  File length before: 0
  14625. %@AS@%  Size successfully changed
  14626. %@AS@%  File length after:  329678%@AE@%%@NL@%
  14627. %@NL@%
  14628. %@NL@%
  14629. %@NL@%
  14630. %@NL@%
  14631. %@QR:fileno@%%@NL@%
  14632. %@2@%%@CR:C6A01030527 @%%@AB@%fileno%@AE@%%@EH@%%@NL@%
  14633. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14634. %@NL@%
  14635. %@NL@%
  14636. %@3@%%@AB@%Description%@CR:C6A01030528 @%%@CR:C6A01030529 @%%@CR:C6A01030530 @% %@CR:C6A01030531 @%%@AE@%%@EH@%%@NL@%
  14637. %@NL@%
  14638. Gets the file handle associated with a stream.  %@NL@%
  14639. %@NL@%
  14640. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14641. %@NL@%
  14642. %@AS@%  int fileno( FILE *stream );%@AE@%%@NL@%
  14643. %@NL@%
  14644. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  14645.  
  14646. %@NL@%
  14647. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14648. %@NL@%
  14649. The %@AB@%fileno%@AE@% routine returns the file handle currently associated with %@AI@%stream%@AE@%.
  14650. This routine is implemented as a macro.  %@NL@%
  14651. %@NL@%
  14652. %@NL@%
  14653. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14654. %@NL@%
  14655. The %@AB@%fileno%@AE@% routine returns the file handle. There is no error return. The
  14656. result is undefined if %@AI@%stream%@AE@% does not specify an open file.  %@NL@%
  14657. %@NL@%
  14658. %@NL@%
  14659. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14660. %@NL@%
  14661.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14662. %@NL@%
  14663. %@NL@%
  14664. %@NL@%
  14665. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14666. %@NL@%
  14667. %@AB@%fdopen%@AE@%, %@AB@%filelength%@AE@%, %@AB@%fopen%@AE@%, %@AB@%freopen%@AE@%  %@NL@%
  14668. %@NL@%
  14669. %@NL@%
  14670. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14671. %@NL@%
  14672. %@AS@%  /* FILENO.C: This program uses fileno to obtain the file handle for
  14673. %@AS@%   * some standard C streams.
  14674. %@AS@%   */
  14675. %@AS@%  
  14676. %@AS@%  #include <stdio.h>
  14677. %@AS@%  
  14678. %@AS@%  void main()
  14679. %@AS@%  {
  14680. %@AS@%     printf( "The file handle for stdin is %d\n", fileno( stdin ) );
  14681. %@AS@%     printf( "The file handle for stdout is %d\n", fileno( stdout ) );
  14682. %@AS@%     printf( "The file handle for stderr is %d\n", fileno( stderr ) );
  14683. %@AS@%  }%@AE@%%@NL@%
  14684. %@NL@%
  14685. %@NL@%
  14686. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14687. %@NL@%
  14688. %@AS@%  
  14689. %@AS@%  
  14690. %@AS@%  The file handle for stdin is 0
  14691. %@AS@%  The file handle for stdout is 1
  14692. %@AS@%  The file handle for stderr is 2%@AE@%%@NL@%
  14693. %@NL@%
  14694. %@NL@%
  14695. %@NL@%
  14696. %@NL@%
  14697. %@QR:_floodfill@%%@QR:_floodfill_w@%%@NL@%
  14698. %@2@%%@CR:C6A01040532 @%%@AB@%_floodfill, _floodfill_w%@AE@%%@EH@%%@NL@%
  14699. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14700. %@NL@%
  14701. %@NL@%
  14702. %@3@%%@AB@%Description%@CR:C6A01040533 @%%@AE@%%@EH@%%@NL@%
  14703. %@NL@%
  14704. Fill an area of a display using the current color and fill mask  %@NL@%
  14705. %@NL@%
  14706. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  14707. %@NL@%
  14708. %@AS@%  short _far _floodfill( short x, short y, short boundary );%@AE@%%@NL@%
  14709. %@NL@%
  14710. %@AS@%  short _far _floodfill_w( double wx, double wy, short boundary );%@AE@%%@NL@%
  14711. %@NL@%
  14712. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Start point
  14713.  
  14714. %@AI@%wx%@AE@%, %@AI@%wy%@AE@%                            Start point
  14715.  
  14716. %@AI@%boundary%@AE@%                          Boundary color of area to be filled
  14717.  
  14718. %@NL@%
  14719. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14720. %@NL@%
  14721. The functions in the %@AB@%_floodfill%@AE@% family fill an area of the display, using
  14722. the current color and fill mask. The %@AB@%_floodfill%@AE@% routine begins filling at
  14723. the view-coordinate point (%@AI@%x%@AE@%, %@AI@%y%@AE@%). The %@AB@%_floodfill_w%@AE@% routine begins filling at
  14724. the window-coordinate point (%@AI@%wx%@AE@%, %@AI@%wy%@AE@%).  %@NL@%
  14725. %@NL@%
  14726. If this point lies inside the figure, the interior is filled; if it lies
  14727. outside the figure, the background is filled. The point must be inside or
  14728. outside the figure to be filled, not on the figure boundary itself. Filling
  14729. occurs in all directions, stopping at the color of %@AI@%boundary%@AE@%.  %@NL@%
  14730. %@NL@%
  14731. %@NL@%
  14732. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14733. %@NL@%
  14734. The %@AB@%_floodfill%@AE@% functions return a nonzero value if the fill is successful.
  14735. It returns 0 if the fill could not be completed, the starting point lies on
  14736. the %@AI@%boundary%@AE@% color, or the start point lies outside the clipping region.  %@NL@%
  14737. %@NL@%
  14738. %@NL@%
  14739. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14740. %@NL@%
  14741.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  14742. %@NL@%
  14743. %@NL@%
  14744. %@NL@%
  14745. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14746. %@NL@%
  14747. %@AB@%_ellipse%@AE@% functions, %@AB@% _getcolor%@AE@%, %@AB@% _getfillmask%@AE@%, %@AB@% _grstatus%@AE@%,%@AB@%  _pie%@AE@% functions, %@AB@%
  14748. %@AB@%_setfillmask%@AE@%, %@AB@%_setcliprgn%@AE@%, %@AB@% _setcolor%@AE@%  %@NL@%
  14749. %@NL@%
  14750. %@NL@%
  14751. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14752. %@NL@%
  14753. %@AS@%  /* FLOODFIL.C: This program draws a series of nested rectangles in
  14754. %@AS@%   * different colors, constantly changing the background color.
  14755. %@AS@%   */
  14756. %@AS@%  
  14757. %@AS@%  #include <conio.h>
  14758. %@AS@%  #include <stdlib.h>
  14759. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  14760. %@NL@%
  14761. %@AS@%  void main()
  14762. %@AS@%  {
  14763. %@AS@%     int loop;
  14764. %@AS@%     int xvar, yvar;
  14765. %@AS@%  
  14766. %@AS@%     /* find a valid graphics mode */
  14767. %@AS@%     if( !_setvideomode( _MAXCOLORMODE ) )
  14768. %@AS@%        exit( 1 );
  14769. %@AS@%  
  14770. %@AS@%     for( xvar = 163, loop = 0; xvar < 320; loop++, xvar += 3 )
  14771. %@AS@%     {
  14772. %@AS@%        _setcolor( loop % 16 );
  14773. %@AS@%        yvar = xvar * 5 / 8;
  14774. %@AS@%        _rectangle( _GBORDER, 320-xvar, 200-yvar, xvar, yvar );
  14775. %@AS@%        _setcolor( rand() % 16 );
  14776. %@AS@%        _floodfill( 0, 0, loop % 16 );
  14777. %@AS@%     }
  14778. %@AS@%     getch();
  14779. %@AS@%     _setvideomode( _DEFAULTMODE );
  14780. %@AS@%  }%@AE@%%@NL@%
  14781. %@NL@%
  14782. %@NL@%
  14783. %@NL@%
  14784. %@NL@%
  14785. %@QR:floor@%%@QR:floorl@%%@NL@%
  14786. %@2@%%@CR:C6A01050534 @%%@AB@%floor, floorl%@AE@%%@EH@%%@NL@%
  14787. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14788. %@NL@%
  14789. %@NL@%
  14790. %@3@%%@AB@%Description%@CR:C6A01050535 @%%@CR:C6A01050536 @%%@AE@%%@EH@%%@NL@%
  14791. %@NL@%
  14792. Calculate the floor of a value.  %@NL@%
  14793. %@NL@%
  14794. %@AS@%  #include <math.h>%@AE@%%@NL@%
  14795. %@NL@%
  14796. %@AS@%  double floor( double x );%@AE@%%@NL@%
  14797. %@NL@%
  14798. %@AS@%  long double floorl( long double x );%@AE@%%@NL@%
  14799. %@NL@%
  14800. %@AI@%x%@AE@%                                 Floating-point value
  14801.  
  14802. %@NL@%
  14803. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14804. %@NL@%
  14805. The %@AB@%floor%@AE@% and %@AB@%floorl%@AE@% functions return a floating-point value representing
  14806. the largest integer that is less than or equal to%@AB@% %@AE@%%@AI@%x%@AE@%.  %@NL@%
  14807. %@NL@%
  14808. The %@AB@%floorl%@AE@% function is the 80-bit counterpart, and it uses the 80-bit,
  14809. 10-byte coprocessor form of arguments and return values. See the reference
  14810. page on the long double functions for more details on this data type.  %@NL@%
  14811. %@NL@%
  14812. %@NL@%
  14813. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14814. %@NL@%
  14815. These functions return the floating-point result. There is no error return.
  14816. %@NL@%
  14817. %@NL@%
  14818. %@NL@%
  14819. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14820. %@NL@%
  14821. %@AB@%floor%@AE@%  %@NL@%
  14822. %@NL@%
  14823. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14824. %@NL@%
  14825. %@NL@%
  14826. %@AB@%floorl%@AE@%  %@NL@%
  14827. %@NL@%
  14828.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14829. %@NL@%
  14830. %@NL@%
  14831. %@NL@%
  14832. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14833. %@NL@%
  14834. %@AB@%ceil%@AE@%, %@AB@%fmod%@AE@%  %@NL@%
  14835. %@NL@%
  14836. %@NL@%
  14837. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14838. %@NL@%
  14839. %@AS@%  /* FLOOR.C: This example displays the largest integers less than or equal
  14840. %@AS@%   * to the floating-point values 2.8 and -2.8. It then shows the smallest
  14841. %@AS@%   * integers greater than or equal to 2.8 and -2.8.
  14842. %@AS@%   */
  14843. %@AS@%  
  14844. %@AS@%  #include <math.h>
  14845. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14846. %@NL@%
  14847. %@AS@%  void main()
  14848. %@AS@%  {
  14849. %@AS@%     double y;
  14850. %@AS@%  
  14851. %@AS@%     y = floor( 2.8 );
  14852. %@AS@%     printf( "The floor of 2.8 is %f\n", y );
  14853. %@AS@%     y = floor( -2.8 );
  14854. %@AS@%     printf( "The floor of -2.8 is %f\n", y );
  14855. %@AS@%  
  14856. %@AS@%     y = ceil( 2.8 );
  14857. %@AS@%     printf( "The ceil of 2.8 is %f\n", y );
  14858. %@AS@%     y = ceil( -2.8 );
  14859. %@AS@%     printf( "The ceil of -2.8 is %f\n", y );
  14860. %@AS@%  }%@AE@%%@NL@%
  14861. %@NL@%
  14862. %@NL@%
  14863. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14864. %@NL@%
  14865. %@AS@%  
  14866. %@AS@%  
  14867. %@AS@%  The floor of 2.8 is 2.000000
  14868. %@AS@%  The floor of -2.8 is -3.000000
  14869. %@AS@%  The ceil of 2.8 is 3.000000
  14870. %@AS@%  The ceil of -2.8 is -2.000000%@AE@%%@NL@%
  14871. %@NL@%
  14872. %@NL@%
  14873. %@NL@%
  14874. %@NL@%
  14875. %@QR:flushall@%%@NL@%
  14876. %@2@%%@CR:C6A01060537 @%%@AB@%flushall%@AE@%%@EH@%%@NL@%
  14877. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14878. %@NL@%
  14879. %@NL@%
  14880. %@3@%%@AB@%Description%@CR:C6A01060538 @%%@CR:C6A01060539 @%%@CR:C6A01060540 @% %@CR:C6A01060541 @%%@AE@%%@EH@%%@NL@%
  14881. %@NL@%
  14882. Flushes all streams; clears all buffers.  %@NL@%
  14883. %@NL@%
  14884. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  14885. %@NL@%
  14886. %@AS@%  int flushall( void );%@AE@%%@NL@%
  14887. %@NL@%
  14888. %@NL@%
  14889. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14890. %@NL@%
  14891. The %@AB@%flushall%@AE@% function writes to its associated files the contents of all
  14892. buffers associated with open output streams. All buffers associated with
  14893. open input streams are cleared of their current contents. The next read
  14894. operation (if there is one) then reads new data from the input files into
  14895. the buffers.  %@NL@%
  14896. %@NL@%
  14897. Buffers are automatically flushed when they are full, when streams are
  14898. closed, or when a program terminates normally without closing streams.  %@NL@%
  14899. %@NL@%
  14900. All streams remain open after the call to %@AB@%flushall%@AE@%.  %@NL@%
  14901. %@NL@%
  14902. %@NL@%
  14903. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14904. %@NL@%
  14905. The %@AB@%flushall%@AE@% function returns the number of open streams (input and output).
  14906. There is no error return.  %@NL@%
  14907. %@NL@%
  14908. %@NL@%
  14909. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14910. %@NL@%
  14911.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14912. %@NL@%
  14913. %@NL@%
  14914. %@NL@%
  14915. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14916. %@NL@%
  14917. %@AB@%fflush%@AE@%  %@NL@%
  14918. %@NL@%
  14919. %@NL@%
  14920. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14921. %@NL@%
  14922. %@AS@%  /* FLUSHALL.C: This program uses flushall to flush all open buffers. */
  14923. %@AS@%  
  14924. %@AS@%  #include <stdio.h>
  14925. %@AS@%  
  14926. %@AS@%  void main()
  14927. %@AS@%  {
  14928. %@AS@%     int numflushed;
  14929. %@AS@%  
  14930. %@AS@%     numflushed = flushall();
  14931. %@AS@%     printf( "There were %d streams flushed\n", numflushed );
  14932. %@AS@%  }%@AE@%%@NL@%
  14933. %@NL@%
  14934. %@NL@%
  14935. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  14936. %@NL@%
  14937. %@AS@%  
  14938. %@AS@%  
  14939. %@AS@%  There were 3 streams flushed%@AE@%%@NL@%
  14940. %@NL@%
  14941. %@NL@%
  14942. %@NL@%
  14943. %@NL@%
  14944. %@QR:fmod@%%@QR:fmodl@%%@NL@%
  14945. %@2@%%@CR:C6A01070542 @%%@AB@%fmod, fmodl%@AE@%%@EH@%%@NL@%
  14946. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  14947. %@NL@%
  14948. %@NL@%
  14949. %@3@%%@AB@%Description%@CR:C6A01070543 @%%@CR:C6A01070544 @%%@CR:C6A01070545 @%%@AE@%%@EH@%%@NL@%
  14950. %@NL@%
  14951. Calculates the floating-point remainder.  %@NL@%
  14952. %@NL@%
  14953. %@AS@%  #include <math.h>%@AE@%%@NL@%
  14954. %@NL@%
  14955. %@AS@%  double fmod( double x, double y );%@AE@%%@NL@%
  14956. %@NL@%
  14957. %@AS@%  long double fmodl( long double x, long double y );%@AE@%%@NL@%
  14958. %@NL@%
  14959. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Floating-point values
  14960.  
  14961. %@NL@%
  14962. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  14963. %@NL@%
  14964. The %@AB@%fmod%@AE@% and %@AB@%fmodl%@AE@% functions calculate the floating-point remainder %@AI@%f%@AE@% of %@AI@%x%@AE@% /
  14965. %@AI@%y %@AE@% such that %@AI@%x%@AE@% = %@AI@%i %@AE@%* y + %@AI@%f%@AE@%, where %@AI@%i%@AE@% is an integer,  %@AI@%f%@AE@%  has the same sign as
  14966. %@AI@%x%@AE@%, and the absolute value of %@AI@% f%@AE@%  is less than the absolute value of %@AI@%y%@AE@%.  %@NL@%
  14967. %@NL@%
  14968. The %@AB@%fmodl%@AE@% function is the 80-bit counterpart; it uses the 80-bit, 10-byte
  14969. coprocessor form of arguments and return values. See the discussion of the
  14970. long double functions for more details on this data type.  %@NL@%
  14971. %@NL@%
  14972. %@NL@%
  14973. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  14974. %@NL@%
  14975. These functions return the floating-point remainder. If %@AI@%y%@AE@% is 0, the function
  14976. returns 0.  %@NL@%
  14977. %@NL@%
  14978. %@NL@%
  14979. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  14980. %@NL@%
  14981. %@AB@%fmod%@AE@%  %@NL@%
  14982. %@NL@%
  14983. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  14984. %@NL@%
  14985. %@NL@%
  14986. %@AB@%fmodl%@AE@%  %@NL@%
  14987. %@NL@%
  14988.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  14989. %@NL@%
  14990. %@NL@%
  14991. %@NL@%
  14992. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  14993. %@NL@%
  14994. %@AB@%ceil%@AE@%, %@AB@%fabs%@AE@%, %@AB@%floor%@AE@%  %@NL@%
  14995. %@NL@%
  14996. %@NL@%
  14997. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  14998. %@NL@%
  14999. %@AS@%  /* FMOD.C: This program displays a floating-point remainder. */
  15000. %@AS@%  
  15001. %@AS@%  #include <math.h>
  15002. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15003. %@NL@%
  15004. %@AS@%  void main()
  15005. %@AS@%  {
  15006. %@AS@%     double x = -10.0, y = 3.0, z;
  15007. %@AS@%  
  15008. %@AS@%     z = fmod( x, y );
  15009. %@AS@%     printf( "The remainder of %.2f / %.2f is %f\n", x, y, z );
  15010. %@AS@%  }%@AE@%%@NL@%
  15011. %@NL@%
  15012. %@NL@%
  15013. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15014. %@NL@%
  15015. %@AS@%  
  15016. %@AS@%  
  15017. %@AS@%  The remainder of -10.00 / 3.00 is -1.000000%@AE@%%@NL@%
  15018. %@NL@%
  15019. %@NL@%
  15020. %@NL@%
  15021. %@NL@%
  15022. %@QR:fopen@%%@NL@%
  15023. %@2@%%@CR:C6A01080546 @%%@AB@%fopen%@AE@%%@EH@%%@NL@%
  15024. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15025. %@NL@%
  15026. %@NL@%
  15027. %@3@%%@AB@%Description%@CR:C6A01080547 @%%@CR:C6A01080548 @%%@CR:C6A01080549 @% %@CR:C6A01080550 @%%@CR:C6A01080551 @%%@CR:C6A01080552 @%%@CR:C6A01080553 @%%@AE@%%@EH@%%@NL@%
  15028. %@NL@%
  15029. Opens a file.  %@NL@%
  15030. %@NL@%
  15031. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15032. %@NL@%
  15033. %@AS@%  FILE *fopen( const char *filename, const char *mode );%@AE@%%@NL@%
  15034. %@NL@%
  15035. %@AI@%filename%@AE@%                          Path name of file
  15036.  
  15037. %@AI@%mode%@AE@%                              Type of access permitted
  15038.  
  15039. %@NL@%
  15040. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15041. %@NL@%
  15042. The %@AB@%fopen%@AE@% function opens the file specified by %@AI@%filename%@AE@%. The character
  15043. string %@AI@%mode%@AE@% specifies the type of access requested for the file, as follows:
  15044. %@NL@%
  15045. %@NL@%
  15046. %@AB@%Type%@AE@%                              %@AB@%Description%@AE@%
  15047. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15048. %@AB@%"r"%@AE@%                               Opens for reading. If the file does not 
  15049.                                   exist or cannot be found, the %@AB@%fopen%@AE@% call
  15050.                                   will fail.
  15051.  
  15052. %@AB@%"w"%@AE@%                               Opens an empty file for writing. If the 
  15053.                                   given file exists, its contents are 
  15054.                                   destroyed. 
  15055.  
  15056. %@AB@%"a"%@AE@%                               Opens for writing at the end of the file
  15057.                                   (appending); creates the file first if 
  15058.                                   it doesn't exist.
  15059.  
  15060. %@AB@%"r+"%@AE@%                              Opens for both reading and writing. (The
  15061.                                   file must exist.)
  15062.  
  15063. %@AB@%"w+"%@AE@%                              Opens an empty file for both reading and
  15064.                                   writing. If the given file exists, its 
  15065.                                   contents are destroyed.
  15066.  
  15067. %@AB@%"a+"%@AE@%                              Opens for reading and appending; creates
  15068.                                   the file first if it doesn't exist.
  15069.  
  15070. When a file is opened with the %@AB@%"a"%@AE@% or %@AB@%"a+"%@AE@% access type, all write operations
  15071. occur at the end of the file. Although the file pointer can be repositioned
  15072. using %@AB@%fseek%@AE@% or%@AB@% rewind%@AE@%, the file pointer is always moved back to the end of
  15073. the file before any write operation is carried out. Thus, existing data
  15074. cannot be overwritten.  %@NL@%
  15075. %@NL@%
  15076. When the %@AB@%"r+"%@AE@%, %@AB@%"w+"%@AE@%, or %@AB@%"a+" %@AE@%access type is specified, both reading and
  15077. writing are allowed (the file is said to be open for "update"). However,
  15078. when you switch between reading and writing, there must be an intervening
  15079. %@AB@%fsetpos%@AE@%, %@AB@%fseek%@AE@%, or %@AB@%rewind%@AE@% operation. The current position can be specified
  15080. for the %@AB@%fsetpos%@AE@% or %@AB@%fseek%@AE@% operation, if desired.  %@NL@%
  15081. %@NL@%
  15082. In addition to the values listed above, one of the following characters can
  15083. be included in %@AI@%mode%@AE@% to specify the translation mode for newline characters: %@CR:C6A01080554 @%%@CR:C6A01080555 @%%@CR:C6A01080556 @%
  15084. %@NL@%
  15085. %@NL@%
  15086. %@AB@%Mode%@AE@%                              %@AB@%Meaning%@AE@%
  15087. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15088. %@AB@%t%@AE@%                                 Open in text (translated) mode. In this 
  15089.                                   mode, carriage-return-line-feed (CR-LF) 
  15090.                                   combinations are translated into single 
  15091.                                   line feeds (LF) on input and LF 
  15092.                                   characters are translated to CR-LF 
  15093.                                   combinations on output. Also, CTRL+Z is 
  15094.                                   interpreted as an end-of-file character 
  15095.                                   on input. In files opened for reading or
  15096.                                   for reading/writing, %@AB@%fopen%@AE@% checks for a 
  15097.                                   CTRL+Z at the end of the file and 
  15098.                                   removes it, if possible. This is done 
  15099.                                   because using the %@AB@%fseek%@AE@% and %@AB@%ftell%@AE@% 
  15100.                                   functions to move within a file that 
  15101.                                   ends with a CTRL+Z may cause %@AB@%fseek%@AE@% to 
  15102.                                   behave improperly near the end of the 
  15103.                                   file.
  15104.  
  15105. %@AB@%b%@AE@%                                 Open in binary (untranslated) mode; the 
  15106.                                   above translations are suppressed.
  15107.  
  15108. If %@AB@%t%@AE@% or %@AB@%b%@AE@% is not given in %@AI@%mode%@AE@%, the translation mode is defined by the
  15109. default-mode variable %@AB@%_fmode%@AE@%. If %@AB@%t%@AE@% or %@AB@%b%@AE@% is prefixed to the argument, the
  15110. function will fail and return %@AB@%NULL%@AE@%.  %@NL@%
  15111. %@NL@%
  15112. See Section 2.7, "Input and Output," for a discussion of text and binary
  15113. modes.  %@NL@%
  15114. %@NL@%
  15115. %@NL@%
  15116. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15117. %@NL@%
  15118. The %@AB@%fopen%@AE@% function returns a pointer to the open file. A null pointer value
  15119. indicates an error.  %@NL@%
  15120. %@NL@%
  15121. %@NL@%
  15122. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15123. %@NL@%
  15124. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  15125. %@NL@%
  15126. %@NL@%
  15127. Note that the %@AB@%t%@AE@% option is not part of the ANSI standard for %@AB@%fopen%@AE@%; it is a
  15128. Microsoft extension and should not be used where ANSI portability is
  15129. desired.  %@NL@%
  15130. %@NL@%
  15131. %@NL@%
  15132. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15133. %@NL@%
  15134. %@AB@%fclose%@AE@%, %@AB@%fcloseall%@AE@%, %@AB@%fdopen%@AE@%, %@AB@%ferror%@AE@%, %@AB@%fileno%@AE@%, %@AB@%freopen%@AE@%, %@AB@%open%@AE@%, %@AB@%setmode%@AE@%  %@NL@%
  15135. %@NL@%
  15136. %@NL@%
  15137. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15138. %@NL@%
  15139. %@AS@%  /* FOPEN.C: This program opens files named "data" and "data2". It uses
  15140. %@AS@%   * fclose to close "data" and fcloseall to close all remaining files.
  15141. %@AS@%   */
  15142. %@AS@%  
  15143. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15144. %@NL@%
  15145. %@AS@%  FILE *stream, *stream2;
  15146. %@AS@%  
  15147. %@AS@%  void main()
  15148. %@AS@%  {
  15149. %@AS@%     int numclosed;
  15150. %@AS@%  
  15151. %@AS@%     /* Open for read (will fail if 'data' does not exist) */
  15152. %@AS@%     if( (stream  = fopen( "data", "r" )) == NULL )
  15153. %@AS@%        printf( "The file 'data' was not opened\n" );
  15154. %@AS@%     else
  15155. %@AS@%        printf( "The file 'data' was opened\n" );
  15156. %@AS@%  
  15157. %@AS@%     /* Open for write */
  15158. %@AS@%     if( (stream2 = fopen( "data2", "w+" )) == NULL )
  15159. %@AS@%        printf( "The file 'data2' was not opened\n" );
  15160. %@AS@%     else
  15161. %@AS@%        printf( "The file 'data2' was opened\n" );
  15162. %@AS@%  
  15163. %@AS@%     /* Close stream */
  15164. %@AS@%     if( fclose( stream ) )
  15165. %@AS@%        printf( "The file 'data' was not closed\n" );
  15166. %@AS@%  
  15167. %@AS@%     /* All other files are closed: */
  15168. %@AS@%     numclosed = fcloseall( );
  15169. %@AS@%     printf( "Number of files closed by fcloseall: %u\n", numclosed );
  15170. %@AS@%  }%@AE@%%@NL@%
  15171. %@NL@%
  15172. %@NL@%
  15173. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15174. %@NL@%
  15175. %@AS@%  
  15176. %@AS@%  
  15177. %@AS@%  The file 'data' was opened
  15178. %@AS@%  The file 'data2' was opened
  15179. %@AS@%  Number of files closed by fcloseall: 1%@AE@%%@NL@%
  15180. %@NL@%
  15181. %@NL@%
  15182. %@NL@%
  15183. %@NL@%
  15184. %@QR:FP_OFF@%%@QR:FP_SEG@%%@NL@%
  15185. %@2@%%@CR:C6A01090557 @%%@AB@%FP_OFF, FP_SEG%@AE@%%@EH@%%@NL@%
  15186. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15187. %@NL@%
  15188. %@NL@%
  15189. %@3@%%@AB@%Description%@CR:C6A01090558 @%%@CR:C6A01090559 @%%@CR:C6A01090560 @%%@AE@%%@EH@%%@NL@%
  15190. %@NL@%
  15191. Get or set a far-pointer offset (%@AB@%FP_OFF%@AE@%) or a far-pointer segment (%@AB@%FP_SEG%@AE@%).
  15192. %@NL@%
  15193. %@NL@%
  15194. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  15195. %@NL@%
  15196. %@AS@%  unsigned FP_OFF( void _far *address );%@AE@%%@NL@%
  15197. %@NL@%
  15198. %@AS@%  unsigned FP_SEG( void _far *address );%@AE@%%@NL@%
  15199. %@NL@%
  15200. %@AI@%address%@AE@%                           Far pointer to memory address
  15201.  
  15202. %@NL@%
  15203. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15204. %@NL@%
  15205. The %@AB@%FP_OFF%@AE@% and %@AB@%FP_SEG%@AE@% macros can be used to set or get the offset and
  15206. segment, respectively, of the far pointer at %@AI@%address%@AE@%.  %@NL@%
  15207. %@NL@%
  15208. %@NL@%
  15209. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15210. %@NL@%
  15211. The %@AB@%FP_OFF%@AE@% macro returns an offset. The %@AB@%FP_SEG%@AE@% macro returns a segment
  15212. address.  %@NL@%
  15213. %@NL@%
  15214. %@NL@%
  15215. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15216. %@NL@%
  15217.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  15218. %@NL@%
  15219. %@NL@%
  15220. %@NL@%
  15221. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15222. %@NL@%
  15223. %@AS@%  /* FP_SEG.C: This program uses FP_SEG and FP_OFF to obtain
  15224. %@AS@%   * the segment and offset of the long pointer p.
  15225. %@AS@%   */
  15226. %@AS@%  
  15227. %@AS@%  #include <dos.h>
  15228. %@AS@%  #include <malloc.h>
  15229. %@AS@%  #include <stdio.h>
  15230. %@AS@%  
  15231. %@AS@%  
  15232. %@AS@%  void main()
  15233. %@AS@%  {
  15234. %@AS@%     void _far *p;
  15235. %@AS@%     unsigned int seg_val;
  15236. %@AS@%     unsigned int off_val;
  15237. %@AS@%  
  15238. %@AS@%     p = _fmalloc( 100 );        /* Points pointer at something */
  15239. %@AS@%  
  15240. %@AS@%     seg_val = FP_SEG( p );      /* Gets address pointed to */
  15241. %@AS@%     off_val = FP_OFF( p );
  15242. %@AS@%  
  15243. %@AS@%     printf( "Segment is %.4X; Offset is %.4X\n", seg_val, off_val );
  15244. %@AS@%  }%@AE@%%@NL@%
  15245. %@NL@%
  15246. %@NL@%
  15247. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15248. %@NL@%
  15249. %@AS@%  
  15250. %@AS@%  
  15251. %@AS@%  Segment is 00C7; Offset is 0016%@AE@%%@NL@%
  15252. %@NL@%
  15253. %@NL@%
  15254. %@NL@%
  15255. %@NL@%
  15256. %@QR:_fpreset@%%@NL@%
  15257. %@2@%%@CR:C6A01100561 @%%@AB@%_fpreset%@AE@%%@EH@%%@NL@%
  15258. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15259. %@NL@%
  15260. %@NL@%
  15261. %@3@%%@AB@%Description%@CR:C6A01100562 @%%@CR:C6A01100563 @% %@CR:C6A01100564 @%%@CR:C6A01100565 @%%@AE@%%@EH@%%@NL@%
  15262. %@NL@%
  15263. Resets the floating-point package.  %@NL@%
  15264. %@NL@%
  15265. %@AS@%  #include <float.h>%@AE@%%@NL@%
  15266. %@NL@%
  15267. %@AS@%  void _fpreset( void );%@AE@%%@NL@%
  15268. %@NL@%
  15269. %@NL@%
  15270. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15271. %@NL@%
  15272. The %@AB@%_fpreset%@AE@% function reinitializes the floating-point-math package. This
  15273. function is usually used in conjunction with %@AB@%signal%@AE@%, %@AB@%system%@AE@%, or the %@AB@%exec%@AE@% or
  15274. %@AB@%spawn%@AE@% functions.  %@NL@%
  15275. %@NL@%
  15276. If a program traps floating-point error signals (%@AB@%SIGFPE%@AE@%) with %@AB@%signal%@AE@%, it can
  15277. safely recover from floating-point errors by invoking %@AB@%_fpreset%@AE@% and using
  15278. %@AB@%longjmp%@AE@%.  %@NL@%
  15279. %@NL@%
  15280. In DOS versions prior to 3.0, a child process executed by %@AB@%exec%@AE@%, %@AB@%spawn%@AE@%, or
  15281. %@AB@%system%@AE@% may affect the floating-point state of the parent process if an 8087
  15282. or 80287 coprocessor is used. If you are using either coprocessor, the
  15283. following precautions are recommended:%@CR:C6A01100566 @%  %@NL@%
  15284. %@NL@%
  15285. %@NL@%
  15286.   ■   The %@AB@%exec%@AE@%, %@AB@%spawn%@AE@%, and %@AB@%system%@AE@% functions should not be called during the
  15287.       evaluation of a floating-point expression.%@NL@%
  15288. %@NL@%
  15289.   ■   The %@AB@%_fpreset%@AE@% function should be called after these routines if there
  15290.       is a possibility of the child process performing any floating-point
  15291.       operations.%@NL@%
  15292. %@NL@%
  15293. %@NL@%
  15294. %@NL@%
  15295. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15296. %@NL@%
  15297. None.  %@NL@%
  15298. %@NL@%
  15299. %@NL@%
  15300. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15301. %@NL@%
  15302.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  15303. %@NL@%
  15304. %@NL@%
  15305. %@NL@%
  15306. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15307. %@NL@%
  15308. %@AB@%exec%@AE@% functions, %@AB@%signal%@AE@%, %@AB@%spawn%@AE@% functions  %@NL@%
  15309. %@NL@%
  15310. %@NL@%
  15311. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15312. %@NL@%
  15313. %@AS@%  /* FPRESET.C: This program uses signal to set up a routine for handling
  15314. %@AS@%   * floating-point errors.
  15315. %@AS@%   */
  15316. %@AS@%  
  15317. %@AS@%  #include <stdio.h>
  15318. %@AS@%  #include <signal.h>
  15319. %@AS@%  #include <setjmp.h>
  15320. %@AS@%  #include <stdlib.h>
  15321. %@AS@%  #include <float.h>
  15322. %@AS@%  #include <math.h>
  15323. %@AS@%  #include <string.h>%@AE@%%@NL@%
  15324. %@NL@%
  15325. %@AS@%  jmp_buf mark;                       /* Address for long jump to jump to */
  15326. %@AS@%  int  fperr;                         /* Global error number */
  15327. %@AS@%  
  15328. %@AS@%  void fphandler( int sig, int num ); /* Prototypes */
  15329. %@AS@%  void fpcheck( void );
  15330. %@AS@%  
  15331. %@AS@%  void main()
  15332. %@AS@%  {
  15333. %@AS@%      double n1, n2, r;
  15334. %@AS@%      int jmpret;
  15335. %@AS@%  
  15336. %@AS@%      /* Set up floating point error handler. */
  15337. %@AS@%      if( signal( SIGFPE, fphandler ) == SIG_ERR )
  15338. %@AS@%      {
  15339. %@AS@%          fprintf( stderr, "Couldn't set SIGFPE\n" );
  15340. %@AS@%          abort();
  15341. %@AS@%      }
  15342. %@AS@%  
  15343. %@AS@%      /* Save stack environment for return in case of error. First time
  15344. %@AS@%       * through, jmpret is 0, so true conditional is executed. If an
  15345. %@AS@%       * error occurs, jmpret will be set to -1 and false conditional
  15346. %@AS@%       * will be executed.
  15347. %@AS@%       */
  15348. %@AS@%      jmpret = setjmp( mark );
  15349. %@AS@%      if( jmpret == 0 )
  15350. %@AS@%      {
  15351. %@AS@%          printf( "Test for invalid operation - " );
  15352. %@AS@%          printf( "enter two numbers: " );
  15353. %@AS@%          scanf( "%lf %lf", &n1, &n2 );
  15354. %@AS@%  
  15355. %@AS@%          r = n1 / n2;
  15356. %@AS@%          /* This won't be reached if error occurs. */
  15357. %@AS@%          printf( "\n\n%4.3g / %4.3g = %4.3g\n", n1, n2, r );
  15358. %@AS@%  
  15359. %@AS@%          r = n1 * n2;
  15360. %@AS@%          /* This won't be reached if error occurs. */
  15361. %@AS@%          printf( "\n\n%4.3g * %4.3g = %4.3g\n", n1, n2, r );
  15362. %@AS@%      }
  15363. %@AS@%      else
  15364. %@AS@%          fpcheck();
  15365. %@AS@%  }%@AE@%%@NL@%
  15366. %@NL@%
  15367. %@AS@%  /* Handles SIGFPE (floating point error) interrupt. */
  15368. %@AS@%  void fphandler( int sig, int num )
  15369. %@AS@%  {
  15370. %@AS@%      /* Set global for outside check since we don't want to do I/O in the
  15371. %@AS@%       * handler.
  15372. %@AS@%       */
  15373. %@AS@%      fperr = num;
  15374. %@AS@%  
  15375. %@AS@%      /* Initialize floating-point package. */
  15376. %@AS@%      _fpreset();
  15377. %@AS@%  
  15378. %@AS@%      /* Restore calling environment and jump back to setjmp. Return -1
  15379. %@AS@%       * so that setjmp will return false for conditional test.
  15380. %@AS@%       */
  15381. %@AS@%      longjmp( mark, -1 );
  15382. %@AS@%  }
  15383. %@AS@%  
  15384. %@AS@%  void fpcheck()
  15385. %@AS@%  {
  15386. %@AS@%      char fpstr[30];
  15387. %@AS@%  
  15388. %@AS@%      switch( fperr )
  15389. %@AS@%      {
  15390. %@AS@%          case FPE_INVALID:
  15391. %@AS@%              strcpy( fpstr, "Invalid number" );
  15392. %@AS@%              break;
  15393. %@AS@%  
  15394. %@AS@%          case FPE_OVERFLOW:
  15395. %@AS@%              strcpy( fpstr, "Overflow" );
  15396. %@AS@%              break;
  15397. %@AS@%  
  15398. %@AS@%          case FPE_UNDERFLOW:
  15399. %@AS@%              strcpy( fpstr, "Underflow" );
  15400. %@AS@%              break;
  15401. %@AS@%  
  15402. %@AS@%          case FPE_ZERODIVIDE:
  15403. %@AS@%              strcpy( fpstr, "Divide by zero" );
  15404. %@AS@%              break;
  15405. %@AS@%  
  15406. %@AS@%          default:
  15407. %@AS@%              strcpy( fpstr, "Other floating point error" );
  15408. %@AS@%              break;
  15409. %@AS@%      }
  15410. %@AS@%      printf( "Error %d: %s\n", fperr, fpstr );
  15411. %@AS@%  }%@AE@%%@NL@%
  15412. %@NL@%
  15413. %@NL@%
  15414. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15415. %@NL@%
  15416. %@AS@%  
  15417. %@AS@%  
  15418. %@AS@%  Test for invalid operation - enter two numbers: 5 0
  15419. %@AS@%  Error 131: Divide by zero%@AE@%%@NL@%
  15420. %@NL@%
  15421. %@NL@%
  15422. %@NL@%
  15423. %@NL@%
  15424. %@QR:fprintf@%%@NL@%
  15425. %@2@%%@CR:C6A01110567 @%%@AB@%fprintf%@AE@%%@EH@%%@NL@%
  15426. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15427. %@NL@%
  15428. %@NL@%
  15429. %@3@%%@AB@%Description%@CR:C6A01110568 @%%@CR:C6A01110569 @% %@CR:C6A01110570 @%%@CR:C6A01110571 @% %@CR:C6A01110572 @%%@AE@%%@EH@%%@NL@%
  15430. %@NL@%
  15431. Prints formatted data to a stream.  %@NL@%
  15432. %@NL@%
  15433. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15434. %@NL@%
  15435. %@AS@%  int fprintf( FILE *stream, const char *format [[, argument]]... );%@AE@%%@NL@%
  15436. %@NL@%
  15437. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  15438.  
  15439. %@AI@%format%@AE@%                            Format-control string
  15440.  
  15441. %@AI@%argument%@AE@%                          Optional arguments
  15442.  
  15443. %@NL@%
  15444. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15445. %@NL@%
  15446. The %@AB@%fprintf%@AE@% function formats and prints a series of characters and values to
  15447. the output %@AI@%stream%@AE@%. Each %@AI@%argument%@AE@% (if any) is converted and output according
  15448. to the corresponding format specification in %@AI@%format%@AE@%.  %@NL@%
  15449. %@NL@%
  15450. The %@AI@%format%@AE@% argument has the same form and function that it does for the
  15451. %@AB@%printf%@AE@% function; see the Remarks section for the %@AB@%printf%@AE@% function for more
  15452. information on %@AI@%format%@AE@% and %@AI@%argument%@AE@%.  %@NL@%
  15453. %@NL@%
  15454. %@NL@%
  15455. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15456. %@NL@%
  15457. The %@AB@%fprintf%@AE@% function returns the number of characters printed, or a negative
  15458. value in the case of an output error.  %@NL@%
  15459. %@NL@%
  15460. %@NL@%
  15461. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15462. %@NL@%
  15463. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  15464. %@NL@%
  15465. %@NL@%
  15466. %@NL@%
  15467. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15468. %@NL@%
  15469. %@AB@%cprintf%@AE@%, %@AB@%fscanf%@AE@%, %@AB@%printf%@AE@%, %@AB@%sprintf%@AE@%  %@NL@%
  15470. %@NL@%
  15471. %@NL@%
  15472. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15473. %@NL@%
  15474. %@AS@%  /* FPRINTF.C: This program uses fprintf to format various data and
  15475. %@AS@%   * print them to the file named FPRINTF.OUT. It then displays
  15476. %@AS@%   * FPRINTF.OUT on the screen using the system function to invoke
  15477. %@AS@%   * the DOS TYPE command.
  15478. %@AS@%   */
  15479. %@AS@%  
  15480. %@AS@%  #include <stdio.h>
  15481. %@AS@%  #include <process.h>%@AE@%%@NL@%
  15482. %@NL@%
  15483. %@AS@%  FILE *stream;
  15484. %@AS@%  
  15485. %@AS@%  void main()
  15486. %@AS@%  {
  15487. %@AS@%     int    i = 10;
  15488. %@AS@%     double fp = 1.5;
  15489. %@AS@%     char   s[] = "this is a string";
  15490. %@AS@%     char   c = '\n';
  15491. %@AS@%  
  15492. %@AS@%     stream = fopen( "fprintf.out", "w" );
  15493. %@AS@%     fprintf( stream, "%s%c", s, c );
  15494. %@AS@%     fprintf( stream, "%d\n", i );
  15495. %@AS@%     fprintf( stream, "%f\n", fp );
  15496. %@AS@%     fclose( stream );
  15497. %@AS@%     system( "type fprintf.out" );
  15498. %@AS@%  }%@AE@%%@NL@%
  15499. %@NL@%
  15500. %@NL@%
  15501. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15502. %@NL@%
  15503. %@AS@%  
  15504. %@AS@%  
  15505. %@AS@%  this is a string
  15506. %@AS@%  10
  15507. %@AS@%  1.500000 %@AE@%%@NL@%
  15508. %@NL@%
  15509. %@NL@%
  15510. %@NL@%
  15511. %@NL@%
  15512. %@QR:fputc@%%@QR:fputchar@%%@NL@%
  15513. %@2@%%@CR:C6A01120573 @%%@AB@%fputc, fputchar%@AE@%%@EH@%%@NL@%
  15514. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15515. %@NL@%
  15516. %@NL@%
  15517. %@3@%%@AB@%Description%@CR:C6A01120574 @%%@CR:C6A01120575 @% %@CR:C6A01120576 @% %@CR:C6A01120577 @%%@CR:C6A01120578 @% %@CR:C6A01120579 @%%@AE@%%@EH@%%@NL@%
  15518. %@NL@%
  15519. Write a character to a stream (%@AB@%fputc%@AE@%) or to %@AB@%stdout %@AE@%(%@AB@%fputchar%@AE@%).  %@NL@%
  15520. %@NL@%
  15521. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15522. %@NL@%
  15523. %@AS@%  int fputc( int c, FILE *stream );%@AE@%%@NL@%
  15524. %@NL@%
  15525. %@AS@%  int fputchar( int c );%@AE@%%@NL@%
  15526. %@NL@%
  15527. %@AI@%c%@AE@%                                 Character to be written
  15528.  
  15529. %@AI@%stream %@AE@%                           Pointer to %@AB@%FILE %@AE@%structure
  15530.  
  15531. %@NL@%
  15532. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15533. %@NL@%
  15534. The %@AB@%fputc%@AE@% function writes the single character %@AI@%c%@AE@% to the output %@AI@%stream%@AE@% at the
  15535. current position. The %@AB@%fputchar%@AE@% function is equivalent to %@AB@%fputc(%@AE@%%@AI@%c%@AE@%,%@AB@% stdout)%@AE@%.  %@NL@%
  15536. %@NL@%
  15537. The %@AB@%fputc%@AE@% and %@AB@%fputchar%@AE@% routines are similar to %@AB@%putc%@AE@% and %@AB@%putchar%@AE@%, but are
  15538. functions rather than macros.  %@NL@%
  15539. %@NL@%
  15540. %@NL@%
  15541. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15542. %@NL@%
  15543. The %@AB@%fputc%@AE@% and %@AB@%fputchar%@AE@% functions return the character written. A return
  15544. value of %@AB@%EOF%@AE@% indicates an error.  %@NL@%
  15545. %@NL@%
  15546. %@NL@%
  15547. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15548. %@NL@%
  15549. %@AB@%fputc%@AE@%  %@NL@%
  15550. %@NL@%
  15551. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  15552. %@NL@%
  15553. %@NL@%
  15554. %@AB@%fputchar%@AE@%  %@NL@%
  15555. %@NL@%
  15556.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  15557. %@NL@%
  15558. %@NL@%
  15559. %@NL@%
  15560. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15561. %@NL@%
  15562. %@AB@%fgetc%@AE@%, %@AB@%fgetchar%@AE@%, %@AB@%putc%@AE@%, %@AB@%putchar%@AE@%  %@NL@%
  15563. %@NL@%
  15564. %@NL@%
  15565. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15566. %@NL@%
  15567. %@AS@%  /* FPUTC.C: This program uses fputc and fputchar to send a character
  15568. %@AS@%   * array to stdout.
  15569. %@AS@%   */
  15570. %@AS@%  
  15571. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15572. %@NL@%
  15573. %@AS@%  void main()
  15574. %@AS@%  {
  15575. %@AS@%     char strptr1[] = "This is a test of fputc!!\n";
  15576. %@AS@%     char strptr2[] = "This is a test of fputchar!!\n";
  15577. %@AS@%     char *p;
  15578. %@AS@%  
  15579. %@AS@%     /* Print line to stream using fputc. */
  15580. %@AS@%     p = strptr1;
  15581. %@AS@%     while( (*p != '\0') && fputc( *(p++), stdout ) != EOF )
  15582. %@AS@%        ;
  15583. %@AS@%  
  15584. %@AS@%     /* Print line to stream using fputchar. */
  15585. %@AS@%     p = strptr2;
  15586. %@AS@%     while( (*p != '\0') && fputchar( *(p++) ) != EOF )
  15587. %@AS@%        ;
  15588. %@AS@%  }%@AE@%%@NL@%
  15589. %@NL@%
  15590. %@NL@%
  15591. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15592. %@NL@%
  15593. %@AS@%  
  15594. %@AS@%  
  15595. %@AS@%  This is a test of fputc!!
  15596. %@AS@%  This is a test of fputchar!! %@AE@%%@NL@%
  15597. %@NL@%
  15598. %@NL@%
  15599. %@NL@%
  15600. %@NL@%
  15601. %@QR:fputs@%%@NL@%
  15602. %@2@%%@CR:C6A01130580 @%%@AB@%fputs%@AE@%%@EH@%%@NL@%
  15603. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15604. %@NL@%
  15605. %@NL@%
  15606. %@3@%%@AB@%Description%@CR:C6A01130581 @%%@CR:C6A01130582 @% %@CR:C6A01130583 @%%@CR:C6A01130584 @% %@CR:C6A01130585 @%%@AE@%%@EH@%%@NL@%
  15607. %@NL@%
  15608. Writes a string to a stream.  %@NL@%
  15609. %@NL@%
  15610. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15611. %@NL@%
  15612. %@AS@%  int fputs( const char *string, FILE *stream );%@AE@%%@NL@%
  15613. %@NL@%
  15614. %@AI@%string%@AE@%                            String to be output
  15615.  
  15616. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  15617.  
  15618. %@NL@%
  15619. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15620. %@NL@%
  15621. The %@AB@%fputs%@AE@% function copies %@AI@%string%@AE@% to the output %@AI@%stream%@AE@% at the current
  15622. position. The terminating null character (%@AB@%'\0'%@AE@%) is not copied.  %@NL@%
  15623. %@NL@%
  15624. %@NL@%
  15625. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15626. %@NL@%
  15627. The %@AB@%fputs%@AE@% function returns a nonnegative value if it is successful. If an
  15628. error occurs, it returns %@AB@%EOF%@AE@%.%@CR:C6A01130586 @%  %@NL@%
  15629. %@NL@%
  15630. %@NL@%
  15631. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15632. %@NL@%
  15633. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  15634. %@NL@%
  15635. %@NL@%
  15636. %@NL@%
  15637. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15638. %@NL@%
  15639. %@AB@%fgets%@AE@%, %@AB@%gets%@AE@%, %@AB@%puts%@AE@%  %@NL@%
  15640. %@NL@%
  15641. %@NL@%
  15642. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15643. %@NL@%
  15644. %@AS@%  /* FPUTS.C: This program uses fputs to write a single line to the
  15645. %@AS@%   * stdout stream.
  15646. %@AS@%   */
  15647. %@AS@%  
  15648. %@AS@%  #include <stdio.h>
  15649. %@AS@%  
  15650. %@AS@%  void main()
  15651. %@AS@%  {
  15652. %@AS@%     fputs( "Hello world from fputs.\n", stdout );
  15653. %@AS@%  }%@AE@%%@NL@%
  15654. %@NL@%
  15655. %@NL@%
  15656. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15657. %@NL@%
  15658. %@AS@%  
  15659. %@AS@%  
  15660. %@AS@%  Hello world from fputs. %@AE@%%@NL@%
  15661. %@NL@%
  15662. %@NL@%
  15663. %@NL@%
  15664. %@NL@%
  15665. %@QR:fread@%%@NL@%
  15666. %@2@%%@CR:C6A01140587 @%%@AB@%fread%@AE@%%@EH@%%@NL@%
  15667. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15668. %@NL@%
  15669. %@NL@%
  15670. %@3@%%@AB@%Description%@CR:C6A01140588 @%%@CR:C6A01140589 @%%@CR:C6A01140590 @% %@CR:C6A01140591 @%%@AE@%%@EH@%%@NL@%
  15671. %@NL@%
  15672. Reads data from a stream.  %@NL@%
  15673. %@NL@%
  15674. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  15675. %@NL@%
  15676. %@AS@%  size_t fread( void *buffer, size_t size, size_t count, FILE *stream );%@AE@%%@NL@%
  15677. %@NL@%
  15678. %@AI@%buffer%@AE@%                            Storage location for data
  15679.  
  15680. %@AI@%size%@AE@%                              Item size in bytes
  15681.  
  15682. %@AI@%count%@AE@%                             Maximum number of items to be read
  15683.  
  15684. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  15685.  
  15686. %@NL@%
  15687. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15688. %@NL@%
  15689. The %@AB@%fread%@AE@% function reads up to %@AI@%count%@AE@% items of %@AI@%size%@AE@% bytes from the input
  15690. %@AI@%stream%@AE@% and stores them in %@AI@%buffer%@AE@%. The file pointer associated with %@AI@%stream%@AE@%
  15691. (if there is one) is increased by the number of bytes actually read.  %@NL@%
  15692. %@NL@%
  15693. If the given stream is opened in text mode, carriage-return-line-feed pairs
  15694. are replaced with single line-feed characters. The replacement has no effect
  15695. on the file pointer or the return value.  %@NL@%
  15696. %@NL@%
  15697. The file-pointer position is indeterminate if an error occurs. The value of
  15698. a partially read item cannot be determined.  %@NL@%
  15699. %@NL@%
  15700. %@NL@%
  15701. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15702. %@NL@%
  15703. The %@AB@%fread%@AE@% function returns the number of full items actually read, which may
  15704. be less than %@AI@%count%@AE@% if an error occurs or if the file end is encountered
  15705. before reaching %@AI@%count%@AE@%.  %@NL@%
  15706. %@NL@%
  15707. The %@AB@%feof%@AE@% or %@AB@%ferror%@AE@% function should be used to distinguish a read error from
  15708. an end-of-file condition. If %@AI@%size%@AE@% or %@AI@%count%@AE@% is 0, %@AB@%fread%@AE@% returns 0 and the
  15709. buffer contents are unchanged.  %@NL@%
  15710. %@NL@%
  15711. %@NL@%
  15712. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15713. %@NL@%
  15714. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  15715. %@NL@%
  15716. %@NL@%
  15717. %@NL@%
  15718. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15719. %@NL@%
  15720. %@AB@%fwrite%@AE@%, %@AB@%read%@AE@%  %@NL@%
  15721. %@NL@%
  15722. %@NL@%
  15723. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15724. %@NL@%
  15725. %@AS@%  /* FREAD.C: This program opens a file named FREAD.OUT and writes 25
  15726. %@AS@%   * characters to the file. It then tries to open FREAD.OUT and
  15727. %@AS@%   * read in 25 characters. If the attempt succeeds, the program
  15728. %@AS@%   * displays the number of actual items read.
  15729. %@AS@%   */%@AE@%%@NL@%
  15730. %@NL@%
  15731. %@AS@%  #include <stdio.h>
  15732. %@AS@%  
  15733. %@AS@%  void main()
  15734. %@AS@%  {
  15735. %@AS@%     FILE *stream;
  15736. %@AS@%     char list[30];
  15737. %@AS@%     int  i, numread, numwritten;
  15738. %@AS@%  
  15739. %@AS@%     /* Open file in text mode: */
  15740. %@AS@%     if( (stream = fopen( "fread.out", "w+t" )) != NULL )
  15741. %@AS@%     {
  15742. %@AS@%        for ( i = 0; i < 25; i++ )
  15743. %@AS@%           list[i] = 'z' - i;
  15744. %@AS@%        /* Write 25 characters to stream */
  15745. %@AS@%        numwritten = fwrite( list, sizeof( char ), 25, stream );
  15746. %@AS@%        printf( "Wrote %d items\n", numwritten );
  15747. %@AS@%        fclose( stream );
  15748. %@AS@%     }
  15749. %@AS@%     else
  15750. %@AS@%        printf( "Problem opening the file\n" );
  15751. %@AS@%  
  15752. %@AS@%     if( (stream = fopen( "fread.out", "r+t" )) != NULL )
  15753. %@AS@%     {
  15754. %@AS@%        /* Attempt to read in 25 characters */
  15755. %@AS@%        numread = fread( list, sizeof( char ), 25, stream );
  15756. %@AS@%        printf( "Number of items read = %d\n", numread );
  15757. %@AS@%        printf( "Contents of buffer = %.25s\n", list );
  15758. %@AS@%        fclose( stream );
  15759. %@AS@%     }
  15760. %@AS@%     else
  15761. %@AS@%        printf( "Was not able to open the file\n" );
  15762. %@AS@%  }%@AE@%%@NL@%
  15763. %@NL@%
  15764. %@NL@%
  15765. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15766. %@NL@%
  15767. %@AS@%  
  15768. %@AS@%  
  15769. %@AS@%  Wrote 25 items
  15770. %@AS@%  Number of items read = 25
  15771. %@AS@%  Contents of buffer = zyxwvutsrqponmlkjihgfedcb %@AE@%%@NL@%
  15772. %@NL@%
  15773. %@NL@%
  15774. %@NL@%
  15775. %@NL@%
  15776. %@QR:free@%%@NL@%
  15777. %@2@%%@CR:C6A01150592 @%%@AB@%free Functions%@AE@%%@EH@%%@NL@%
  15778. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15779. %@NL@%
  15780. %@NL@%
  15781. %@3@%%@AB@%Description%@CR:C6A01150593 @%%@CR:C6A01150594 @%%@CR:C6A01150595 @% %@CR:C6A01150596 @%%@CR:C6A01150597 @% %@CR:C6A01150598 @%%@CR:C6A01150599 @%%@CR:C6A01150600 @%%@AE@%%@EH@%%@NL@%
  15782. %@NL@%
  15783. Deallocate a memory block.  %@NL@%
  15784. %@NL@%
  15785. %@AB@%#include <stdlib.h>%@AE@%               For ANSI compatibility (%@AB@%free%@AE@% only)
  15786.  
  15787. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  15788.  
  15789. %@AS@%  void free( void *memblock );%@AE@%%@NL@%
  15790. %@NL@%
  15791. %@AS@%  void _bfree( _segment seg, void _based( void ) *memblock );%@AE@%%@NL@%
  15792. %@NL@%
  15793. %@AS@%  void _ffree( void _far *memblock );%@AE@%%@NL@%
  15794. %@NL@%
  15795. %@AS@%  void _nfree( void _near *memblock );%@AE@%%@NL@%
  15796. %@NL@%
  15797. %@AI@%memblock%@AE@%                          Allocated memory block
  15798.  
  15799. %@AI@%seg%@AE@%                               Based-heap segment selector
  15800.  
  15801. %@NL@%
  15802. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15803. %@NL@%
  15804. The %@AB@%free%@AE@% family of functions deallocates a memory block. The argument
  15805. %@AI@%memblock%@AE@% points to a memory block previously allocated through a call to
  15806. %@AB@%calloc%@AE@%, %@AB@%malloc%@AE@%, or %@AB@%realloc%@AE@%. The number of bytes freed is the number of bytes
  15807. specified when the block was allocated (or reallocated, in the case of
  15808. %@AB@%realloc%@AE@%). After the call, the freed block is available for allocation.  %@NL@%
  15809. %@NL@%
  15810. The %@AI@%seg%@AE@% argument specifies the based heap containing the memory block to be
  15811. freed by the %@AB@%_bfree%@AE@% function.  %@NL@%
  15812. %@NL@%
  15813. Attempting to free an invalid pointer may affect subsequent allocation and
  15814. cause errors. An invalid pointer is one not allocated with the appropriate
  15815. call.  %@NL@%
  15816. %@NL@%
  15817. The following restrictions apply to use of the %@AB@%free%@AE@%, %@AB@%_bfree%@AE@%, %@AB@%_ffree%@AE@%, and
  15818. %@AB@%_nfree%@AE@% functions:  %@NL@%
  15819. %@NL@%
  15820. %@AB@%Blocks allocated with:%@AE@%            %@AB@%Should be freed with:%@AE@%
  15821. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15822. %@AB@%calloc%@AE@%, %@AB@%malloc%@AE@%, %@AB@%realloc%@AE@%           %@AB@%free%@AE@%
  15823.  
  15824. %@AB@%_bcalloc%@AE@%,%@AB@% _bmalloc%@AE@%,%@AB@% _brealloc%@AE@%     %@AB@%_bfree%@AE@%
  15825.  
  15826. %@AB@%_fcalloc%@AE@%, %@AB@%_fmalloc%@AE@%, %@AB@%_frealloc%@AE@%     %@AB@%_ffree%@AE@%
  15827.  
  15828. %@AB@%_ncalloc%@AE@%,%@AB@% _nmalloc%@AE@%,%@AB@% _nrealloc%@AE@%     %@AB@%_nfree%@AE@%
  15829.  
  15830. A%@AB@% NULL%@AE@% pointer argument is ignored.  %@NL@%
  15831. %@NL@%
  15832. In large data models (compact-, large-, and huge-model programs), %@AB@%free%@AE@% maps
  15833. to %@AB@%_ffree%@AE@%. In small data models (tiny-, small-, and medium-model programs),
  15834. %@AB@%free%@AE@% maps to %@AB@%_nfree%@AE@%.  %@NL@%
  15835. %@NL@%
  15836. The various %@AB@%free%@AE@% functions deallocate a memory block in the segments shown
  15837. in the list below:  %@NL@%
  15838. %@NL@%
  15839. %@AB@%Function%@AE@%                          %@AB@%Data Segment%@AE@%
  15840. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15841. %@AB@%free%@AE@%                              Depends on data model of program
  15842.  
  15843. %@AB@%_bfree%@AE@%                            Based heap specified by %@AI@%seg%@AE@% value
  15844.  
  15845. %@AB@%_ffree%@AE@%                            Far heap (outside default data segment)
  15846.  
  15847. %@AB@%_nfree%@AE@%                            Near heap (inside default data segment)
  15848.  
  15849. %@NL@%
  15850. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15851. %@NL@%
  15852. None.  %@NL@%
  15853. %@NL@%
  15854. %@NL@%
  15855. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15856. %@NL@%
  15857. %@AB@%free%@AE@%  %@NL@%
  15858. %@NL@%
  15859. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  15860. %@NL@%
  15861. %@NL@%
  15862. %@AB@%_bfree, _ffree, _nfree%@AE@%  %@NL@%
  15863. %@NL@%
  15864.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  15865. %@NL@%
  15866. %@NL@%
  15867. %@NL@%
  15868. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15869. %@NL@%
  15870. %@AB@%calloc %@AE@%functions, %@AB@%malloc%@AE@% functions, %@AB@%realloc %@AE@%functions  %@NL@%
  15871. %@NL@%
  15872. %@NL@%
  15873. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15874. %@NL@%
  15875. %@AS@%  /* MALLOC.C: This program allocates memory with malloc, then frees
  15876. %@AS@%   * the memory with free.
  15877. %@AS@%   */
  15878. %@AS@%  
  15879. %@AS@%  #include <stdlib.h>         /* Definition of _MAX_PATH */
  15880. %@AS@%  #include <stdio.h>
  15881. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  15882. %@NL@%
  15883. %@AS@%  void main()
  15884. %@AS@%  {
  15885. %@AS@%     char *string;
  15886. %@AS@%  
  15887. %@AS@%     /* Allocate space for a path name */
  15888. %@AS@%     string = malloc( _MAX_PATH );
  15889. %@AS@%     if( string == NULL )
  15890. %@AS@%        printf( "Insufficient memory available\n" );
  15891. %@AS@%     else
  15892. %@AS@%        printf( "Memory space allocated for path name\n" );
  15893. %@AS@%     free( string );
  15894. %@AS@%     printf( "Memory freed\n" );
  15895. %@AS@%  }%@AE@%%@NL@%
  15896. %@NL@%
  15897. %@NL@%
  15898. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15899. %@NL@%
  15900. %@AS@%  
  15901. %@AS@%  
  15902. %@AS@%  Memory space allocated for path name
  15903. %@AS@%  Memory freed %@AE@%%@NL@%
  15904. %@NL@%
  15905. %@NL@%
  15906. %@NL@%
  15907. %@NL@%
  15908. %@QR:_freect@%%@NL@%
  15909. %@2@%%@CR:C6A01160601 @%%@AB@%_freect%@AE@%%@EH@%%@NL@%
  15910. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15911. %@NL@%
  15912. %@NL@%
  15913. %@3@%%@AB@%Description%@CR:C6A01160602 @%%@CR:C6A01160603 @% %@CR:C6A01160604 @%%@CR:C6A01160605 @%%@AE@%%@EH@%%@NL@%
  15914. %@NL@%
  15915. Returns the amount of memory available for memory allocation.  %@NL@%
  15916. %@NL@%
  15917. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  15918.  
  15919. %@AS@%  unsigned int _freect( size_t size );%@AE@%%@NL@%
  15920. %@NL@%
  15921. %@AI@%size%@AE@%                              Item size in bytes
  15922.  
  15923. %@NL@%
  15924. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  15925. %@NL@%
  15926. The %@AB@%_freect%@AE@% function tells you how much memory is available for dynamic
  15927. memory allocation in the near heap. It does so by returning the approximate
  15928. number of times your program can call%@AB@% _nmalloc%@AE@% (or %@AB@%malloc%@AE@% in small data
  15929. models) to allocate an item %@AI@%size%@AE@% bytes long in the near heap (default data
  15930. segment).  %@NL@%
  15931. %@NL@%
  15932. %@NL@%
  15933. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  15934. %@NL@%
  15935. The %@AB@%_freect%@AE@% function returns the number of calls as an unsigned integer.  %@NL@%
  15936. %@NL@%
  15937. %@NL@%
  15938. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  15939. %@NL@%
  15940.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  15941. %@NL@%
  15942. %@NL@%
  15943. %@NL@%
  15944. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  15945. %@NL@%
  15946. %@AB@%calloc%@AE@% functions,%@AB@% _expand%@AE@% functions, %@AB@%malloc%@AE@% functions, %@AB@%_memavl%@AE@%, %@AB@%_msize%@AE@%
  15947. functions, %@AB@% realloc%@AE@% functions  %@NL@%
  15948. %@NL@%
  15949. %@NL@%
  15950. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  15951. %@NL@%
  15952. %@AS@%  /* FREECT.C: This program determines how much free space is available for
  15953. %@AS@%   * integers in the default data segment. Then it allocates space for
  15954. %@AS@%   * 1,000 integers and checks the space again, using _freect.
  15955. %@AS@%   */
  15956. %@AS@%  
  15957. %@AS@%  #include <malloc.h>
  15958. %@AS@%  #include <stdio.h>
  15959. %@AS@%  
  15960. %@AS@%  void main()
  15961. %@AS@%  {
  15962. %@AS@%     int i;
  15963. %@AS@%  
  15964. %@AS@%     /* First report on the free space: */
  15965. %@AS@%     printf( "Integers (approximate) available on heap: %u\n\n",
  15966. %@AS@%             _freect( sizeof( int ) ) );
  15967. %@AS@%  
  15968. %@AS@%     /* Allocate space for 1000 integers: */
  15969. %@AS@%     for( i = 0; i < 1000; ++i )
  15970. %@AS@%        malloc( sizeof( int ) );%@AE@%%@NL@%
  15971. %@NL@%
  15972. %@AS@%  /* Report again on the free space: */
  15973. %@AS@%     printf( "After allocating space for 1000 integers:\n" );
  15974. %@AS@%     printf( "Integers (approximate) available on heap: %u\n\n",
  15975. %@AS@%             _freect( sizeof( int ) ) );
  15976. %@AS@%  
  15977. %@AS@%  }%@AE@%%@NL@%
  15978. %@NL@%
  15979. %@NL@%
  15980. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  15981. %@NL@%
  15982. %@AS@%  
  15983. %@AS@%  
  15984. %@AS@%  Integers (approximate) available on heap: 15212
  15985. %@AS@%  
  15986. %@AS@%  After allocating space for 1000 integers:
  15987. %@AS@%  Integers (approximate) available on heap: 14084 %@AE@%%@NL@%
  15988. %@NL@%
  15989. %@NL@%
  15990. %@NL@%
  15991. %@NL@%
  15992. %@QR:freopen@%%@NL@%
  15993. %@2@%%@CR:C6A01170606 @%%@AB@%freopen%@AE@%%@EH@%%@NL@%
  15994. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  15995. %@NL@%
  15996. %@NL@%
  15997. %@3@%%@AB@%Description%@CR:C6A01170607 @%%@CR:C6A01170608 @%%@CR:C6A01170609 @% %@CR:C6A01170610 @%%@CR:C6A01170611 @%%@CR:C6A01170612 @%%@CR:C6A01170613 @% %@CR:C6A01170614 @%%@CR:C6A01170615 @%%@AE@%%@EH@%%@NL@%
  15998. %@NL@%
  15999. Reassigns a file pointer.  %@NL@%
  16000. %@NL@%
  16001. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16002. %@NL@%
  16003. %@AS@%  FILE *freopen( const char *filename, const char *mode, FILE *stream );%@AE@%%@NL@%
  16004. %@NL@%
  16005. %@AI@%filename%@AE@%                          Path name of new file
  16006.  
  16007. %@AI@%mode%@AE@%                              Type of access permitted
  16008.  
  16009. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  16010.  
  16011. %@NL@%
  16012. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16013. %@NL@%
  16014. The %@AB@%freopen%@AE@% function closes the file currently associated with %@AI@%stream%@AE@% and
  16015. reassigns %@AI@%stream%@AE@% to the file specified by %@AI@%filename%@AE@%. The %@AB@%freopen%@AE@% function is
  16016. typically used to redirect the pre-opened files %@AB@%stdin%@AE@%, %@AB@%stdout%@AE@%, and %@AB@%stderr %@AE@%to
  16017. files specified by the user. The new file associated with%@AB@% %@AE@%%@AI@%stream%@AE@% is opened
  16018. with %@AI@%mode%@AE@%, which is a character string specifying the type of access
  16019. requested for the file, as follows: %@CR:C6A01170616 @%  %@NL@%
  16020. %@NL@%
  16021. %@AB@%Type%@AE@%                              %@AB@%Description %@AE@%
  16022. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16023. %@AB@%"r"%@AE@%                               Opens for reading. If the file does not 
  16024.                                   exist or cannot be found, the %@AB@%freopen%@AE@% 
  16025.                                   call fails. 
  16026.  
  16027. %@AB@%"w"%@AE@%                               Opens an empty file for writing. If the 
  16028.                                   given file exists, its contents are 
  16029.                                   destroyed. 
  16030.  
  16031. %@AB@%"a"%@AE@%                               Opens for writing at the end of the file
  16032.                                   (appending); creates the file first if 
  16033.                                   it does not exist.
  16034.  
  16035. %@AB@%"r+"%@AE@%                              Opens for both reading and writing. (The
  16036.                                   file must exist.)
  16037.  
  16038. %@AB@%"w+"%@AE@%                              Opens an empty file for both reading and
  16039.                                   writing. If the given file exists, its 
  16040.                                   contents are destroyed.
  16041.  
  16042. %@AB@%"a+"%@AE@%                              Opens for reading and appending; creates
  16043.                                   the file first if it does not exist.
  16044.  
  16045. Use the %@AB@%"w" %@AE@%and%@AB@% "w+" %@AE@%types with care, as they can destroy existing files.  %@NL@%
  16046. %@NL@%
  16047. When a file is opened with the %@AB@%"a"%@AE@% or %@AB@%"a+"%@AE@% access type, all write operations
  16048. take place at the end of the file. Although the file pointer can be
  16049. repositioned using %@AB@%fseek%@AE@% or %@AB@%rewind%@AE@%, the file pointer is always moved back to
  16050. the end of the file before any write operation is carried out. Thus,
  16051. existing data cannot be overwritten.  %@NL@%
  16052. %@NL@%
  16053. When the %@AB@%"r+"%@AE@%, %@AB@%"w+"%@AE@%, or %@AB@%"a+"%@AE@% access type is specified, both reading and
  16054. writing are allowed (the file is said to be open for "update"). However,
  16055. when you switch between reading and writing, there must be an intervening
  16056. %@AB@%fsetpos%@AE@%, %@AB@%fseek%@AE@%, or %@AB@%rewind%@AE@% operation. The current position can be specified
  16057. for the %@AB@%fsetpos%@AE@% or %@AB@%fseek%@AE@% operation, if desired.  %@NL@%
  16058. %@NL@%
  16059. In addition to the values listed above, one of the following characters may
  16060. be included in the %@AI@%mode%@AE@% string to specify the translation mode for newlines.%@CR:C6A01170617 @%
  16061. %@NL@%
  16062. %@NL@%
  16063. %@AB@%Mode%@AE@%                              %@AB@%Meaning%@AE@%
  16064. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16065. %@AB@%t%@AE@%                                 Open in text (translated) mode; 
  16066.                                   carriage-return-line-feed
  16067.                                   (CR-LF) combinations are translated into
  16068.                                   single line-feed (LF) characters on 
  16069.                                   input; LF characters are translated to 
  16070.                                   CR-LF combinations on output. Also, 
  16071.                                   CTRL+Z is interpreted as an end-of-file 
  16072.                                   character on input. In files opened for 
  16073.                                   reading, or writing and reading, the 
  16074.                                   run-time library checks for a CTRL+Z at 
  16075.                                   the end of the file and removes it, if 
  16076.                                   possible. This is done because using the
  16077.                                   %@AB@%fseek%@AE@% and %@AB@%ftell%@AE@% functions to move within
  16078.                                   a file may cause %@AB@%fseek%@AE@% to behave 
  16079.                                   improperly near the end of the file.
  16080.  
  16081. %@AB@%b%@AE@%                                 Open in binary (untranslated) mode; the 
  16082.                                   above translations are suppressed.
  16083.  
  16084. If %@AB@%t%@AE@% or %@AB@%b%@AE@% is not given in the %@AI@%mode%@AE@% string, the translation mode is defined
  16085. by the default mode variable %@AB@%_fmode%@AE@%.  %@NL@%
  16086. %@NL@%
  16087. See Section 2.7, "Input and Output," for a discussion of text and binary
  16088. modes.  %@NL@%
  16089. %@NL@%
  16090. %@NL@%
  16091. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16092. %@NL@%
  16093. The %@AB@%freopen%@AE@% function returns a pointer to the newly opened file. If an error
  16094. occurs, the original file is closed and the function returns a %@AB@%NULL%@AE@% pointer
  16095. value.  %@NL@%
  16096. %@NL@%
  16097. %@NL@%
  16098. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16099. %@NL@%
  16100. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  16101. %@NL@%
  16102. %@NL@%
  16103. The %@AB@%t%@AE@% option is not part of the ANSI standard for %@AB@%freopen%@AE@%; it is a Microsoft
  16104. extension that should not be used where ANSI portability is desired.  %@NL@%
  16105. %@NL@%
  16106. %@NL@%
  16107. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16108. %@NL@%
  16109. %@AB@%fclose%@AE@%, %@AB@%fcloseall%@AE@%, %@AB@%fdopen%@AE@%, %@AB@%fileno%@AE@%, %@AB@%fopen%@AE@%, %@AB@%open%@AE@%, %@AB@%setmode%@AE@%  %@NL@%
  16110. %@NL@%
  16111. %@NL@%
  16112. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16113. %@NL@%
  16114. %@AS@%  /* FREOPEN.C: This program reassigns stdaux to the file
  16115. %@AS@%   * named FREOPEN.OUT and writes a line to that file.
  16116. %@AS@%   */%@AE@%%@NL@%
  16117. %@NL@%
  16118. %@AS@%  #include <stdio.h>
  16119. %@AS@%  #include <stdlib.h>
  16120. %@AS@%  
  16121. %@AS@%  FILE *stream;
  16122. %@AS@%  
  16123. %@AS@%  void main()
  16124. %@AS@%  {
  16125. %@AS@%  
  16126. %@AS@%     /* Reassign "stdaux" to "freopen.out": */
  16127. %@AS@%     stream = freopen( "freopen.out", "w", stdaux );
  16128. %@AS@%  
  16129. %@AS@%     if( stream == NULL )
  16130. %@AS@%        fprintf( stdout, "error on freopen\n" );
  16131. %@AS@%     else
  16132. %@AS@%     {
  16133. %@AS@%        fprintf( stream, "This will go to the file 'freopen.out'\n" );
  16134. %@AS@%        fprintf( stdout, "successfully reassigned\n" );
  16135. %@AS@%        fclose( stream );
  16136. %@AS@%     }
  16137. %@AS@%     system( "type freopen.out" );
  16138. %@AS@%  }%@AE@%%@NL@%
  16139. %@NL@%
  16140. %@NL@%
  16141. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16142. %@NL@%
  16143. %@AS@%  
  16144. %@AS@%  
  16145. %@AS@%  successfully reassigned
  16146. %@AS@%  This will go to the file 'freopen.out' %@AE@%%@NL@%
  16147. %@NL@%
  16148. %@NL@%
  16149. %@NL@%
  16150. %@NL@%
  16151. %@QR:frexp@%%@QR:frexpl@%%@NL@%
  16152. %@2@%%@CR:C6A01180618 @%%@AB@%frexp, frexpl%@AE@%%@EH@%%@NL@%
  16153. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16154. %@NL@%
  16155. %@NL@%
  16156. %@3@%%@AB@%Description%@CR:C6A01180619 @%%@CR:C6A01180620 @%%@CR:C6A01180621 @% %@CR:C6A01180622 @%%@AE@%%@EH@%%@NL@%
  16157. %@NL@%
  16158. Get the mantissa and exponent of a floating-point number.  %@NL@%
  16159. %@NL@%
  16160. %@AS@%  #include <math.h>%@AE@%%@NL@%
  16161. %@NL@%
  16162. %@AS@%  double frexp( double x, int *expptr );%@AE@%%@NL@%
  16163. %@NL@%
  16164. %@AS@%  long double frexpl( long double x, int *expptr );%@AE@%%@NL@%
  16165. %@NL@%
  16166. %@AI@%x%@AE@%                                 Floating-point value
  16167.  
  16168. %@AI@%expptr%@AE@%                            Pointer to stored integer exponent
  16169.  
  16170. %@NL@%
  16171. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16172. %@NL@%
  16173. The %@AB@%frexp%@AE@% and %@AB@%frexpl%@AE@% functions break down the floating-point value (%@AI@%x%@AE@%) into
  16174. a mantissa (%@AI@%m%@AE@%) and an exponent (%@AI@%n%@AE@%), such that the absolute value of %@AI@%m%@AE@% is
  16175. greater than or equal to 0.5 and less than 1.0, and %@AI@%x%@AE@% = %@AI@%m%@AE@%%@AB@%*%@AE@%2n. The integer
  16176. exponent %@AI@%n%@AE@% is stored at the location pointed to by %@AI@%expptr%@AE@%.  %@NL@%
  16177. %@NL@%
  16178. The %@AB@%frexpl%@AE@% function is the 80-bit counterpart and uses an 80-bit, 10-byte
  16179. coprocessor form of arguments and return values. See the reference page on
  16180. the long double functions for more details on this data type.  %@NL@%
  16181. %@NL@%
  16182. %@NL@%
  16183. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16184. %@NL@%
  16185. These functions return the mantissa. If %@AI@%x%@AE@% is 0, the function returns 0 for
  16186. both the mantissa and the exponent. There is no error return.  %@NL@%
  16187. %@NL@%
  16188. %@NL@%
  16189. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16190. %@NL@%
  16191. %@AB@%frexp%@AE@%  %@NL@%
  16192. %@NL@%
  16193. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  16194. %@NL@%
  16195. %@NL@%
  16196. %@AB@%frexpl%@AE@%  %@NL@%
  16197. %@NL@%
  16198.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  16199. %@NL@%
  16200. %@NL@%
  16201. %@NL@%
  16202. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16203. %@NL@%
  16204. %@AB@%ldexp%@AE@% functions, %@AB@%modf%@AE@%  %@NL@%
  16205. %@NL@%
  16206. %@NL@%
  16207. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16208. %@NL@%
  16209. %@AS@%  /* FREXP.C: This program calculates frexp( 16.4, &n ), then displays y
  16210. %@AS@%   * and n.
  16211. %@AS@%   */
  16212. %@AS@%  
  16213. %@AS@%  #include <math.h>
  16214. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16215. %@NL@%
  16216. %@AS@%  void main()
  16217. %@AS@%  {
  16218. %@AS@%     double x, y;
  16219. %@AS@%     int n;
  16220. %@AS@%  
  16221. %@AS@%     x = 16.4;
  16222. %@AS@%     y = frexp( x, &n );
  16223. %@AS@%     printf( "frexp( %f, &n ) = %f, n = %d\n", x, y, n );
  16224. %@AS@%  }%@AE@%%@NL@%
  16225. %@NL@%
  16226. %@NL@%
  16227. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16228. %@NL@%
  16229. %@AS@%  
  16230. %@AS@%  
  16231. %@AS@%  frexp( 16.400000, &n ) = 0.512500, n = 5 %@AE@%%@NL@%
  16232. %@NL@%
  16233. %@NL@%
  16234. %@NL@%
  16235. %@NL@%
  16236. %@QR:fscanf@%%@NL@%
  16237. %@2@%%@CR:C6A01190623 @%%@AB@%fscanf%@AE@%%@EH@%%@NL@%
  16238. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16239. %@NL@%
  16240. %@NL@%
  16241. %@3@%%@AB@%Description%@CR:C6A01190624 @%%@CR:C6A01190625 @% %@CR:C6A01190626 @%%@CR:C6A01190627 @% %@CR:C6A01190628 @%%@AE@%%@EH@%%@NL@%
  16242. %@NL@%
  16243. Reads formatted data from a stream.  %@NL@%
  16244. %@NL@%
  16245. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16246. %@NL@%
  16247. %@AS@%  int fscanf( FILE *stream, const char *format [[, argument]]...  )%@AE@%%@NL@%
  16248. %@NL@%
  16249. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  16250.  
  16251. %@AI@%format%@AE@%                            Format-control string
  16252.  
  16253. %@AI@%argument%@AE@%                          Optional arguments
  16254.  
  16255. %@NL@%
  16256. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16257. %@NL@%
  16258. The %@AB@%fscanf%@AE@% function reads data from the current position of %@AI@%stream%@AE@% into the
  16259. locations given by %@AI@%argument%@AE@% (if any). Each argument must be a pointer to a
  16260. variable with a type that corresponds to a type specifier in %@AI@%format%@AE@%. The
  16261. format controls the interpretation of the input fields and has the same form
  16262. and function as the %@AI@%format%@AE@% argument for the %@AB@%scanf%@AE@% function; see %@AB@%scanf%@AE@% for a
  16263. description of %@AI@%format%@AE@%.  %@NL@%
  16264. %@NL@%
  16265. %@NL@%
  16266. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16267. %@NL@%
  16268. The %@AB@%fscanf%@AE@% function returns the number of fields that were successfully
  16269. converted and assigned. The return value does not include fields that were
  16270. read but not assigned.  %@NL@%
  16271. %@NL@%
  16272. The return value is %@AB@%EOF%@AE@% for an error or end-of-file on %@AI@%stream%@AE@% before the
  16273. first conversion. A return value of 0 means that no fields were assigned.  %@NL@%
  16274. %@NL@%
  16275. %@NL@%
  16276. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16277. %@NL@%
  16278. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  16279. %@NL@%
  16280. %@NL@%
  16281. %@NL@%
  16282. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16283. %@NL@%
  16284. %@AB@%cscanf%@AE@%, %@AB@%fprintf%@AE@%, %@AB@%scanf%@AE@%, %@AB@%sscanf%@AE@%  %@NL@%
  16285. %@NL@%
  16286. %@NL@%
  16287. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16288. %@NL@%
  16289. %@AS@%  /* FSCANF.C: This program writes formatted data to a file. It
  16290. %@AS@%   * then uses fscanf to read the various data back from the file.
  16291. %@AS@%   */
  16292. %@AS@%  
  16293. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16294. %@NL@%
  16295. %@AS@%  FILE *stream;
  16296. %@AS@%  
  16297. %@AS@%  void main()
  16298. %@AS@%  {
  16299. %@AS@%     long l;
  16300. %@AS@%     float fp;
  16301. %@AS@%     char s[81];
  16302. %@AS@%     char c;
  16303. %@AS@%     int result;
  16304. %@AS@%  
  16305. %@AS@%     stream = fopen( "fscanf.out", "w+" );
  16306. %@AS@%     if( stream == NULL )
  16307. %@AS@%        printf( "The file fscanf.out was not opened\n" );
  16308. %@AS@%     else
  16309. %@AS@%     {
  16310. %@AS@%        fprintf( stream, "%s %ld %f%c", "a-string", 65000, 3.14159, 'x' );
  16311. %@AS@%  
  16312. %@AS@%        /* Set pointer to beginning of file: */
  16313. %@AS@%        fseek( stream, 0L, SEEK_SET );
  16314. %@AS@%  
  16315. %@AS@%        /* Read data back from file: */
  16316. %@AS@%        fscanf( stream, "%s", s );
  16317. %@AS@%        fscanf( stream, "%ld", &l );
  16318. %@AS@%        fscanf( stream, "%f", &fp );
  16319. %@AS@%        fscanf( stream, "%c", &c );
  16320. %@AS@%  
  16321. %@AS@%        /* Output data read: */
  16322. %@AS@%        printf( "%s\n", s );
  16323. %@AS@%        printf( "%ld\n", l );
  16324. %@AS@%        printf( "%f\n", fp );
  16325. %@AS@%        printf( "%c\n", c );
  16326. %@AS@%  
  16327. %@AS@%        fclose( stream );
  16328. %@AS@%     }
  16329. %@AS@%  }%@AE@%%@NL@%
  16330. %@NL@%
  16331. %@NL@%
  16332. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16333. %@NL@%
  16334. %@AS@%  
  16335. %@AS@%  
  16336. %@AS@%  a-string
  16337. %@AS@%  65000
  16338. %@AS@%  3.141590
  16339. %@AS@%  x %@AE@%%@NL@%
  16340. %@NL@%
  16341. %@NL@%
  16342. %@NL@%
  16343. %@NL@%
  16344. %@QR:fseek@%%@NL@%
  16345. %@2@%%@CR:C6A01200629 @%%@AB@%fseek%@AE@%%@EH@%%@NL@%
  16346. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16347. %@NL@%
  16348. %@NL@%
  16349. %@3@%%@AB@%Description%@CR:C6A01200630 @%%@CR:C6A01200631 @% %@CR:C6A01200632 @%%@CR:C6A01200633 @% %@CR:C6A01200634 @%%@AE@%%@EH@%%@NL@%
  16350. %@NL@%
  16351. Moves the file pointer to a specified location.  %@NL@%
  16352. %@NL@%
  16353. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16354. %@NL@%
  16355. %@AS@%  int fseek( FILE *stream, long offset, int origin );%@AE@%%@NL@%
  16356. %@NL@%
  16357. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  16358.  
  16359. %@AI@%offset%@AE@%                            Number of bytes from %@AI@%origin%@AE@%
  16360.  
  16361. %@AI@%origin%@AE@%                            Initial position
  16362.  
  16363. %@NL@%
  16364. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16365. %@NL@%
  16366. The %@AB@%fseek%@AE@% function moves the file pointer (if any) associated with %@AI@%stream%@AE@% to
  16367. a new location that is %@AI@%offset%@AE@% bytes from %@AI@%origin%@AE@%. The next operation on the
  16368. stream takes place at the new location. On a stream open for update, the
  16369. next operation can be either a read or a write.  %@NL@%
  16370. %@NL@%
  16371. The argument %@AI@%origin%@AE@% must be one of the following constants defined in
  16372. STDIO.H:  %@NL@%
  16373. %@NL@%
  16374. %@AB@%Origin%@AE@%                            %@AB@%Definition%@AE@%
  16375. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16376. %@AB@%SEEK_CUR%@AE@%                          Current position of file pointer
  16377.  
  16378. %@AB@%SEEK_END%@AE@%                          End of file
  16379.  
  16380. %@AB@%SEEK_SET%@AE@%                          Beginning of file
  16381.  
  16382. The %@AB@%fseek%@AE@% function can be used to reposition the pointer anywhere in a file.
  16383. The pointer can also be positioned beyond the end of the file. However, an
  16384. attempt to position the pointer in front of the beginning of the file causes
  16385. an error.  %@NL@%
  16386. %@NL@%
  16387. The %@AB@%fseek%@AE@% function clears the end-of-file indicator and negates the effect
  16388. of any prior %@AB@%ungetc%@AE@% calls against %@AI@%stream%@AE@%.  %@NL@%
  16389. %@NL@%
  16390. When a file is opened for appending data, the current file position is
  16391. determined by the last I/O operation, not by where the next write would
  16392. occur. If no I/O operation has yet occurred on a file opened for appending,
  16393. the file position is the start of the file.  %@NL@%
  16394. %@NL@%
  16395. For streams opened in text mode, %@AB@%fseek%@AE@% has limited use because
  16396. carriage-return-line-feed translations can cause %@AB@%fseek%@AE@% to produce unexpected
  16397. results. The only %@AB@%fseek%@AE@% operations guaranteed to work on streams opened in
  16398. text mode are the following:  %@NL@%
  16399. %@NL@%
  16400. %@NL@%
  16401.   ■   Seeking with an offset of 0 relative to any of the %@AI@%origin%@AE@% values%@NL@%
  16402. %@NL@%
  16403.   ■   Seeking from the beginning of the file with an offset value returned
  16404.       from a call to %@AB@%ftell%@AE@%%@NL@%
  16405. %@NL@%
  16406. %@NL@%
  16407. %@NL@%
  16408. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16409. %@NL@%
  16410. If successful, %@AB@%fseek%@AE@% returns 0. Otherwise, it returns a nonzero value. On
  16411. devices incapable of seeking, the return value is undefined.  %@NL@%
  16412. %@NL@%
  16413. %@NL@%
  16414. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16415. %@NL@%
  16416. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  16417. %@NL@%
  16418. %@NL@%
  16419. %@NL@%
  16420. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16421. %@NL@%
  16422. %@AB@%ftell%@AE@%, %@AB@%lseek%@AE@%, %@AB@%rewind%@AE@%  %@NL@%
  16423. %@NL@%
  16424. %@NL@%
  16425. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16426. %@NL@%
  16427. %@AS@%  /* FSEEK.C: This program opens the file FSEEK.OUT and
  16428. %@AS@%   * moves the pointer to the file's beginning.
  16429. %@AS@%   */
  16430. %@AS@%  
  16431. %@AS@%  #include <stdio.h>
  16432. %@AS@%  
  16433. %@AS@%  void main()
  16434. %@AS@%  {
  16435. %@AS@%     FILE *stream;
  16436. %@AS@%     char line[81];
  16437. %@AS@%     int  result;
  16438. %@AS@%  
  16439. %@AS@%     stream = fopen( "fseek.out", "w+" );
  16440. %@AS@%     if( stream == NULL )
  16441. %@AS@%        printf( "The file fseek.out was not opened\n" );
  16442. %@AS@%     else
  16443. %@AS@%     {
  16444. %@AS@%        fprintf( stream, "The fseek begins here: "
  16445. %@AS@%                         "This is the file 'fseek.out'.\n" );
  16446. %@AS@%        result = fseek( stream, 23L, SEEK_SET);
  16447. %@AS@%        if( result )
  16448. %@AS@%           perror( "Fseek failed" );
  16449. %@AS@%        else
  16450. %@AS@%        {
  16451. %@AS@%           printf( "File pointer is set to middle of first line.\n" );
  16452. %@AS@%           fgets( line, 80, stream );
  16453. %@AS@%           printf( "%s", line );
  16454. %@AS@%        }
  16455. %@AS@%        fclose( stream );
  16456. %@AS@%     }
  16457. %@AS@%  }%@AE@%%@NL@%
  16458. %@NL@%
  16459. %@NL@%
  16460. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16461. %@NL@%
  16462. %@AS@%  
  16463. %@AS@%  
  16464. %@AS@%  File pointer is set to middle of first line.
  16465. %@AS@%  This is the file 'fseek.out'. %@AE@%%@NL@%
  16466. %@NL@%
  16467. %@NL@%
  16468. %@NL@%
  16469. %@NL@%
  16470. %@QR:fsetpos@%%@NL@%
  16471. %@2@%%@CR:C6A01210635 @%%@AB@%fsetpos%@AE@%%@EH@%%@NL@%
  16472. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16473. %@NL@%
  16474. %@NL@%
  16475. %@3@%%@AB@%Description%@CR:C6A01210636 @%%@CR:C6A01210637 @% %@CR:C6A01210638 @%%@CR:C6A01210639 @% %@CR:C6A01210640 @%%@AE@%%@EH@%%@NL@%
  16476. %@NL@%
  16477. Sets the stream-position indicator.  %@NL@%
  16478. %@NL@%
  16479. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16480. %@NL@%
  16481. %@AS@%  int fsetpos( FILE *stream, const fpos_t *pos ) ;%@AE@%%@NL@%
  16482. %@NL@%
  16483. %@AI@%stream%@AE@%                            Target stream
  16484.  
  16485. %@AI@%pos%@AE@%                               Position-indicator storage
  16486.  
  16487. %@NL@%
  16488. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16489. %@NL@%
  16490. The %@AB@%fsetpos%@AE@% function sets the file-position indicator for %@AI@%stream%@AE@% to the
  16491. value of %@AI@%pos%@AE@%, which is obtained in a prior call to %@AB@%fgetpos%@AE@% against %@AI@%stream%@AE@%.  %@NL@%
  16492. %@NL@%
  16493. The function clears the end-of-file indicator and undoes any effects of the
  16494. %@AB@%ungetc%@AE@% function on %@AI@%stream%@AE@%. After calling %@AB@%fsetpos%@AE@%, the next operation on
  16495. %@AI@%stream%@AE@% may be either input or output.  %@NL@%
  16496. %@NL@%
  16497. %@NL@%
  16498. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16499. %@NL@%
  16500. If successful, the %@AB@%fsetpos%@AE@% function returns 0. On failure, the function
  16501. returns a nonzero value and sets %@AB@%errno%@AE@% to one of the following manifest
  16502. constants (defined in ERRNO.H):  %@NL@%
  16503. %@NL@%
  16504. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  16505. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16506. %@AB@%EBADF%@AE@%                             The object that %@AI@%stream%@AE@% points to is not 
  16507.                                   a valid file handle, or the file is not 
  16508.                                   accessible.
  16509.  
  16510. %@AB@%EINVAL%@AE@%                            An invalid %@AI@%stream%@AE@% value was passed.
  16511.  
  16512. %@NL@%
  16513. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16514. %@NL@%
  16515. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  16516. %@NL@%
  16517. %@NL@%
  16518. %@NL@%
  16519. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16520. %@NL@%
  16521. %@AB@%fgetpos%@AE@%  %@NL@%
  16522. %@NL@%
  16523. %@NL@%
  16524. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16525. %@NL@%
  16526. %@AS@%  /* FGETPOS.C: This program opens a file and reads bytes at several
  16527. %@AS@%   * different locations.
  16528. %@AS@%   */
  16529. %@AS@%  
  16530. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16531. %@NL@%
  16532. %@AS@%  void main()
  16533. %@AS@%  {
  16534. %@AS@%     FILE   *stream;
  16535. %@AS@%     fpos_t pos;
  16536. %@AS@%     int    val;
  16537. %@AS@%     char   buffer[20];
  16538. %@AS@%  
  16539. %@AS@%     if( (stream = fopen( "fgetpos.c", "rb" )) == NULL )
  16540. %@AS@%        printf( "Trouble opening file\n" );
  16541. %@AS@%     else
  16542. %@AS@%     {
  16543. %@AS@%        /* Read some data and then check the position. */
  16544. %@AS@%        fread( buffer, sizeof( char ), 10, stream );
  16545. %@AS@%        if( fgetpos( stream, &pos ) != 0 )
  16546. %@AS@%           perror( "fgetpos error" );
  16547. %@AS@%        else
  16548. %@AS@%        {
  16549. %@AS@%           fread( buffer, sizeof( char ), 10, stream );
  16550. %@AS@%           printf( "10 bytes at byte %ld: %.10s\n", pos, buffer );
  16551. %@AS@%        }
  16552. %@AS@%  
  16553. %@AS@%        /* Set a new position and read more data. */
  16554. %@AS@%        pos = 140;
  16555. %@AS@%        if( fsetpos( stream, &pos ) != 0 )
  16556. %@AS@%           perror( "fsetpos error" );
  16557. %@AS@%  
  16558. %@AS@%        fread( buffer, sizeof( char ), 10, stream );
  16559. %@AS@%           printf( "10 bytes at byte %ld: %.10s\n", pos, buffer );
  16560. %@AS@%  
  16561. %@AS@%        fclose( stream );
  16562. %@AS@%     }
  16563. %@AS@%  }%@AE@%%@NL@%
  16564. %@NL@%
  16565. %@NL@%
  16566. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16567. %@NL@%
  16568. %@AS@%  
  16569. %@AS@%  
  16570. %@AS@%  10 bytes at byte 10: .C: This p
  16571. %@AS@%  10 bytes at byte 140:   FILE   * %@AE@%%@NL@%
  16572. %@NL@%
  16573. %@NL@%
  16574. %@NL@%
  16575. %@NL@%
  16576. %@QR:_fsopen@%%@NL@%
  16577. %@2@%%@CR:C6A01220641 @%%@AB@%_fsopen%@AE@%%@EH@%%@NL@%
  16578. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16579. %@NL@%
  16580. %@NL@%
  16581. %@3@%%@AB@%Description%@CR:C6A01220642 @%%@CR:C6A01220643 @% %@CR:C6A01220644 @%%@CR:C6A01220645 @%%@CR:C6A01220646 @%%@CR:C6A01220647 @% %@CR:C6A01220648 @%%@AE@%%@EH@%%@NL@%
  16582. %@NL@%
  16583. Opens a stream with file sharing.  %@NL@%
  16584. %@NL@%
  16585. %@AB@%#include <stdio.h>%@AE@%                
  16586.  
  16587. %@AB@%#include <share.h>%@AE@%                %@AI@%shflag%@AE@% constants
  16588.  
  16589. %@AS@%  FILE *_fsopen( const char *filename, const char *mode, int shflag );%@AE@%%@NL@%
  16590. %@NL@%
  16591. %@AI@%filename%@AE@%                          File name to open
  16592.  
  16593. %@AI@%mode%@AE@%                              Type of access permitted
  16594.  
  16595. %@AI@%shflag%@AE@%                            Type of sharing allowed
  16596.  
  16597. %@NL@%
  16598. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16599. %@NL@%
  16600. The %@AB@%_fsopen%@AE@% function opens the file specified by %@AI@%filename%@AE@% as a stream and
  16601. prepares the file for subsequent shared reading or writing, as defined by
  16602. the %@AI@%mode%@AE@% and %@AI@%shflag%@AE@% arguments.  %@NL@%
  16603. %@NL@%
  16604. The character string %@AI@%mode%@AE@% specifies the type of access requested for the
  16605. file, as follows:  %@NL@%
  16606. %@NL@%
  16607. %@AB@%Type%@AE@%                              %@AB@%Description%@AE@%
  16608. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16609. %@AB@%"r"%@AE@%                               Opens for reading. If the file does not 
  16610.                                   exist or cannot be found, the %@AB@%_fsopen%@AE@% 
  16611.                                   call will fail.
  16612.  
  16613. %@AB@%"w"%@AE@%                               Opens an empty file for writing. If the 
  16614.                                   given file exists, its contents are 
  16615.                                   destroyed. 
  16616.  
  16617. %@AB@%"a"%@AE@%                               Opens for writing at the end of the file
  16618.                                   (appending); creates the file first if 
  16619.                                   it does not exist.
  16620.  
  16621. %@AB@%"r+"%@AE@%                              Opens for both reading and writing. (The
  16622.                                   file must exist.)
  16623.  
  16624. %@AB@%"w+"%@AE@%                              Opens an empty file for both reading and
  16625.                                   writing. If the given file exists, its 
  16626.                                   contents are destroyed.
  16627.  
  16628. %@AB@%"a+"%@AE@%                              Opens for reading and appending; creates
  16629.                                   the file first if it does not exist.
  16630.  
  16631. Use the %@AB@%"w"%@AE@% and %@AB@%"w+"%@AE@% types with care, as they can destroy existing files.  %@NL@%
  16632. %@NL@%
  16633. When a file is opened with the %@AB@%"a"%@AE@% or %@AB@%"a+"%@AE@% access type, all write operations
  16634. occur at the end of the file. Although the file pointer can be repositioned
  16635. using %@AB@%fseek%@AE@% or%@AB@% rewind%@AE@%, the file pointer is always moved back to the end of
  16636. the file before any write operation is carried out. Thus, existing data
  16637. cannot be overwritten.  %@NL@%
  16638. %@NL@%
  16639. When the %@AB@%"r+"%@AE@%, %@AB@%"w+"%@AE@%, or %@AB@%"a+" %@AE@% access type is specified, both reading and
  16640. writing are allowed (the file is said to be open for "update"). However,
  16641. when switching between reading and writing, there must be an intervening
  16642. %@AB@%fsetpos%@AE@%, %@AB@%fseek%@AE@%, or %@AB@%rewind%@AE@% operation. The current position can be specified
  16643. for the %@AB@%fsetpos%@AE@% or %@AB@%fseek%@AE@% operation, if desired.  %@NL@%
  16644. %@NL@%
  16645. In addition to the values listed above, one of the following characters can
  16646. be included in %@AI@%mode%@AE@% to specify the translation mode for newlines: %@CR:C6A01220649 @%%@CR:C6A01220650 @%%@CR:C6A01220651 @%%@CR:C6A01220652 @%  %@NL@%
  16647. %@NL@%
  16648. %@AB@%Mode%@AE@%                              %@AB@%Meaning%@AE@%
  16649. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16650. %@AB@%t%@AE@%                                 Open in text (translated) mode. In this 
  16651.                                   mode, carriage-return-line-feed (CR-LF) 
  16652.                                   combinations are translated into single 
  16653.                                   line feeds (LF) on input and LF 
  16654.                                   characters are translated to CR-LF 
  16655.                                   combinations on output. Also, CTRL+Z is 
  16656.                                   interpreted as an end-of-file character 
  16657.                                   on input. In files opened for reading or
  16658.                                   reading/writing, %@AB@%_fsopen%@AE@% checks for a 
  16659.                                   CTRL+Z at the end of the file and 
  16660.                                   removes it, if possible. This is done 
  16661.                                   because using the %@AB@%fseek%@AE@% and %@AB@%ftell%@AE@% 
  16662.                                   functions to move within a file that 
  16663.                                   ends with a CTRL+Z may cause %@AB@%fseek%@AE@% to 
  16664.                                   behave improperly near the end of the 
  16665.                                   file.
  16666.  
  16667. %@AB@%b%@AE@%                                 Open in binary (untranslated) mode; the 
  16668.                                   above translations are suppressed.
  16669.  
  16670. If %@AB@%t%@AE@% or %@AB@%b%@AE@% is not given in %@AI@%mode%@AE@%, the translation mode is defined by the
  16671. default-mode variable %@AB@%_fmode%@AE@%. If %@AB@%t%@AE@% or %@AB@%b%@AE@% is prefixed to the argument, the
  16672. function will fail and will return %@AB@%NULL%@AE@%.  %@NL@%
  16673. %@NL@%
  16674. See Section 2.7, "Input and Output," for a discussion of text and binary
  16675. modes.  %@NL@%
  16676. %@NL@%
  16677. The argument %@AI@%shflag%@AE@% is a constant expression consisting of one of the
  16678. following manifest constants, defined in SHARE.H.  If SHARE.COM ─or
  16679. SHARE.EXE for some versions of DOS─ is not installed, DOS ignores the
  16680. sharing mode. (See your system documentation for detailed information about
  16681. sharing modes.)  %@NL@%
  16682. %@NL@%
  16683. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  16684. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16685. %@AB@%SH_COMPAT%@AE@%                         Sets compatibility mode (not available 
  16686.                                   in OS/2)
  16687.  
  16688. %@AB@%SH_DENYNO%@AE@%                         Permits read and write access
  16689.  
  16690. %@AB@%SH_DENYRD%@AE@%                         Denies read access to file
  16691.  
  16692. %@AB@%SH_DENYRW%@AE@%                         Denies read and write access to file
  16693.  
  16694. %@AB@%SH_DENYWR%@AE@%                         Denies write access to file
  16695.  
  16696. The %@AB@%_fsopen%@AE@% function should be used only under OS/2 and DOS versions 3.0 and
  16697. later. Under earlier versions of DOS, the %@AI@%shflag%@AE@% argument is ignored.  %@NL@%
  16698. %@NL@%
  16699. %@NL@%
  16700. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16701. %@NL@%
  16702. The %@AB@%_fsopen%@AE@% function returns a pointer to the stream. A %@AB@%NULL%@AE@% pointer value
  16703. indicates an error.  %@NL@%
  16704. %@NL@%
  16705. %@NL@%
  16706. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16707. %@NL@%
  16708.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  16709. %@NL@%
  16710. %@NL@%
  16711. %@NL@%
  16712. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16713. %@NL@%
  16714. %@AB@%fclose%@AE@%, %@AB@%fcloseall%@AE@%, %@AB@%fdopen%@AE@%, %@AB@%ferror%@AE@%, %@AB@%fileno%@AE@%, %@AB@%fopen%@AE@%, %@AB@%freopen%@AE@%, %@AB@%open%@AE@%, %@AB@%setmode%@AE@%,
  16715. %@AB@%sopen%@AE@%  %@NL@%
  16716. %@NL@%
  16717. %@NL@%
  16718. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16719. %@NL@%
  16720. %@AS@%  /* FSOPEN.C: This program opens files named "data" and "data2". It uses
  16721. %@AS@%   * fclose to close "data" and fcloseall to close all remaining files.
  16722. %@AS@%   */
  16723. %@AS@%  
  16724. %@AS@%  #include <stdio.h>
  16725. %@AS@%  #include <share.h>
  16726. %@AS@%  
  16727. %@AS@%  FILE *stream;
  16728. %@AS@%  
  16729. %@AS@%  void main()
  16730. %@AS@%  {
  16731. %@AS@%     FILE *stream;
  16732. %@AS@%  
  16733. %@AS@%     /* Open output file for writing. Using _fsopen allows us to ensure
  16734. %@AS@%      * that no one else writes to the file while we are writing to it.
  16735. %@AS@%      */
  16736. %@AS@%     if( (stream = _fsopen( "outfile", "wt", SH_DENYWR )) != NULL )
  16737. %@AS@%     {
  16738. %@AS@%        fprintf( stream, "No one else in the network can write "
  16739. %@AS@%                         "to this file until we are done.\n" );
  16740. %@AS@%        fclose( stream );
  16741. %@AS@%     }
  16742. %@AS@%     /* Now others can write to the file while we read it. */
  16743. %@AS@%     system( "type outfile" );
  16744. %@AS@%  }%@AE@%%@NL@%
  16745. %@NL@%
  16746. %@NL@%
  16747. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16748. %@NL@%
  16749. %@AS@%  
  16750. %@AS@%  
  16751. %@AS@%  No one else in the network can write to this file until we are done. %@AE@%%@NL@%
  16752. %@NL@%
  16753. %@NL@%
  16754. %@NL@%
  16755. %@NL@%
  16756. %@QR:fstat@%%@NL@%
  16757. %@2@%%@CR:C6A01230653 @%%@AB@%fstat%@AE@%%@EH@%%@NL@%
  16758. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16759. %@NL@%
  16760. %@NL@%
  16761. %@3@%%@AB@%Description%@CR:C6A01230654 @%%@CR:C6A01230655 @%%@CR:C6A01230656 @% %@CR:C6A01230657 @%%@AE@%%@EH@%%@NL@%
  16762. %@NL@%
  16763. Gets information about an open file.  %@NL@%
  16764. %@NL@%
  16765. %@AS@%  #include <sys\types.h>%@AE@%%@NL@%
  16766. %@NL@%
  16767. %@AS@%  #include <sys\stat.h>%@AE@%%@NL@%
  16768. %@NL@%
  16769. %@AS@%  int fstat( int handle, struct stat *buffer );%@AE@%%@NL@%
  16770. %@NL@%
  16771. %@AI@%handle%@AE@%                            Handle of open file
  16772.  
  16773. %@AI@%buffer%@AE@%                            Pointer to structure to store results
  16774.  
  16775. %@NL@%
  16776. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16777. %@NL@%
  16778. The %@AB@%fstat%@AE@% function obtains information about the open file associated with
  16779. %@AI@%handle%@AE@% and stores it in the structure pointed to by %@AI@%buffer%@AE@%. The structure,
  16780. whose type %@AB@%stat%@AE@% is defined in SYS\STAT.H, contains the following fields:   %@CR:C6A01230658 @%
  16781. %@NL@%
  16782. %@NL@%
  16783. %@AB@%Field%@AE@%                             %@AB@%Value%@AE@%
  16784. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16785. %@AB@%st_atime%@AE@%                          Time of last modification of file (same 
  16786.                                   as %@AB@%st_mtime%@AE@% and %@AB@%st_ctime%@AE@%).
  16787.  
  16788. %@AB@%st_ctime%@AE@%                          Time of last modification of file (same 
  16789.                                   as %@AB@%st_atime%@AE@% and %@AB@%st_mtime%@AE@%).
  16790.  
  16791. %@AB@%st_dev%@AE@%                            Either the drive number of the disk 
  16792.                                   containing the file, or %@AI@%handle%@AE@% in the 
  16793.                                   case of a device (same as %@AB@%st_rdev%@AE@%).
  16794.  
  16795. %@AB@%st_mode%@AE@%                           Bit mask for file-mode information. The %@AB@%%@AE@%
  16796.                                   %@AB@%S_IFCHR%@AE@% bit is set if%@AI@%%@AE@%
  16797.                                   %@AI@%handle%@AE@% refers to a device. The %@AB@%S_IFREG%@AE@% 
  16798.                                   bit is set if %@AI@%handle%@AE@% refers to an 
  16799.                                   ordinary file. The read/write bits are 
  16800.                                   set according to the file's permission 
  16801.                                   mode. (%@AB@%S_IFCHR%@AE@% and other constants are 
  16802.                                   defined in SYS\ STAT.H.)
  16803.  
  16804. %@AB@%st_mtime%@AE@%                          Time of last modification of file (same 
  16805.                                   as %@AB@%st_atime%@AE@% and %@AB@%st_ctime%@AE@%).
  16806.  
  16807. %@AB@%st_nlink%@AE@%                          Always 1.
  16808.  
  16809. %@AB@%st_rdev%@AE@%                           Either the drive number of the disk 
  16810.                                   containing the file, or %@AI@%handle%@AE@% in the 
  16811.                                   case of a device (same as %@AB@%st_dev%@AE@%).
  16812.  
  16813. %@AB@%st_size%@AE@%                           Size of the file in bytes.
  16814.  
  16815. If %@AI@%handle%@AE@% refers to a device, the size and time fields in the %@AB@%stat %@AE@%structure
  16816. are not meaningful.  %@NL@%
  16817. %@NL@%
  16818. %@NL@%
  16819. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16820. %@NL@%
  16821. The %@AB@%fstat%@AE@% function returns the value 0 if the file-status information is
  16822. obtained. A return value of -1 indicates an error; in this case, %@AB@%errno%@AE@% is
  16823. set to %@AB@%EBADF%@AE@%, indicating an invalid file handle.  %@NL@%
  16824. %@NL@%
  16825. %@NL@%
  16826. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16827. %@NL@%
  16828.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  16829. %@NL@%
  16830. %@NL@%
  16831. In OS/2, the %@AB@%st_dev%@AE@% field does not contain meaningful information. In fact,
  16832. it is set to zero. OS/2 provides no way to recover the host drive from just
  16833. the open file handle.  %@NL@%
  16834. %@NL@%
  16835. %@NL@%
  16836. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16837. %@NL@%
  16838. %@AB@%access, chmod, filelength%@AE@%, %@AB@%stat%@AE@%  %@NL@%
  16839. %@NL@%
  16840. %@NL@%
  16841. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16842. %@NL@%
  16843. %@AS@%  /* FSTAT.C: This program uses fstat to report the size of a file
  16844. %@AS@%   * named FSTAT.OUT.
  16845. %@AS@%   */
  16846. %@AS@%  
  16847. %@AS@%  #include <io.h>
  16848. %@AS@%  #include <fcntl.h>
  16849. %@AS@%  #include <time.h>
  16850. %@AS@%  #include <sys\types.h>
  16851. %@AS@%  #include <sys\stat.h>
  16852. %@AS@%  #include <stdio.h>
  16853. %@AS@%  #include <stdlib.h>
  16854. %@AS@%  #include <string.h>
  16855. %@AS@%  
  16856. %@AS@%  void main()
  16857. %@AS@%  {
  16858. %@AS@%     struct stat buf;
  16859. %@AS@%     int fh, result;
  16860. %@AS@%     char buffer[] = "A line to output";
  16861. %@AS@%  
  16862. %@AS@%     if( (fh = open( "fstat.out", O_CREAT | O_WRONLY | O_TRUNC )) == -1 )
  16863. %@AS@%        exit( 1 );
  16864. %@AS@%     write( fh, buffer, strlen( buffer ) );
  16865. %@AS@%  
  16866. %@AS@%     /* Get data associated with "fh": */
  16867. %@AS@%  
  16868. %@AS@%     result = fstat( fh, &buf );%@AE@%%@NL@%
  16869. %@NL@%
  16870. %@AS@%  /* Check if statistics are valid: */
  16871. %@AS@%     if( result != 0 )
  16872. %@AS@%        printf( "Bad file handle\n" );
  16873. %@AS@%     else
  16874. %@AS@%     {
  16875. %@AS@%        printf( "File size     : %ld\n", buf.st_size );
  16876. %@AS@%        printf( "Drive number  : %d\n", buf.st_dev );
  16877. %@AS@%        printf( "Time modified : %s", ctime( &buf.st_atime ) );
  16878. %@AS@%     }
  16879. %@AS@%     close( fh );
  16880. %@AS@%  }%@AE@%%@NL@%
  16881. %@NL@%
  16882. %@NL@%
  16883. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16884. %@NL@%
  16885. %@AS@%  
  16886. %@AS@%  
  16887. %@AS@%  File size     : 16
  16888. %@AS@%  Drive number  : 0
  16889. %@AS@%  Time modified : Thu Jun 15 21:38:46 1989 %@AE@%%@NL@%
  16890. %@NL@%
  16891. %@NL@%
  16892. %@NL@%
  16893. %@NL@%
  16894. %@QR:ftell@%%@NL@%
  16895. %@2@%%@CR:C6A01240659 @%%@AB@%ftell%@AE@%%@EH@%%@NL@%
  16896. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16897. %@NL@%
  16898. %@NL@%
  16899. %@3@%%@AB@%Description%@CR:C6A01240660 @%%@CR:C6A01240661 @% %@CR:C6A01240662 @%%@CR:C6A01240663 @% %@CR:C6A01240664 @%%@AE@%%@EH@%%@NL@%
  16900. %@NL@%
  16901. Gets the current position of a file pointer.  %@NL@%
  16902. %@NL@%
  16903. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  16904. %@NL@%
  16905. %@AS@%  long ftell( FILE *stream );%@AE@%%@NL@%
  16906. %@NL@%
  16907. %@AI@%stream%@AE@%                            Target %@AB@%FILE structure%@AE@%
  16908.  
  16909. %@NL@%
  16910. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  16911. %@NL@%
  16912. The %@AB@%ftell%@AE@% function gets the current position of the file pointer (if any)
  16913. associated with %@AI@%stream%@AE@%. The position is expressed as an offset relative to
  16914. the beginning of the stream.  %@NL@%
  16915. %@NL@%
  16916. Note that when a file is opened for appending data, the current file
  16917. position is determined by the last I/O operation, not by where the next
  16918. write would occur. For example, if a file is opened for an append and the
  16919. last operation was a read, the file position is the point where the next
  16920. read operation would start, not where the next write would start. (When a
  16921. file is opened for appending, the file position is moved to end-of-file
  16922. before any write operation.) If no I/O operation has yet occurred on a file
  16923. opened for appending, the file position is the beginning of the file.  %@NL@%
  16924. %@NL@%
  16925. %@NL@%
  16926. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  16927. %@NL@%
  16928. The %@AB@%ftell%@AE@% function returns the current file position. The value returned by
  16929. %@AB@%ftell%@AE@% may not reflect the physical byte offset for streams opened in text
  16930. mode, since text mode causes carriage-return-line-feed translation. Use
  16931. %@AB@%ftell%@AE@% in conjunction with the %@AB@%fseek%@AE@% function to return to file locations
  16932. correctly. On error, the function returns -1L and %@AB@%errno%@AE@% is set to one of the
  16933. following constants, defined in ERRNO.H:  %@NL@%
  16934. %@NL@%
  16935. %@AB@%Constant%@AE@%                          %@AB@%Description%@AE@%
  16936. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  16937. %@AB@%EBADF%@AE@%                             Bad file number. The %@AI@%stream%@AE@% argument is 
  16938.                                   not a valid file-handle value or does 
  16939.                                   not refer to an open file.
  16940.  
  16941. %@AB@%EINVAL%@AE@%                            Invalid argument. An invalid %@AI@%stream%@AE@% 
  16942.                                   argument was passed to the function.
  16943.  
  16944. On devices incapable of seeking (such as terminals and printers), or when
  16945. %@AI@%stream%@AE@% does not refer to an open file, the return value is undefined.  %@NL@%
  16946. %@NL@%
  16947. %@NL@%
  16948. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  16949. %@NL@%
  16950. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  16951. %@NL@%
  16952. %@NL@%
  16953. %@NL@%
  16954. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  16955. %@NL@%
  16956. %@AB@%fgetpos%@AE@%, %@AB@%fseek%@AE@%, %@AB@%lseek%@AE@%, %@AB@%tell%@AE@%  %@NL@%
  16957. %@NL@%
  16958. %@NL@%
  16959. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  16960. %@NL@%
  16961. %@AS@%  /* FTELL.C: This program opens a file named FTELL.C for reading and
  16962. %@AS@%   * tries to read 100 characters. It then uses ftell to determine the
  16963. %@AS@%   * position of the file pointer and displays this position.
  16964. %@AS@%   */
  16965. %@AS@%  
  16966. %@AS@%  #include <stdio.h>
  16967. %@AS@%  
  16968. %@AS@%  FILE *stream;
  16969. %@AS@%  
  16970. %@AS@%  void main()
  16971. %@AS@%  {
  16972. %@AS@%     long position;
  16973. %@AS@%     char list[100];
  16974. %@AS@%  
  16975. %@AS@%     if( (stream = fopen( "ftell.c", "rb" )) != NULL )
  16976. %@AS@%     {
  16977. %@AS@%        /* Move the pointer by reading data: */
  16978. %@AS@%        fread( list, sizeof( char ), 100, stream );
  16979. %@AS@%  
  16980. %@AS@%        /* Get position after read: */
  16981. %@AS@%        position = ftell( stream );
  16982. %@AS@%        printf( "Position after trying to read 100 bytes: %ld\n", position
  16983. %@AS@%);
  16984. %@AS@%        fclose( stream );
  16985. %@AS@%     }
  16986. %@AS@%  }%@AE@%%@NL@%
  16987. %@NL@%
  16988. %@NL@%
  16989. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  16990. %@NL@%
  16991. %@AS@%  
  16992. %@AS@%  
  16993. %@AS@%  Position after trying to read 100 bytes: 100 %@AE@%%@NL@%
  16994. %@NL@%
  16995. %@NL@%
  16996. %@NL@%
  16997. %@NL@%
  16998. %@QR:ftime@%%@NL@%
  16999. %@2@%%@CR:C6A01250665 @%%@AB@%ftime%@AE@%%@EH@%%@NL@%
  17000. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17001. %@NL@%
  17002. %@NL@%
  17003. %@3@%%@AB@%Description%@CR:C6A01250666 @%%@CR:C6A01250667 @%%@CR:C6A01250668 @%%@AE@%%@EH@%%@NL@%
  17004. %@NL@%
  17005. Gets the current time.  %@NL@%
  17006. %@NL@%
  17007. %@AS@%  #include <sys\types.h>%@AE@%%@NL@%
  17008. %@NL@%
  17009. %@AS@%  #include <sys\timeb.h>%@AE@%%@NL@%
  17010. %@NL@%
  17011. %@AS@%  void ftime( struct timeb *timeptr );%@AE@%%@NL@%
  17012. %@NL@%
  17013. %@AI@%timeptr%@AE@%                           Pointer to structure defined in 
  17014.                                   SYS\TIMEB.H
  17015.  
  17016. %@NL@%
  17017. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17018. %@NL@%
  17019. The %@AB@%ftime%@AE@% function gets the current time and stores it in the structure
  17020. pointed to by %@AI@%timeptr%@AE@%. The %@AB@%timeb%@AE@% structure is defined in SYS\TIMEB.H. It
  17021. contains four fields (%@AB@%dstflag%@AE@%, %@AB@%millitm%@AE@%, %@AB@%time%@AE@%, and %@AB@%timezone%@AE@%), which have the
  17022. following values: %@CR:C6A01250669 @%%@CR:C6A01250670 @%  %@NL@%
  17023. %@NL@%
  17024. %@AB@%Field%@AE@%                             %@AB@%Value%@AE@%
  17025. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17026. %@AB@%dstflag%@AE@%                           Nonzero if daylight saving time is 
  17027.                                   currently in effect for the local time 
  17028.                                   zone. (See %@AB@%tzset%@AE@% for an explanation of 
  17029.                                   how daylight saving time is determined.)
  17030.  
  17031. %@AB@%millitm%@AE@%                           Fraction of a second in milliseconds. 
  17032.                                   The last digit is always 0 since %@AB@%millitm%@AE@%
  17033.                                   is incremented to the nearest 
  17034.                                   one-hundredth of a second.
  17035.  
  17036. %@AB@%time%@AE@%                              Time in seconds since 00:00:00 Greenwich
  17037.                                   mean time, January 1, 1970.
  17038.  
  17039. %@AB@%timezone%@AE@%                          Difference in minutes, moving westward, 
  17040.                                   between Greenwich mean time and local 
  17041.                                   time. The value of %@AB@%timezone%@AE@% is set from 
  17042.                                   the value of the global variable %@AB@%%@AE@%
  17043.                                   %@AB@%timezone%@AE@% (see %@AB@%tzset%@AE@%).
  17044.  
  17045. %@NL@%
  17046. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17047. %@NL@%
  17048. The %@AB@%ftime%@AE@% function gives values to the fields in the structure pointed to by
  17049. %@AI@%timeptr%@AE@%. It does not return a value.  %@NL@%
  17050. %@NL@%
  17051. %@NL@%
  17052. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17053. %@NL@%
  17054.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  17055. %@NL@%
  17056. %@NL@%
  17057. %@NL@%
  17058. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17059. %@NL@%
  17060. %@AB@%asctime%@AE@%, %@AB@%ctime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%time%@AE@%, %@AB@%tzset%@AE@%  %@NL@%
  17061. %@NL@%
  17062. %@NL@%
  17063. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17064. %@NL@%
  17065. %@AS@%  /* FTIME.C: This program uses ftime to obtain the current time
  17066. %@AS@%   * and then stores this time in timebuffer.
  17067. %@AS@%   */
  17068. %@AS@%  
  17069. %@AS@%  #include <stdio.h>
  17070. %@AS@%  #include <sys\timeb.h>
  17071. %@AS@%  #include <time.h>
  17072. %@AS@%  
  17073. %@AS@%  void main()
  17074. %@AS@%  {
  17075. %@AS@%  
  17076. %@AS@%     struct timeb timebuffer;
  17077. %@AS@%     char *timeline;
  17078. %@AS@%  
  17079. %@AS@%     ftime( &timebuffer );
  17080. %@AS@%     timeline = ctime( & ( timebuffer.time ) );
  17081. %@AS@%  
  17082. %@AS@%     printf( "The time is %.19s.%hu %s",
  17083. %@AS@%             timeline, timebuffer.millitm, &timeline[20] );
  17084. %@AS@%  }%@AE@%%@NL@%
  17085. %@NL@%
  17086. %@NL@%
  17087. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  17088. %@NL@%
  17089. %@AS@%  
  17090. %@AS@%  
  17091. %@AS@%  The time is Thu Jun 15 21:40:34.870 1989 %@AE@%%@NL@%
  17092. %@NL@%
  17093. %@NL@%
  17094. %@NL@%
  17095. %@NL@%
  17096. %@QR:_fullpath@%%@NL@%
  17097. %@2@%%@CR:C6A01260671 @%%@AB@%_fullpath%@AE@%%@EH@%%@NL@%
  17098. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17099. %@NL@%
  17100. %@NL@%
  17101. %@3@%%@AB@%Description%@CR:C6A01260672 @%%@AE@%%@EH@%%@NL@%
  17102. %@NL@%
  17103. Makes an absolute path name from a relative path name.  %@NL@%
  17104. %@NL@%
  17105. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  17106. %@NL@%
  17107. %@AS@%  char *_fullpath( char *buffer, const char *pathname, size_t maxlen );%@AE@%%@NL@%
  17108. %@NL@%
  17109. %@AI@%buffer%@AE@%                            Full path-name buffer
  17110.  
  17111. %@AI@%pathname%@AE@%                          Relative path name
  17112.  
  17113. %@AI@%maxlen%@AE@%                            Length of the buffer pointed to by %@AI@%%@AE@%
  17114.                                   %@AI@%buffer%@AE@%
  17115.  
  17116. %@NL@%
  17117. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17118. %@NL@%
  17119. The %@AB@%_fullpath%@AE@% routine converts the partial path stored in %@AI@%pathname%@AE@% to a
  17120. fully qualified path that is stored in %@AI@%buffer%@AE@%. Unlike %@AB@%_makepath%@AE@%, the
  17121. %@AB@%_fullpath%@AE@% routine can be used with %@AB@%.\%@AE@% and %@AB@%..\%@AE@% in the path.  %@NL@%
  17122. %@NL@%
  17123. If the length of the fully qualified path is greater than the value of
  17124. %@AI@%maxlen%@AE@%, then %@AB@%NULL%@AE@% is returned; otherwise, the address of %@AI@%buffer%@AE@% is returned.
  17125. %@NL@%
  17126. %@NL@%
  17127. If the %@AI@%buffer%@AE@% is %@AB@%NULL%@AE@%, %@AB@%_fullpath%@AE@% will allocate a buffer of %@AB@%MAX_PATH%@AE@% size and
  17128. the %@AI@%maxlen%@AE@% argument is ignored.  %@NL@%
  17129. %@NL@%
  17130. If the %@AI@%pathname%@AE@% argument specifies a disk drive, the current directory of
  17131. this drive is combined with the path. If the drive is not valid, %@AB@%_fullpath%@AE@%
  17132. returns %@AB@%NULL%@AE@%.  %@NL@%
  17133. %@NL@%
  17134. %@NL@%
  17135. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17136. %@NL@%
  17137. The %@AB@%_fullpath%@AE@% function returns a pointer to the buffer containing the
  17138. absolute path (%@AI@%buffer%@AE@%). If there is an error, %@AB@%_fullpath%@AE@% returns %@AB@%NULL%@AE@%.  %@NL@%
  17139. %@NL@%
  17140. %@NL@%
  17141. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17142. %@NL@%
  17143.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  17144. %@NL@%
  17145. %@NL@%
  17146. %@NL@%
  17147. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17148. %@NL@%
  17149. %@AB@%getcwd%@AE@%, %@AB@% _getdcwd%@AE@%, %@AB@% _makepath%@AE@%,  %@AB@%_splitpath%@AE@%  %@NL@%
  17150. %@NL@%
  17151. %@NL@%
  17152. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17153. %@NL@%
  17154. %@AS@%  /* FULLPATH.C: This program demonstrates how _fullpath creates a full
  17155. %@AS@%   * path from a partial path.
  17156. %@AS@%   */
  17157. %@AS@%  
  17158. %@AS@%  #include <stdio.h>
  17159. %@AS@%  #include <conio.h>
  17160. %@AS@%  #include <stdlib.h>
  17161. %@AS@%  #include <direct.h>%@AE@%%@NL@%
  17162. %@NL@%
  17163. %@AS@%  char full[_MAX_PATH], part[_MAX_PATH];
  17164. %@AS@%  
  17165. %@AS@%  void main()
  17166. %@AS@%  {
  17167. %@AS@%      while( 1 )
  17168. %@AS@%      {
  17169. %@AS@%          printf( "Enter partial path or ENTER to quit: " );
  17170. %@AS@%          gets( part );
  17171. %@AS@%          if( part[0] == 0 )
  17172. %@AS@%              break;
  17173. %@AS@%  
  17174. %@AS@%          if( _fullpath( full, part, _MAX_PATH ) != NULL )
  17175. %@AS@%              printf( "Full path is: %s\n", full );
  17176. %@AS@%          else
  17177. %@AS@%              printf( "Invalid path\n" );
  17178. %@AS@%      }
  17179. %@AS@%  }%@AE@%%@NL@%
  17180. %@NL@%
  17181. %@NL@%
  17182. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  17183. %@NL@%
  17184. %@AS@%  
  17185. %@AS@%  
  17186. %@AS@%  Enter partial path or ENTER to quit: ..
  17187. %@AS@%  Full path is: C:\
  17188. %@AS@%  Enter partial path or ENTER to quit: ..\include
  17189. %@AS@%  Full path is: C:\include
  17190. %@AS@%  Enter partial path or ENTER to quit: p:
  17191. %@AS@%  Full path is: P:\
  17192. %@AS@%  Enter partial path or ENTER to quit: fullpath.c
  17193. %@AS@%  Full path is: C:\LIBREF\fullpath.c
  17194. %@AS@%  Enter partial path or ENTER to quit: %@AE@%%@NL@%
  17195. %@NL@%
  17196. %@NL@%
  17197. %@NL@%
  17198. %@NL@%
  17199. %@QR:fwrite@%%@NL@%
  17200. %@2@%%@CR:C6A01270673 @%%@AB@%fwrite%@AE@%%@EH@%%@NL@%
  17201. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17202. %@NL@%
  17203. %@NL@%
  17204. %@3@%%@AB@%Description%@CR:C6A01270674 @%%@CR:C6A01270675 @% %@CR:C6A01270676 @%%@CR:C6A01270677 @% %@CR:C6A01270678 @%%@AE@%%@EH@%%@NL@%
  17205. %@NL@%
  17206. Writes data to a stream.  %@NL@%
  17207. %@NL@%
  17208. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  17209. %@NL@%
  17210. %@AS@%  size_t fwrite( const void *buffer, size_t size, size_t count, FILE *stream
  17211. %@AS@%  );%@AE@%%@NL@%
  17212. %@NL@%
  17213. %@AI@%buffer%@AE@%                            Pointer to data to be written
  17214.  
  17215. %@AI@%size%@AE@%                              Item size in bytes
  17216.  
  17217. %@AI@%count%@AE@%                             Maximum number of items to be written
  17218.  
  17219. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  17220.  
  17221. %@NL@%
  17222. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17223. %@NL@%
  17224. The %@AB@%fwrite%@AE@% function writes up to %@AI@%count%@AE@% items, of length %@AI@%size%@AE@% each, from
  17225. %@AI@%buffer%@AE@% to the output %@AI@%stream%@AE@%. The file pointer associated with %@AI@%stream%@AE@% (if
  17226. there is one) is incremented by the number of bytes actually written.  %@NL@%
  17227. %@NL@%
  17228. If %@AI@%stream%@AE@% is opened in text mode, each carriage return is replaced with a
  17229. carriage-return-line-feed pair. The replacement has no effect on the return
  17230. value.  %@NL@%
  17231. %@NL@%
  17232. %@NL@%
  17233. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17234. %@NL@%
  17235. The %@AB@%fwrite%@AE@% function returns the number of full items actually written, which
  17236. may be less than %@AI@%count%@AE@% if an error occurs. Also, if an error occurs, the
  17237. file-position indicator cannot be determined.  %@NL@%
  17238. %@NL@%
  17239. %@NL@%
  17240. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17241. %@NL@%
  17242. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  17243. %@NL@%
  17244. %@NL@%
  17245. %@NL@%
  17246. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17247. %@NL@%
  17248. %@AB@%fread%@AE@%, %@AB@%write%@AE@%  %@NL@%
  17249. %@NL@%
  17250. %@NL@%
  17251. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17252. %@NL@%
  17253. %@AS@%  /* FREAD.C: This program opens a file named FREAD.OUT and writes 25
  17254. %@AS@%   * characters to the file. It then tries to open FREAD.OUT and
  17255. %@AS@%   * read in 25 characters. If the attempt succeeds, the program
  17256. %@AS@%   * displays the number of actual items read.
  17257. %@AS@%   */
  17258. %@AS@%  
  17259. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  17260. %@NL@%
  17261. %@AS@%  %@AE@%%@NL@%
  17262. %@NL@%
  17263. %@AS@%  void main()
  17264. %@AS@%  {
  17265. %@AS@%     FILE *stream;
  17266. %@AS@%     char list[30];
  17267. %@AS@%     int  i, numread, numwritten;
  17268. %@AS@%  
  17269. %@AS@%     /* Open file in text mode: */
  17270. %@AS@%     if( (stream = fopen( "fread.out", "w+t" )) != NULL )
  17271. %@AS@%     {
  17272. %@AS@%        for ( i = 0; i < 25; i++ )
  17273. %@AS@%           list[i] = 'z' - i;
  17274. %@AS@%        /* Write 25 characters to stream */
  17275. %@AS@%        numwritten = fwrite( list, sizeof( char ), 25, stream );
  17276. %@AS@%        printf( "Wrote %d items\n", numwritten );
  17277. %@AS@%        fclose( stream );
  17278. %@AS@%     }
  17279. %@AS@%     else
  17280. %@AS@%        printf( "Problem opening the file\n" );
  17281. %@AS@%  
  17282. %@AS@%     if( (stream = fopen( "fread.out", "r+t" )) != NULL )
  17283. %@AS@%     {
  17284. %@AS@%        /* Attempt to read in 25 characters */
  17285. %@AS@%        numread = fread( list, sizeof( char ), 25, stream );
  17286. %@AS@%        printf( "Number of items read = %d\n", numread );
  17287. %@AS@%        printf( "Contents of buffer = %.25s\n", list );
  17288. %@AS@%        fclose( stream );
  17289. %@AS@%     }
  17290. %@AS@%     else
  17291. %@AS@%        printf( "Was not able to open the file\n" );
  17292. %@AS@%  }%@AE@%%@NL@%
  17293. %@NL@%
  17294. %@NL@%
  17295. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  17296. %@NL@%
  17297. %@AS@%  
  17298. %@AS@%  
  17299. %@AS@%  Wrote 25 items
  17300. %@AS@%  Number of items read = 25
  17301. %@AS@%  Contents of buffer = zyxwvutsrqponmlkjihgfedcb %@AE@%%@NL@%
  17302. %@NL@%
  17303. %@NL@%
  17304. %@NL@%
  17305. %@NL@%
  17306. %@QR:gcvt@%%@NL@%
  17307. %@2@%%@CR:C6A01280679 @%%@AB@%gcvt%@AE@%%@EH@%%@NL@%
  17308. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17309. %@NL@%
  17310. %@NL@%
  17311. %@3@%%@AB@%Description%@CR:C6A01280680 @%%@CR:C6A01280681 @% %@CR:C6A01280682 @% %@CR:C6A01280683 @%%@AE@%%@EH@%%@NL@%
  17312. %@NL@%
  17313. Converts a floating-point value to a string, which it stores in a buffer.  %@NL@%
  17314. %@NL@%
  17315. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  17316.  
  17317. %@AS@%  char *gcvt( double value, int digits, char *buffer );%@AE@%%@NL@%
  17318. %@NL@%
  17319. %@AI@%value%@AE@%                             Value to be converted
  17320.  
  17321. %@AI@%digits%@AE@%                            Number of significant digits stored
  17322.  
  17323. %@AI@%buffer%@AE@%                            Storage location for result
  17324.  
  17325. %@NL@%
  17326. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17327. %@NL@%
  17328. The %@AB@%gcvt%@AE@% function converts a floating-point %@AI@%value%@AE@% to a character string and
  17329. stores the string in %@AI@%buffer%@AE@%. The %@AI@%buffer%@AE@% should be large enough to
  17330. accommodate the converted value plus a terminating null character (%@AB@%'\0'%@AE@%),
  17331. which is appended automatically. There is no provision for overflow.  %@NL@%
  17332. %@NL@%
  17333. The %@AB@%gcvt%@AE@% function attempts to produce %@AI@%digits%@AE@% significant digits in decimal
  17334. format. If this is not possible, it produces %@AI@%digits%@AE@% significant digits in
  17335. exponential format. Trailing zeros may be suppressed in the conversion.  %@NL@%
  17336. %@NL@%
  17337. %@NL@%
  17338. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17339. %@NL@%
  17340. The %@AB@%gcvt%@AE@% function returns a pointer to the string of digits. There is no
  17341. error return.  %@NL@%
  17342. %@NL@%
  17343. %@NL@%
  17344. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17345. %@NL@%
  17346.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  17347. %@NL@%
  17348. %@NL@%
  17349. %@NL@%
  17350. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17351. %@NL@%
  17352. %@AB@%atof%@AE@%, %@AB@%atoi%@AE@%, %@AB@%atol%@AE@%, %@AB@%ecvt%@AE@%, %@AB@%fcvt%@AE@%  %@NL@%
  17353. %@NL@%
  17354. %@NL@%
  17355. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17356. %@NL@%
  17357. %@AS@%  /* GCVT.C: This program converts -3.1415e5 to its string representation.
  17358. %@AS@%  */
  17359. %@AS@%  
  17360. %@AS@%  #include <stdlib.h>
  17361. %@AS@%  #include <stdio.h>
  17362. %@AS@%  %@AE@%%@NL@%
  17363. %@NL@%
  17364. %@AS@%  void main()
  17365. %@AS@%  {
  17366. %@AS@%     char buffer[50];
  17367. %@AS@%     double source = -3.1415e5;
  17368. %@AS@%  
  17369. %@AS@%     gcvt( source, 7, buffer );
  17370. %@AS@%     printf( "source: %f  buffer: '%s'\n", source, buffer );
  17371. %@AS@%  }%@AE@%%@NL@%
  17372. %@NL@%
  17373. %@NL@%
  17374. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  17375. %@NL@%
  17376. %@AS@%  
  17377. %@AS@%  
  17378. %@AS@%  source: -314150.000000  buffer: '-314150.' %@AE@%%@NL@%
  17379. %@NL@%
  17380. %@NL@%
  17381. %@NL@%
  17382. %@NL@%
  17383. %@QR:_getactivepage@%%@NL@%
  17384. %@2@%%@CR:C6A01290684 @%%@AB@%_getactivepage%@AE@%%@EH@%%@NL@%
  17385. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17386. %@NL@%
  17387. %@NL@%
  17388. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  17389. %@NL@%
  17390. Gets the current active page number.  %@NL@%
  17391. %@NL@%
  17392. %@CR:C6A01290685 @%%@AS@%  #include <graph.h>%@AE@%%@NL@%
  17393. %@NL@%
  17394. %@AS@%  short _far _getactivepage( void );%@AE@%%@NL@%
  17395. %@NL@%
  17396. %@NL@%
  17397. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17398. %@NL@%
  17399. The %@AB@%_getactivepage%@AE@% function returns the number of the current active page.  %@NL@%
  17400. %@NL@%
  17401. %@NL@%
  17402. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17403. %@NL@%
  17404. The function returns the number of the current active page. All hardware
  17405. combinations support at least one page (page number 0). In OS/2, only page 0
  17406. is valid.  %@NL@%
  17407. %@NL@%
  17408. %@NL@%
  17409. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17410. %@NL@%
  17411.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  17412. %@NL@%
  17413. %@NL@%
  17414. %@NL@%
  17415. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17416. %@NL@%
  17417. %@AB@%_getactivepage%@AE@%,  %@AB@%_getvideoconfig%@AE@%,  %@AB@%_getvisualpage%@AE@%,  %@AB@%_grstatus%@AE@%,
  17418. %@AB@%_setactivepage%@AE@%, %@AB@%_setvideomode%@AE@%,  %@AB@%_setvisualpage%@AE@%  %@NL@%
  17419. %@NL@%
  17420. %@NL@%
  17421. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17422. %@NL@%
  17423. %@AS@%  /* PAGE.C illustrates video page functions including:
  17424. %@AS@%   *      _getactivepage  _getvisualpage  _setactivepage  _setvisualpage
  17425. %@AS@%   */
  17426. %@AS@%  
  17427. %@AS@%  #include <conio.h>
  17428. %@AS@%  #include <graph.h>
  17429. %@AS@%  #include <stdlib.h>
  17430. %@AS@%  
  17431. %@AS@%  void main()
  17432. %@AS@%  {
  17433. %@AS@%     short  oldvpage, oldapage, page, row, col, line;
  17434. %@AS@%     struct videoconfig vc;
  17435. %@AS@%     char   buf[80];
  17436. %@AS@%  
  17437. %@AS@%     _getvideoconfig( &vc );
  17438. %@AS@%     if( vc.numvideopages < 4 )
  17439. %@AS@%         exit( 1 );              /* Fail for OS/2 or monochrome. */
  17440. %@AS@%     oldapage  = _getactivepage();
  17441. %@AS@%     oldvpage  = _getvisualpage();
  17442. %@AS@%     _displaycursor( _GCURSOROFF );
  17443. %@AS@%  %@AE@%%@NL@%
  17444. %@NL@%
  17445. %@AS@%  /* Draw arrows in different place on each page. */
  17446. %@AS@%     for( page = 1; page < 4; page++ )
  17447. %@AS@%     {
  17448. %@AS@%        _setactivepage( page );
  17449. %@AS@%        _settextposition( 12, 16 * page );
  17450. %@AS@%        _outtext( ">>>>>>>>" );
  17451. %@AS@%     }
  17452. %@AS@%  
  17453. %@AS@%     while( !kbhit() )
  17454. %@AS@%        /* Cycle through pages 1 to 3 to show moving image. */
  17455. %@AS@%        for( page = 1; page < 4; page++ )
  17456. %@AS@%            _setvisualpage( page );
  17457. %@AS@%     getch();
  17458. %@AS@%  
  17459. %@AS@%     /* Restore original page (normally 0) to restore screen. */
  17460. %@AS@%     _setactivepage( oldapage );
  17461. %@AS@%     _setvisualpage( oldvpage );
  17462. %@AS@%     _displaycursor( _GCURSORON );
  17463. %@AS@%  }%@AE@%%@NL@%
  17464. %@NL@%
  17465. %@NL@%
  17466. %@NL@%
  17467. %@NL@%
  17468. %@QR:_getarcinfo@%%@NL@%
  17469. %@2@%%@CR:C6A01300686 @%%@AB@%_getarcinfo%@AE@%%@EH@%%@NL@%
  17470. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17471. %@NL@%
  17472. %@NL@%
  17473. %@3@%%@AB@%Description%@CR:C6A01300687 @% %@CR:C6A01300688 @%%@AE@%%@EH@%%@NL@%
  17474. %@NL@%
  17475. Determines the endpoints in viewport coordinates of the most recently drawn
  17476. arc or pie.  %@NL@%
  17477. %@NL@%
  17478. %@AS@%  #include  <graph.h>%@AE@%%@NL@%
  17479. %@NL@%
  17480. %@AS@%  short _far _getarcinfo( struct xycoord _far *start, struct xycoord _far
  17481. %@AS@%  *end, 
  17482. %@AS@%  struct xycoord _far *fillpoint );%@AE@%%@NL@%
  17483. %@NL@%
  17484. %@AI@%start%@AE@%                             Starting point of arc
  17485.  
  17486. %@AI@%end%@AE@%                               Ending point of arc
  17487.  
  17488. %@AI@%fillpoint%@AE@%                         Point at which pie fill will begin
  17489.  
  17490. %@NL@%
  17491. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17492. %@NL@%
  17493. The %@AB@%_getarcinfo%@AE@% function determines the endpoints in viewport coordinates of
  17494. the most recently drawn arc or pie.  %@NL@%
  17495. %@NL@%
  17496. If successful, the %@AB@%_getarcinfo%@AE@% function updates the %@AI@%start%@AE@% and %@AI@%end%@AE@% %@AB@%xycoord%@AE@%
  17497. structures to contain the endpoints (in viewport coordinates) of the arc
  17498. drawn by the most recent call to one of the %@AB@%_arc%@AE@% or %@AB@%_pie%@AE@% functions.  %@NL@%
  17499. %@NL@%
  17500. In addition, %@AI@%fillpoint%@AE@% specifies a point from which a pie can be filled.
  17501. This is useful for filling a pie in a color different from the border color.
  17502. After a call to %@AB@%_getarcinfo%@AE@%, change colors using the %@AB@%_setcolor %@AE@%function. Use
  17503. the color, along with the coordinates in %@AI@%fillpoint%@AE@%, as arguments for the
  17504. %@AI@%floodfill%@AE@% function.  %@NL@%
  17505. %@NL@%
  17506. %@NL@%
  17507. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17508. %@NL@%
  17509. The %@AB@%_getarcinfo%@AE@% function returns a nonzero value if successful. If neither
  17510. the %@AB@%_arc%@AE@% nor the %@AB@%_pie%@AE@% function has been successfully called since the last
  17511. time the screen was cleared or a new graphics mode or viewport was selected,
  17512. the %@AB@%_getarcinfo%@AE@% function returns 0.  %@NL@%
  17513. %@NL@%
  17514. %@NL@%
  17515. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17516. %@NL@%
  17517.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  17518. %@NL@%
  17519. %@NL@%
  17520. %@NL@%
  17521. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17522. %@NL@%
  17523. %@AB@%_arc%@AE@% functions,  %@AB@%_floodfill%@AE@%,  %@AB@%_getvideoconfig%@AE@%,  %@AB@%_grstatus%@AE@%,  %@AB@%_pie%@AE@% functions  %@NL@%
  17524. %@NL@%
  17525. %@NL@%
  17526. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17527. %@NL@%
  17528. See the example for %@AB@%_arc%@AE@%.  %@NL@%
  17529. %@NL@%
  17530. %@NL@%
  17531. %@NL@%
  17532. %@NL@%
  17533. %@QR:_getbkcolor@%%@NL@%
  17534. %@2@%%@CR:C6A01310689 @%%@AB@%_getbkcolor%@AE@%%@EH@%%@NL@%
  17535. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17536. %@NL@%
  17537. %@NL@%
  17538. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  17539. %@NL@%
  17540. Gets the current background color.  %@NL@%
  17541. %@NL@%
  17542. %@CR:C6A01310690 @%%@AS@%  #include <graph.h>%@AE@%%@NL@%
  17543. %@NL@%
  17544. %@AS@%  long _far _getbkcolor( void );%@AE@%%@NL@%
  17545. %@NL@%
  17546. %@NL@%
  17547. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17548. %@NL@%
  17549. The %@AB@%_getbkcolor%@AE@% function returns the current background color. The default
  17550. is 0.  %@NL@%
  17551. %@NL@%
  17552. In a color text mode such as %@AB@%_TEXTC80%@AE@%, %@AB@%_setbkcolor%@AE@% accepts, and %@AB@%_getbkcolor%@AE@%
  17553. returns, a color index. For example, %@AB@%_setbkcolor(2L)%@AE@% sets the background
  17554. color to color index 2. The actual color displayed depends on the palette
  17555. mapping for color index 2. The default for color index 2 is green in a color
  17556. text mode.  %@NL@%
  17557. %@NL@%
  17558. In a color graphics mode such as %@AB@%_ERESCOLOR%@AE@%, %@AB@%_setbkcolor%@AE@% accepts and
  17559. %@AB@%_getbkcolor%@AE@% returns a color value (as used in %@AB@%_remappalette%@AE@%). The value for
  17560. the simplest background colors is given by the manifest constants defined in
  17561. the GRAPH.H include file. For example, %@AB@%_setbkcolor( _GREEN)%@AE@% sets the
  17562. background color in a graphics mode to green. These manifest constants are
  17563. provided as a convenience in defining and manipulating the most common
  17564. colors. In general, the actual range of colors is much greater.  %@NL@%
  17565. %@NL@%
  17566. In most cases, whenever an argument is long, it refers to a color value, and
  17567. whenever it is short, it refers to a color index. The two exceptions are
  17568. %@AB@%_setbkcolor%@AE@% and %@AB@%_getbkcolor%@AE@%, described above. For a more complete discussion
  17569. of colors, see %@AB@%_remappalette%@AE@%.  %@NL@%
  17570. %@NL@%
  17571. %@NL@%
  17572. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17573. %@NL@%
  17574. The function returns the current background color value. There is no error
  17575. return.  %@NL@%
  17576. %@NL@%
  17577. %@NL@%
  17578. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17579. %@NL@%
  17580.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  17581. %@NL@%
  17582. %@NL@%
  17583. %@NL@%
  17584. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17585. %@NL@%
  17586. %@AB@%_remappalette%@AE@%,  %@AB@%_setbkcolor%@AE@%  %@NL@%
  17587. %@NL@%
  17588. %@NL@%
  17589. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17590. %@NL@%
  17591. See the example for %@AB@%_getcolor%@AE@%.  %@NL@%
  17592. %@NL@%
  17593. %@NL@%
  17594. %@NL@%
  17595. %@NL@%
  17596. %@QR:getc@%%@QR:getchar@%%@NL@%
  17597. %@2@%%@CR:C6A01320691 @%%@AB@%getc, getchar%@AE@%%@EH@%%@NL@%
  17598. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17599. %@NL@%
  17600. %@NL@%
  17601. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  17602. %@NL@%
  17603. Reads a character from a stream (%@AB@%getc%@AE@%), or gets a character from %@AB@%stdin%@AE@%
  17604. (%@AB@%getchar%@AE@%).%@CR:C6A01320692 @%%@CR:C6A01320693 @%%@CR:C6A01320694 @%%@CR:C6A01320695 @%%@CR:C6A01320696 @%%@CR:C6A01320697 @%  %@NL@%
  17605. %@NL@%
  17606. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  17607. %@NL@%
  17608. %@AS@%  int getc( FILE *stream );%@AE@%%@NL@%
  17609. %@NL@%
  17610. %@AS@%  int getchar( void );%@AE@%%@NL@%
  17611. %@NL@%
  17612. %@AI@%stream %@AE@%                           Current stream
  17613.  
  17614. %@NL@%
  17615. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17616. %@NL@%
  17617. The %@AB@%getc%@AE@% macro reads a single character from the %@AI@%stream%@AE@% position and
  17618. increments the associated file pointer (if there is one) to point to the
  17619. next character. The %@AB@%getchar%@AE@% macro is identical to %@AB@%getc%@AE@%(%@AB@%stdin%@AE@%).  %@NL@%
  17620. %@NL@%
  17621. The %@AB@%getc%@AE@% and %@AB@%getchar%@AE@% routines are similar to %@AB@%fgetc%@AE@% and %@AB@%fgetchar%@AE@%,
  17622. respectively, but are macros rather than functions.  %@NL@%
  17623. %@NL@%
  17624. %@NL@%
  17625. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17626. %@NL@%
  17627. The %@AB@%getc%@AE@% and %@AB@%getchar%@AE@% macros return the character read. A return value of %@AB@%EOF%@AE@%
  17628. indicates an error or end-of-file condition. Use %@AB@%ferror%@AE@% or %@AB@%feof%@AE@% to determine
  17629. whether an error or end-of-file occurred.  %@NL@%
  17630. %@NL@%
  17631. %@NL@%
  17632. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17633. %@NL@%
  17634. %@AB@%getc%@AE@%  %@NL@%
  17635. %@NL@%
  17636. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  17637. %@NL@%
  17638. %@NL@%
  17639. %@AB@%getchar%@AE@%  %@NL@%
  17640. %@NL@%
  17641. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  17642. %@NL@%
  17643. %@NL@%
  17644. %@NL@%
  17645. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17646. %@NL@%
  17647. %@AB@%fgetc%@AE@%, %@AB@%fgetchar%@AE@%, %@AB@%getch%@AE@%, %@AB@%getche%@AE@%, %@AB@%putc%@AE@%, %@AB@%putchar%@AE@%, %@AB@%ungetc%@AE@%  %@NL@%
  17648. %@NL@%
  17649. %@NL@%
  17650. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17651. %@NL@%
  17652. %@AS@%  /* GETC.C: This program uses getchar to read a single line of input
  17653. %@AS@%   * from stdin, places this input in buffer, then terminates the
  17654. %@AS@%   * string before printing it to the screen.
  17655. %@AS@%   */
  17656. %@AS@%  
  17657. %@AS@%  #include <stdio.h>
  17658. %@AS@%  %@AE@%%@NL@%
  17659. %@NL@%
  17660. %@AS@%  void main()
  17661. %@AS@%  {
  17662. %@AS@%     char buffer[81];
  17663. %@AS@%     int i, ch;
  17664. %@AS@%  
  17665. %@AS@%     printf( "Enter a line: " );
  17666. %@AS@%  
  17667. %@AS@%     /* Read in single line from "stdin": */
  17668. %@AS@%     for( i = 0; (i < 80) &&  ((ch = getchar()) != EOF) && (ch != '\n'); i++
  17669. %@AS@%)
  17670. %@AS@%        buffer[i] = ch;
  17671. %@AS@%  
  17672. %@AS@%     /* Terminate string with null character: */
  17673. %@AS@%     buffer[i] = '\0';
  17674. %@AS@%     printf( "%s\n", buffer );
  17675. %@AS@%  }%@AE@%%@NL@%
  17676. %@NL@%
  17677. %@NL@%
  17678. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  17679. %@NL@%
  17680. %@AS@%  
  17681. %@AS@%  
  17682. %@AS@%  Enter a line: This is a line of text.
  17683. %@AS@%  This is a line of text. %@AE@%%@NL@%
  17684. %@NL@%
  17685. %@NL@%
  17686. %@NL@%
  17687. %@NL@%
  17688. %@QR:getch@%%@QR:getche@%%@NL@%
  17689. %@2@%%@CR:C6A01330698 @%%@AB@%getch, getche%@AE@%%@EH@%%@NL@%
  17690. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17691. %@NL@%
  17692. %@NL@%
  17693. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  17694. %@NL@%
  17695. Get a character from the console without echo (%@AB@%getch%@AE@%) or with echo (%@AB@%getche%@AE@%).
  17696. %@NL@%
  17697. %@NL@%
  17698. %@CR:C6A01330699 @%%@CR:C6A01330700 @%%@CR:C6A01330701 @%%@CR:C6A01330702 @%  %@NL@%
  17699. %@NL@%
  17700. %@AB@%#include <conio.h> %@AE@%               Required only for function declarations
  17701.  
  17702. %@AS@%  int getch( void );%@AE@%%@NL@%
  17703. %@NL@%
  17704. %@AS@%  int getche( void );%@AE@%%@NL@%
  17705. %@NL@%
  17706. %@NL@%
  17707. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17708. %@NL@%
  17709. The %@AB@%getch%@AE@% function reads a single character from the console without
  17710. echoing. The %@AB@%getche%@AE@% function reads a single character from the console and
  17711. echoes the character read. Neither function can be used to read CTRL+C.  %@NL@%
  17712. %@NL@%
  17713. When reading a function key or cursor-moving key, the %@AB@%getch%@AE@% and %@AB@%getche%@AE@%
  17714. functions must be called twice; the first call returns 0 or 0xE0, and the
  17715. second call returns the actual key code.  %@NL@%
  17716. %@NL@%
  17717. %@NL@%
  17718. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17719. %@NL@%
  17720. The %@AB@%getch%@AE@% function returns the character read. There is no error return.  %@NL@%
  17721. %@NL@%
  17722. %@NL@%
  17723. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17724. %@NL@%
  17725.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  17726. %@NL@%
  17727. %@NL@%
  17728. %@NL@%
  17729. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17730. %@NL@%
  17731. %@AB@%cgets%@AE@%, %@AB@%getchar%@AE@%, %@AB@%ungetch%@AE@%  %@NL@%
  17732. %@NL@%
  17733. %@NL@%
  17734. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17735. %@NL@%
  17736. %@AS@%  /* GETCH.C: This program reads characters from the keyboard until it
  17737. %@AS@%   * receives a 'Y' or 'y'.
  17738. %@AS@%   */
  17739. %@AS@%  
  17740. %@AS@%  #include <conio.h>
  17741. %@AS@%  #include <ctype.h>
  17742. %@AS@%  %@AE@%%@NL@%
  17743. %@NL@%
  17744. %@AS@%  void main()
  17745. %@AS@%  {
  17746. %@AS@%     int ch;
  17747. %@AS@%  
  17748. %@AS@%     cputs( "Type 'Y' when finished typing keys: " );
  17749. %@AS@%     do
  17750. %@AS@%     {
  17751. %@AS@%        ch = getch();
  17752. %@AS@%        ch = toupper( ch );
  17753. %@AS@%     } while( ch != 'Y' );
  17754. %@AS@%  
  17755. %@AS@%     putch( ch );
  17756. %@AS@%     putch( '\r' );    /* Carriage return */
  17757. %@AS@%     putch( '\n' );    /* Line feed       */
  17758. %@AS@%  }%@AE@%%@NL@%
  17759. %@NL@%
  17760. %@NL@%
  17761. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  17762. %@NL@%
  17763. %@AS@%  
  17764. %@AS@%  
  17765. %@AS@%  Type 'Y' when finished typing keys: Y%@AE@%%@NL@%
  17766. %@NL@%
  17767. %@NL@%
  17768. %@NL@%
  17769. %@NL@%
  17770. %@QR:_getcolor@%%@NL@%
  17771. %@2@%%@CR:C6A01340703 @%%@AB@%_getcolor%@AE@%%@EH@%%@NL@%
  17772. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17773. %@NL@%
  17774. %@NL@%
  17775. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  17776. %@NL@%
  17777. Gets the current color.  %@NL@%
  17778. %@NL@%
  17779. %@CR:C6A01340704 @%%@AS@%  #include <graph.h>%@AE@%%@NL@%
  17780. %@NL@%
  17781. %@AS@%  short _far _getcolor( void );%@AE@%%@NL@%
  17782. %@NL@%
  17783. %@NL@%
  17784. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17785. %@NL@%
  17786. The %@AB@%_getcolor%@AE@% function returns the current graphics color index. The default
  17787. is the highest legal value of the current palette.  %@NL@%
  17788. %@NL@%
  17789. %@NL@%
  17790. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17791. %@NL@%
  17792. The %@AB@%_getcolor%@AE@% function returns the current color index.  %@NL@%
  17793. %@NL@%
  17794. %@NL@%
  17795. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17796. %@NL@%
  17797.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  17798. %@NL@%
  17799. %@NL@%
  17800. %@NL@%
  17801. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17802. %@NL@%
  17803. %@AB@%_setcolor%@AE@%  %@NL@%
  17804. %@NL@%
  17805. %@NL@%
  17806. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17807. %@NL@%
  17808. %@AS@%  /* OUTTXT.C: This example illustrates text output functions:
  17809. %@AS@%   *    _gettextcolor   _getbkcolor   _gettextposition   _outtext
  17810. %@AS@%   *    _settextcolor   _setbkcolor   _settextposition
  17811. %@AS@%   */
  17812. %@AS@%  
  17813. %@AS@%  #include <conio.h>
  17814. %@AS@%  #include <stdio.h>
  17815. %@AS@%  #include <graph.h>
  17816. %@AS@%  
  17817. %@AS@%  char buffer [80];
  17818. %@AS@%  
  17819. %@AS@%  void main()
  17820. %@AS@%  {
  17821. %@AS@%  
  17822. %@AS@%     /* Save original foreground, background, and text position. */
  17823. %@AS@%     short blink, fgd, oldfgd;
  17824. %@AS@%     long  bgd, oldbgd;
  17825. %@AS@%     struct rccoord oldpos;
  17826. %@AS@%  
  17827. %@AS@%     /* Save original foreground, background, and text position. */
  17828. %@AS@%     oldfgd = _gettextcolor();
  17829. %@AS@%     oldbgd = _getbkcolor();
  17830. %@AS@%     oldpos = _gettextposition();
  17831. %@AS@%     _clearscreen( _GCLEARSCREEN );
  17832. %@AS@%  %@AE@%%@NL@%
  17833. %@NL@%
  17834. %@AS@%  /* First time no blink, second time blinking. */
  17835. %@AS@%     for( blink = 0; blink <= 16; blink += 16 )
  17836. %@AS@%     {
  17837. %@AS@%        /* Loop through 8 background colors. */
  17838. %@AS@%        for( bgd = 0; bgd < 8; bgd++ )
  17839. %@AS@%        {
  17840. %@AS@%           _setbkcolor( bgd );
  17841. %@AS@%           _settextposition( (short)bgd + ((blink / 16) * 9) + 3, 1 );
  17842. %@AS@%           _settextcolor( 7 );
  17843. %@AS@%           sprintf(buffer, "Back: %d Fore:", bgd );
  17844. %@AS@%           _outtext( buffer );
  17845. %@AS@%  
  17846. %@AS@%           /* Loop through 16 foreground colors. */
  17847. %@AS@%           for( fgd = 0; fgd < 16; fgd++ )
  17848. %@AS@%           {
  17849. %@AS@%              _settextcolor( fgd + blink );
  17850. %@AS@%              sprintf( buffer, " %2d ", fgd + blink );
  17851. %@AS@%              _outtext( buffer );
  17852. %@AS@%           }
  17853. %@AS@%        }
  17854. %@AS@%     }
  17855. %@AS@%     getch();
  17856. %@AS@%  
  17857. %@AS@%     /* Restore original foreground, background, and text position. */
  17858. %@AS@%     _settextcolor( oldfgd );
  17859. %@AS@%     _setbkcolor( oldbgd );
  17860. %@AS@%     _clearscreen( _GCLEARSCREEN );
  17861. %@AS@%     _settextposition( oldpos.row, oldpos.col );
  17862. %@AS@%  }%@AE@%%@NL@%
  17863. %@NL@%
  17864. %@NL@%
  17865. %@NL@%
  17866. %@NL@%
  17867. %@QR:_getcurrentposition@%%@NL@%
  17868. %@2@%%@CR:C6A01350705 @%%@AB@%_getcurrentposition Functions%@AE@%%@EH@%%@NL@%
  17869. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17870. %@NL@%
  17871. %@NL@%
  17872. %@3@%%@AB@%Description %@CR:C6A01350706 @%%@AE@%%@EH@%%@NL@%
  17873. %@NL@%
  17874. Get the current position and return it as a structure.  %@NL@%
  17875. %@NL@%
  17876. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  17877. %@NL@%
  17878. %@AS@%  struct xycoord _far _getcurrentposition( void );%@AE@%%@NL@%
  17879. %@NL@%
  17880. %@AS@%  struct _wxycoord _far _getcurrentposition_w( void );%@AE@%%@NL@%
  17881. %@NL@%
  17882. %@NL@%
  17883. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17884. %@NL@%
  17885. The %@AB@%_getcurrentposition%@AE@% functions return the coordinates of the current
  17886. graphics output position. The %@AB@%_getcurrentposition%@AE@% function returns the
  17887. position as an %@AB@%xycoord%@AE@% structure, defined in GRAPH.H.  %@NL@%
  17888. %@NL@%
  17889. The %@AB@%xycoord%@AE@% structure contains the following elements:  %@NL@%
  17890. %@NL@%
  17891. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  17892. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17893. %@AB@%short xcoord%@AE@%                      %@AI@%x%@AE@% coordinate
  17894.  
  17895. %@AB@%short ycoord%@AE@%                      %@AI@%y%@AE@% coordinate
  17896.  
  17897. The %@AB@%_getcurrentposition_w%@AE@% function returns the position as an %@AB@%_wxycoord%@AE@%
  17898. structure, defined in GRAPH.H.  %@NL@%
  17899. %@NL@%
  17900. The %@AB@%_wxycoord%@AE@% structure contains the following elements:  %@NL@%
  17901. %@NL@%
  17902. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  17903. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17904. %@AB@%double wx%@AE@%                         window%@AI@% x%@AE@% coordinate
  17905.  
  17906. %@AB@%double wy%@AE@%                         window%@AI@% y%@AE@% coordinate
  17907.  
  17908. The current position can be changed by the %@AB@%_lineto%@AE@%, %@AB@%_moveto%@AE@%, and %@AB@%_outgtext%@AE@%
  17909. functions.  %@NL@%
  17910. %@NL@%
  17911. The default position, set by %@AB@%_setvideomode%@AE@%, %@AB@%_setvideomoderows%@AE@%, or
  17912. %@AB@%_setviewport%@AE@%, is the center of the viewport.  %@NL@%
  17913. %@NL@%
  17914. Only graphics output starts at the current position; these functions do not
  17915. affect text output, which begins at the current text position. (See
  17916. %@AB@%_settextposition%@AE@% for more information.)  %@NL@%
  17917. %@NL@%
  17918. %@NL@%
  17919. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  17920. %@NL@%
  17921. The %@AB@%_getcurrentposition%@AE@% function returns the coordinates of the current
  17922. graphics output position. There is no error return.  %@NL@%
  17923. %@NL@%
  17924. %@NL@%
  17925. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  17926. %@NL@%
  17927.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  17928. %@NL@%
  17929. %@NL@%
  17930. %@NL@%
  17931. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  17932. %@NL@%
  17933. %@AB@%_grstatus%@AE@%,  %@AB@%_lineto%@AE@% functions,  %@AB@%_moveto%@AE@% functions,  %@AB@%_outgtext%@AE@%  %@NL@%
  17934. %@NL@%
  17935. %@NL@%
  17936. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  17937. %@NL@%
  17938. %@AS@%  /* GCURPOS.C: This program sets a random current location, then gets that
  17939. %@AS@%   * location with _getcurrentposition.
  17940. %@AS@%   */
  17941. %@AS@%  
  17942. %@AS@%  #include <stdio.h>
  17943. %@AS@%  #include <stdlib.h>
  17944. %@AS@%  #include <conio.h>
  17945. %@AS@%  #include <graph.h>
  17946. %@AS@%  
  17947. %@AS@%  char   buffer[255];
  17948. %@AS@%  
  17949. %@AS@%  void main()
  17950. %@AS@%  {
  17951. %@AS@%     struct videoconfig vc;
  17952. %@AS@%     struct xycoord position;
  17953. %@AS@%  
  17954. %@AS@%     /* Find a valid graphics mode. */
  17955. %@AS@%     if( !_setvideomode( _MAXRESMODE ) )
  17956. %@AS@%        exit( 1 );
  17957. %@AS@%     _getvideoconfig( &vc );
  17958. %@AS@%  
  17959. %@AS@%     /* Move to random location and report that location. */
  17960. %@AS@%     _moveto( rand() % vc.numxpixels, rand() % vc.numypixels );
  17961. %@AS@%     position = _getcurrentposition();
  17962. %@AS@%     sprintf( buffer, "x = %d, y = %d", position.xcoord, position.ycoord );
  17963. %@AS@%     _settextposition( 1, 1 );
  17964. %@AS@%     _outtext( buffer );
  17965. %@AS@%  
  17966. %@AS@%     getch();
  17967. %@AS@%     _setvideomode( _DEFAULTMODE );
  17968. %@AS@%  }%@AE@%%@NL@%
  17969. %@NL@%
  17970. %@NL@%
  17971. %@NL@%
  17972. %@NL@%
  17973. %@QR:getcwd@%%@NL@%
  17974. %@2@%%@CR:C6A01360707 @%%@AB@%getcwd%@AE@%%@EH@%%@NL@%
  17975. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  17976. %@NL@%
  17977. %@NL@%
  17978. %@3@%%@AB@%Description%@CR:C6A01360708 @%%@CR:C6A01360709 @% %@CR:C6A01360710 @%%@AE@%%@EH@%%@NL@%
  17979. %@NL@%
  17980. Gets the current working directory.  %@NL@%
  17981. %@NL@%
  17982. %@AB@%#include <direct.h>%@AE@%               Required only for function declarations
  17983.  
  17984. %@AS@%  char *getcwd( char *buffer, int maxlen );%@AE@%%@NL@%
  17985. %@NL@%
  17986. %@AI@%buffer%@AE@%                            Storage location for path name
  17987.  
  17988. %@AI@%maxlen%@AE@%                            Maximum length of path name
  17989.  
  17990. %@NL@%
  17991. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  17992. %@NL@%
  17993. The %@AB@%getcwd%@AE@% function gets the full path name of the current working directory
  17994. and stores it at %@AI@%buffer%@AE@%. The integer argument %@AI@%maxlen%@AE@% specifies the maximum
  17995. length for the path name. An error occurs if the length of the path name
  17996. (including the terminating null character) exceeds %@AI@%maxlen.%@AE@%  %@NL@%
  17997. %@NL@%
  17998. The %@AI@%buffer%@AE@% argument can be %@AB@%NULL%@AE@%; a buffer of at least size %@AI@%maxlen%@AE@% (more only
  17999. if necessary) will automatically be allocated, using %@AB@%malloc%@AE@%, to store the
  18000. path name. This buffer can later be freed by calling %@AB@%free%@AE@% and passing it the
  18001. %@AB@%getcwd%@AE@% return value (a pointer to the allocated buffer).  %@NL@%
  18002. %@NL@%
  18003. %@NL@%
  18004. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18005. %@NL@%
  18006. The %@AB@%getcwd%@AE@% function returns a pointer to %@AI@%buffer%@AE@%. A %@AB@%NULL%@AE@% return value
  18007. indicates an error, and %@AB@%errno%@AE@% is set to one of the following values:  %@NL@%
  18008. %@NL@%
  18009. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  18010. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18011. %@AB@%ENOMEM%@AE@%                            Insufficient memory to allocate %@AI@%maxlen%@AE@% 
  18012.                                   bytes (when a %@AB@%NULL%@AE@% argument is given as %@AI@%%@AE@%
  18013.                                   %@AI@%buffer%@AE@%)
  18014.  
  18015. %@AB@%ERANGE%@AE@%                            Path name longer than %@AI@%maxlen%@AE@% characters
  18016.  
  18017. %@NL@%
  18018. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18019. %@NL@%
  18020.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  18021. %@NL@%
  18022. %@NL@%
  18023. %@NL@%
  18024. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18025. %@NL@%
  18026. %@AB@%chdir%@AE@%, %@AB@%mkdir%@AE@%, %@AB@%rmdir%@AE@%  %@NL@%
  18027. %@NL@%
  18028. %@NL@%
  18029. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18030. %@NL@%
  18031. %@AS@%  /* This program places the name of the current directory in the buffer
  18032. %@AS@%   * array, then displays the name of the current directory on the screen.
  18033. %@AS@%   * Specifying a length of _MAX_DIR leaves room for the longest legal
  18034. %@AS@%   * directory name.
  18035. %@AS@%   */%@AE@%%@NL@%
  18036. %@NL@%
  18037. %@AS@%  #include <direct.h>
  18038. %@AS@%  #include <stdlib.h>
  18039. %@AS@%  #include <stdio.h>
  18040. %@AS@%  
  18041. %@AS@%  void main()
  18042. %@AS@%  {
  18043. %@AS@%     char buffer[_MAX_DIR];
  18044. %@AS@%  
  18045. %@AS@%     /* Get the current working directory: */
  18046. %@AS@%     if( getcwd( buffer, _MAX_DIR ) == NULL )
  18047. %@AS@%        perror( "getcwd error" );
  18048. %@AS@%     else
  18049. %@AS@%        printf( "%s\n", buffer );
  18050. %@AS@%  }%@AE@%%@NL@%
  18051. %@NL@%
  18052. %@NL@%
  18053. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  18054. %@NL@%
  18055. %@AS@%  
  18056. %@AS@%  
  18057. %@AS@%  C:\LIBREF %@AE@%%@NL@%
  18058. %@NL@%
  18059. %@NL@%
  18060. %@NL@%
  18061. %@NL@%
  18062. %@QR:_getdcwd@%%@NL@%
  18063. %@2@%%@CR:C6A01370711 @%%@AB@%_getdcwd%@AE@%%@EH@%%@NL@%
  18064. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18065. %@NL@%
  18066. %@NL@%
  18067. %@3@%%@AB@%Description%@CR:C6A01370712 @%%@CR:C6A01370713 @% %@CR:C6A01370714 @%%@AE@%%@EH@%%@NL@%
  18068. %@NL@%
  18069. Gets full path name of current working directory, including disk drive.  %@NL@%
  18070. %@NL@%
  18071. %@AB@%#include <direct.h>%@AE@%               Required only for function declarations
  18072.  
  18073. %@AS@%  char *_getdcwd( int drive, char *buffer, int maxlen );%@AE@%%@NL@%
  18074. %@NL@%
  18075. %@AI@%drive%@AE@%                             Disk drive
  18076.  
  18077. %@AI@%buffer%@AE@%                            Storage location for path name
  18078.  
  18079. %@AI@%maxlen%@AE@%                            Maximum length of path name
  18080.  
  18081. %@NL@%
  18082. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18083. %@NL@%
  18084. The %@AB@%_getdcwd%@AE@% function gets the full path name of the current working
  18085. directory, including disk drive specification, and stores it at %@AI@%buffer%@AE@%. The
  18086. argument %@AI@%maxlen%@AE@% specifies the maximum length for the path name. An error
  18087. occurs if the length of the path name (including the terminating null
  18088. character) exceeds %@AI@%maxlen%@AE@%.  %@NL@%
  18089. %@NL@%
  18090. The %@AI@%drive%@AE@% argument specifies the drive (0 = default drive, 1=A, 2=B, etc.).
  18091. The %@AI@%buffer%@AE@% argument can be %@AB@%NULL%@AE@%; a buffer of at least size %@AI@%maxlen%@AE@% (more only
  18092. if necessary) will automatically be allocated, using %@AB@%malloc%@AE@%, to store the
  18093. path name. This buffer can later be freed by calling %@AB@%free%@AE@% and passing it the
  18094. %@AB@%_getdcwd%@AE@% return value (a pointer to the allocated buffer).  %@NL@%
  18095. %@NL@%
  18096. %@NL@%
  18097. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18098. %@NL@%
  18099. The %@AB@%_getdcwd%@AE@% function returns %@AI@%buffer%@AE@%. A %@AB@%NULL%@AE@% return value indicates an
  18100. error, and %@AB@%errno%@AE@% is set to one of the following values:  %@NL@%
  18101. %@NL@%
  18102. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  18103. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18104. %@AB@%ENOMEM%@AE@%                            Insufficient memory to allocate %@AI@%maxlen%@AE@% 
  18105.                                   bytes (when a %@AB@%NULL%@AE@% argument is given as %@AI@%%@AE@%
  18106.                                   %@AI@%buffer%@AE@%)
  18107.  
  18108. %@AB@%ERANGE%@AE@%                            Path name longer than %@AI@%maxlen%@AE@% characters
  18109.  
  18110. %@NL@%
  18111. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18112. %@NL@%
  18113.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  18114. %@NL@%
  18115. %@NL@%
  18116. %@NL@%
  18117. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18118. %@NL@%
  18119. %@AB@%chdir%@AE@%, %@AB@%getcwd%@AE@%, %@AB@%_getdrive%@AE@%,%@AB@% mkdir%@AE@%, %@AB@%rmdir%@AE@%  %@NL@%
  18120. %@NL@%
  18121. %@NL@%
  18122. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18123. %@NL@%
  18124. %@AS@%  /* GETDRIVE.C illustrates drive functions including:
  18125. %@AS@%   *      _getdrive       _chdrive        _getdcwd
  18126. %@AS@%   */%@AE@%%@NL@%
  18127. %@NL@%
  18128. %@AS@%  #include <stdio.h>
  18129. %@AS@%  #include <conio.h>
  18130. %@AS@%  #include <direct.h>
  18131. %@AS@%  #include <stdlib.h>
  18132. %@AS@%  
  18133. %@AS@%  void main()
  18134. %@AS@%  {
  18135. %@AS@%     int ch, drive, curdrive;
  18136. %@AS@%     static char path[_MAX_PATH];
  18137. %@AS@%  
  18138. %@AS@%     /* Save current drive. */
  18139. %@AS@%     curdrive = _getdrive();
  18140. %@AS@%  
  18141. %@AS@%     printf( "Available drives are: \n" );
  18142. %@AS@%  
  18143. %@AS@%     /* If we can switch to the drive, it exists. */
  18144. %@AS@%     for( drive = 1; drive <= 26; drive++ )
  18145. %@AS@%        if( !_chdrive( drive ) )
  18146. %@AS@%           printf( "%c: ", drive + 'A' - 1 );
  18147. %@AS@%  
  18148. %@AS@%     while( 1 )
  18149. %@AS@%     {
  18150. %@AS@%        printf( "\nType drive letter to check or ESC to quit: " );
  18151. %@AS@%        ch = getch();
  18152. %@AS@%        if( ch == 27 )
  18153. %@AS@%           break;
  18154. %@AS@%        if( isalpha( ch ) )
  18155. %@AS@%           putch( ch );
  18156. %@AS@%        if( _getdcwd( toupper( ch ) - 'A' + 1, path, _MAX_PATH ) != NULL )
  18157. %@AS@%           printf( "\nCurrent directory on that drive is %s\n", path );
  18158. %@AS@%     }
  18159. %@AS@%  
  18160. %@AS@%     /* Restore original drive. This is only necessary for DOS. Under OS/2
  18161. %@AS@%      * the current drive of the calling process is always restored.
  18162. %@AS@%      */
  18163. %@AS@%     _chdrive( curdrive );
  18164. %@AS@%     printf( "\n" );
  18165. %@AS@%  }%@AE@%%@NL@%
  18166. %@NL@%
  18167. %@NL@%
  18168. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  18169. %@NL@%
  18170. %@AS@%  
  18171. %@AS@%  
  18172. %@AS@%  Available drives are:
  18173. %@AS@%  A: B: C:
  18174. %@AS@%  Type drive letter to check or ESC to quit: q
  18175. %@AS@%  Type drive letter to check or ESC to quit: a
  18176. %@AS@%  Current directory on that drive is A:\
  18177. %@AS@%  
  18178. %@AS@%  Type drive letter to check or ESC to quit: c
  18179. %@AS@%  Current directory on that drive is C:\LIBREF
  18180. %@AS@%  
  18181. %@AS@%  Type drive letter to check or ESC to quit: %@AE@%%@NL@%
  18182. %@NL@%
  18183. %@NL@%
  18184. %@NL@%
  18185. %@NL@%
  18186. %@QR:_getdrive@%%@NL@%
  18187. %@2@%%@CR:C6A01380715 @%%@AB@%_getdrive%@AE@%%@EH@%%@NL@%
  18188. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18189. %@NL@%
  18190. %@NL@%
  18191. %@3@%%@AB@%Description%@CR:C6A01380716 @% %@CR:C6A01380717 @%%@AE@%%@EH@%%@NL@%
  18192. %@NL@%
  18193. Gets the current disk drive.  %@NL@%
  18194. %@NL@%
  18195. %@AS@%  #include <direct.h>%@AE@%%@NL@%
  18196. %@NL@%
  18197. %@AS@%  int _getdrive( void );%@AE@%%@NL@%
  18198. %@NL@%
  18199. %@NL@%
  18200. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18201. %@NL@%
  18202. The %@AB@%_getdrive%@AE@% function returns the current working drive (1=A, 2=B, etc.).  %@NL@%
  18203. %@NL@%
  18204. %@NL@%
  18205. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18206. %@NL@%
  18207. The return value is stated above. There is no error return.  %@NL@%
  18208. %@NL@%
  18209. %@NL@%
  18210. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18211. %@NL@%
  18212.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  18213. %@NL@%
  18214. %@NL@%
  18215. %@NL@%
  18216. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18217. %@NL@%
  18218. %@AB@%_chdrive%@AE@%,  %@AB@%_dos_getdrive%@AE@%,  %@AB@%_dos_setdrive%@AE@%,  %@AB@%_getcwd%@AE@%,  %@AB@%_getdcwd%@AE@%  %@NL@%
  18219. %@NL@%
  18220. %@NL@%
  18221. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18222. %@NL@%
  18223. See the example for %@AB@%_getdcwd%@AE@%.  %@NL@%
  18224. %@NL@%
  18225. %@NL@%
  18226. %@NL@%
  18227. %@NL@%
  18228. %@QR:getenv@%%@NL@%
  18229. %@2@%%@CR:C6A01390718 @%%@AB@%getenv%@AE@%%@EH@%%@NL@%
  18230. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18231. %@NL@%
  18232. %@NL@%
  18233. %@3@%%@AB@%Description%@CR:C6A01390719 @%%@AE@%%@EH@%%@NL@%
  18234. %@NL@%
  18235. Gets a value from the environment table.  %@NL@%
  18236. %@NL@%
  18237. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  18238.  
  18239. %@AS@%  char *getenv( const char *varname );%@AE@%%@NL@%
  18240. %@NL@%
  18241. %@AI@%varname%@AE@%                           Name of environment variable
  18242.  
  18243. %@NL@%
  18244. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18245. %@NL@%
  18246. The %@AB@%getenv%@AE@% function searches the list of environment variables for an entry
  18247. corresponding to %@AI@%varname%@AE@%. Environment variables define the environment in
  18248. which a process executes. (For example, the LIB environment variable defines
  18249. the default search path for libraries to be linked with a program.) Because
  18250. the %@AB@%getenv%@AE@% function is case sensitive, the %@AI@%varname%@AE@% variable should match the
  18251. case of the environment variable. %@CR:C6A01390720 @%  %@NL@%
  18252. %@NL@%
  18253. The %@AB@%getenv%@AE@% function returns a pointer to an entry in the environment table.
  18254. It is, however, only safe to retrieve the value of the environment variable
  18255. using the returned pointer. To modify the value of an environmental
  18256. variable, use the %@AB@%putenv%@AE@% function.  %@NL@%
  18257. %@NL@%
  18258. The %@AB@%getenv%@AE@% and %@AB@%putenv%@AE@% functions use the copy of the environment contained in
  18259. the global variable %@AB@%environ%@AE@% to access the environment. Programs that use the
  18260. %@AI@%envp%@AE@% argument to %@AB@%main%@AE@% and the %@AB@%putenv%@AE@% function may retrieve invalid
  18261. information. The safest programming practice is to use %@AB@%getenv%@AE@% and %@AB@%putenv%@AE@%.%@CR:C6A01390721 @%%@CR:C6A01390722 @%  %@NL@%
  18262. %@NL@%
  18263. %@NL@%
  18264. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18265. %@NL@%
  18266. The %@AB@%getenv%@AE@% function returns a pointer to the environment table entry
  18267. containing the current string value of %@AI@%varname%@AE@%. The return value is %@AB@%NULL%@AE@% if
  18268. the given variable is not currently defined.  %@NL@%
  18269. %@NL@%
  18270. %@NL@%
  18271. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18272. %@NL@%
  18273. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  18274. %@NL@%
  18275. %@NL@%
  18276. The %@AB@%getenv%@AE@% function operates only on the data structures accessible to the
  18277. run-time library and not on the environment "segment" created for a process
  18278. by DOS or OS/2.  %@NL@%
  18279. %@NL@%
  18280. %@NL@%
  18281. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18282. %@NL@%
  18283. %@AB@%putenv%@AE@%  %@NL@%
  18284. %@NL@%
  18285. %@NL@%
  18286. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18287. %@NL@%
  18288. %@AS@%  /* GETENV.C: This program uses getenv to retrieve the LIB environment
  18289. %@AS@%   * variable and then uses putenv to change it to a new value.
  18290. %@AS@%   */
  18291. %@AS@%  
  18292. %@AS@%  #include <stdlib.h>
  18293. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  18294. %@NL@%
  18295. %@AS@%  main()
  18296. %@AS@%  {
  18297. %@AS@%     char *libvar;
  18298. %@AS@%  
  18299. %@AS@%     /* Get the value of the LIB environment variable. */
  18300. %@AS@%     libvar = getenv( "LIB" );
  18301. %@AS@%     if( libvar != NULL )
  18302. %@AS@%        printf( "Original LIB variable is: %s\n", libvar );
  18303. %@AS@%  
  18304. %@AS@%     /* Attempt to change path. Note that this only affects the environment
  18305. %@AS@%      * variable of the current process. The command processor's environment
  18306. %@AS@%      * is not changed.
  18307. %@AS@%      */
  18308. %@AS@%     putenv( "LIB=c:\\mylib;c:\\yourlib" );
  18309. %@AS@%  
  18310. %@AS@%     /* Get new value. */
  18311. %@AS@%     libvar = getenv( "LIB" );
  18312. %@AS@%     if( libvar != NULL )
  18313. %@AS@%        printf( "New LIB variable is: %s\n", libvar );
  18314. %@AS@%  
  18315. %@AS@%  }%@AE@%%@NL@%
  18316. %@NL@%
  18317. %@NL@%
  18318. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  18319. %@NL@%
  18320. %@AS@%  
  18321. %@AS@%  
  18322. %@AS@%  Original LIB variable is: C:\LIB
  18323. %@AS@%  New LIB variable is: c:\mylib;c:\yourlib %@AE@%%@NL@%
  18324. %@NL@%
  18325. %@NL@%
  18326. %@NL@%
  18327. %@NL@%
  18328. %@QR:_getfillmask@%%@NL@%
  18329. %@2@%%@CR:C6A01400723 @%%@AB@%_getfillmask%@AE@%%@EH@%%@NL@%
  18330. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18331. %@NL@%
  18332. %@NL@%
  18333. %@3@%%@AB@%Description%@CR:C6A01400724 @%%@AE@%%@EH@%%@NL@%
  18334. %@NL@%
  18335. Gets the current fill mask for some graphics routines.  %@NL@%
  18336. %@NL@%
  18337. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18338. %@NL@%
  18339. %@AS@%  unsigned char _far * _far _getfillmask( unsigned char _far *mask );%@AE@%%@NL@%
  18340. %@NL@%
  18341. %@AI@%mask%@AE@%                              Mask array
  18342.  
  18343. %@NL@%
  18344. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18345. %@NL@%
  18346. Some graphics routines (%@AB@%_ellipse%@AE@%, %@AB@%_floodfill%@AE@%, %@AB@%_pie%@AE@%, %@AB@%_polygon%@AE@%, and%@AB@%
  18347. %@AB@%_rectangle%@AE@%) can fill part or all of the screen with the current color or
  18348. background color. The fill mask controls the pattern used for filling.  %@NL@%
  18349. %@NL@%
  18350. The %@AB@%_getfillmask%@AE@% function returns the current fill mask. The mask is an
  18351. 8-by-8-bit array, in which each bit represents a pixel. If the bit is 1, the
  18352. corresponding pixel is set to the current color; if the bit is 0, the pixel
  18353. is left unchanged. The mask is repeated over the entire fill area. If no
  18354. fill mask is set, or if %@AI@%mask%@AE@% is %@AB@%NULL%@AE@%, a solid (unpatterned) fill is
  18355. performed using the current color.  %@NL@%
  18356. %@NL@%
  18357. %@NL@%
  18358. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18359. %@NL@%
  18360. If no mask is set, the function returns %@AB@%NULL%@AE@%.  %@NL@%
  18361. %@NL@%
  18362. %@NL@%
  18363. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18364. %@NL@%
  18365.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18366. %@NL@%
  18367. %@NL@%
  18368. %@NL@%
  18369. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18370. %@NL@%
  18371. %@AB@%_ellipse%@AE@% functions,  %@AB@%_floodfill%@AE@%,  %@AB@%_pie%@AE@% functions,  %@AB@%_polygon%@AE@% functions,
  18372. %@AB@%_rectangle%@AE@% functions, %@AB@%_setfillmask%@AE@%  %@NL@%
  18373. %@NL@%
  18374. %@NL@%
  18375. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18376. %@NL@%
  18377. %@AS@%  /* GFILLMSK.C: This program illustrates _getfillmask and _setfillmask. */
  18378. %@AS@%  
  18379. %@AS@%  #include <conio.h>
  18380. %@AS@%  #include <stdlib.h>
  18381. %@AS@%  #include <graph.h>
  18382. %@AS@%  %@AE@%%@NL@%
  18383. %@NL@%
  18384. %@AS@%  void ellipsemask( short x1, short y1, short x2, short y2, char _far
  18385. %@AS@%  *newmask );
  18386. %@AS@%  
  18387. %@AS@%  unsigned char mask1[8] = { 0x43, 0x23, 0x7c, 0xf7, 0x8a, 0x4d, 0x78, 0x39
  18388. %@AS@%};
  18389. %@AS@%  unsigned char mask2[8] = { 0x18, 0xad, 0xc0, 0x79, 0xf6, 0xc4, 0xa8, 0x23
  18390. %@AS@%};
  18391. %@AS@%  char oldmask[8];
  18392. %@AS@%  
  18393. %@AS@%  void main()
  18394. %@AS@%  {
  18395. %@AS@%     int loop;
  18396. %@AS@%  
  18397. %@AS@%     /* Find a valid graphics mode. */
  18398. %@AS@%     if( !_setvideomode( _MAXRESMODE ) )
  18399. %@AS@%        exit( 1 );
  18400. %@AS@%  
  18401. %@AS@%     /* Set first fill mask and draw rectangle. */
  18402. %@AS@%     _setfillmask( mask1 );
  18403. %@AS@%     _rectangle( _GFILLINTERIOR, 20, 20, 100, 100 );
  18404. %@AS@%     getch();
  18405. %@AS@%  
  18406. %@AS@%     /* Call routine that saves and restores mask. */
  18407. %@AS@%     ellipsemask( 60, 60, 150, 150, mask2 );
  18408. %@AS@%     getch();
  18409. %@AS@%  
  18410. %@AS@%     /* Back to original mask. */
  18411. %@AS@%     _rectangle( _GFILLINTERIOR, 120, 120, 190, 190 );
  18412. %@AS@%     getch();
  18413. %@AS@%  
  18414. %@AS@%     _setvideomode( _DEFAULTMODE );
  18415. %@AS@%  }
  18416. %@AS@%  
  18417. %@AS@%  /* Draw an ellipse with a specified fill mask. */
  18418. %@AS@%  void ellipsemask( short x1, short y1, short x2, short y2, char _far
  18419. %@AS@%*newmask )
  18420. %@AS@%  {
  18421. %@AS@%     unsigned char savemask[8];
  18422. %@AS@%  
  18423. %@AS@%     _getfillmask( savemask );                    /* Save mask         */
  18424. %@AS@%     _setfillmask( newmask );                     /* Set new mask      */
  18425. %@AS@%     _ellipse( _GFILLINTERIOR, x1, y1, x2, y2 );  /* Use new mask      */
  18426. %@AS@%     _setfillmask( savemask );                    /* Restore original  */
  18427. %@AS@%  } %@AE@%%@NL@%
  18428. %@NL@%
  18429. %@NL@%
  18430. %@NL@%
  18431. %@NL@%
  18432. %@QR:_getfontinfo@%%@NL@%
  18433. %@2@%%@CR:C6A01410725 @%%@AB@%_getfontinfo%@AE@%%@EH@%%@NL@%
  18434. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18435. %@NL@%
  18436. %@NL@%
  18437. %@3@%%@AB@%Description%@CR:C6A01410726 @% %@CR:C6A01410727 @%%@AE@%%@EH@%%@NL@%
  18438. %@NL@%
  18439. Gets the current font characteristics.  %@NL@%
  18440. %@NL@%
  18441. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18442. %@NL@%
  18443. %@AS@%  short _far _getfontinfo( struct _fontinfo _far *fontbuffer );%@AE@%%@NL@%
  18444. %@NL@%
  18445. %@AI@%fontbuffer%@AE@%                        Buffer to hold font information
  18446.  
  18447. %@NL@%
  18448. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18449. %@NL@%
  18450. The %@AB@%_getfontinfo%@AE@% function gets the current font characteristics and stores
  18451. them in a%@AB@% _fontinfo%@AE@% structure, defined in GRAPH.H.  %@NL@%
  18452. %@NL@%
  18453. The %@AB@%_fontinfo%@AE@% structure contains the following elements:  %@NL@%
  18454. %@NL@%
  18455. %@AB@%Element%@AE@%                           %@AB@%Contents%@AE@%
  18456. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18457. %@AB@%int type%@AE@%                          Specifies vector (1) or bit-mapped (0) 
  18458.                                   font
  18459.  
  18460. %@AB@%int ascent%@AE@%                        Specifies pixel distance from top to 
  18461.                                   baseline
  18462.  
  18463. %@AB@%int pixwidth%@AE@%                      Specifies the character width in pixels;
  18464.                                   0 indicates a proportional font 
  18465.  
  18466. %@AB@%int pixheight%@AE@%                     Specifies the character height in pixels
  18467.  
  18468. %@AB@%int avgwidth%@AE@%                      Specifies the average character width in
  18469.                                   pixels
  18470.  
  18471. %@AB@%char filename [81]%@AE@%                Specifies the file name, including the 
  18472.                                   path
  18473.  
  18474. %@AB@%char facename%@AE@% %@AB@%[32]%@AE@%                Specifies the font name
  18475.  
  18476. %@NL@%
  18477. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18478. %@NL@%
  18479. The %@AB@%_getfontinfo%@AE@% function returns a negative number if a font has not been
  18480. registered or loaded.  %@NL@%
  18481. %@NL@%
  18482. %@NL@%
  18483. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18484. %@NL@%
  18485.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18486. %@NL@%
  18487. %@NL@%
  18488. %@NL@%
  18489. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18490. %@NL@%
  18491. %@AB@%_getgtextextent%@AE@%,  %@AB@%_outgtext%@AE@%,  %@AB@%_registerfonts%@AE@%,  %@AB@%_setfont%@AE@%,  %@AB@%_setgtextvector%@AE@%,
  18492. %@AB@%_unregisterfonts%@AE@%  %@NL@%
  18493. %@NL@%
  18494. %@NL@%
  18495. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18496. %@NL@%
  18497. See the example for %@AB@%_outgtext%@AE@%.  %@NL@%
  18498. %@NL@%
  18499. %@NL@%
  18500. %@NL@%
  18501. %@NL@%
  18502. %@QR:_getgtextextent@%%@NL@%
  18503. %@2@%%@CR:C6A01420728 @%%@AB@%_getgtextextent%@CR:C6A01420729 @%%@AE@%%@EH@%%@NL@%
  18504. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18505. %@NL@%
  18506. %@NL@%
  18507. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  18508. %@NL@%
  18509. Gets the width in pixels of font-based text.  %@NL@%
  18510. %@NL@%
  18511. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18512. %@NL@%
  18513. %@AS@%  short _far _getgtextextent( unsigned char _far *text );%@AE@%%@NL@%
  18514. %@NL@%
  18515. %@AI@%text%@AE@%                              Text to be analyzed
  18516.  
  18517. %@NL@%
  18518. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18519. %@NL@%
  18520. The %@AB@%_getgtextextent%@AE@% function returns the width in pixels that would be
  18521. required to print the %@AI@%text%@AE@% string using %@AB@%_outgtext %@AE@%with the current font.  %@NL@%
  18522. %@NL@%
  18523. This function is particularly useful for determining the size of text that
  18524. uses proportionally spaced fonts.  %@NL@%
  18525. %@NL@%
  18526. %@NL@%
  18527. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18528. %@NL@%
  18529. The %@AB@%_getgtextextent%@AE@% function returns the width in pixels. It returns -1 if a
  18530. font has not been registered.  %@NL@%
  18531. %@NL@%
  18532. %@NL@%
  18533. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18534. %@NL@%
  18535.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18536. %@NL@%
  18537. %@NL@%
  18538. %@NL@%
  18539. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18540. %@NL@%
  18541. %@AB@%_getfontinfo%@AE@%,  %@AB@%_outgtext%@AE@%,%@AB@%  _registerfonts%@AE@%,  %@AB@%_setfont%@AE@%, %@AB@% _unregisterfonts  %@AE@%%@NL@%
  18542. %@NL@%
  18543. %@NL@%
  18544. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18545. %@NL@%
  18546. See the example for %@AB@%_outgtext%@AE@%.  %@NL@%
  18547. %@NL@%
  18548. %@NL@%
  18549. %@NL@%
  18550. %@NL@%
  18551. %@QR:_getimage@%%@NL@%
  18552. %@2@%%@CR:C6A01430730 @%%@AB@%_getimage Functions%@AE@%%@EH@%%@NL@%
  18553. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18554. %@NL@%
  18555. %@NL@%
  18556. %@3@%%@AB@%Description%@CR:C6A01430731 @%%@AE@%%@EH@%%@NL@%
  18557. %@NL@%
  18558. Store images in buffers.  %@NL@%
  18559. %@NL@%
  18560. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18561. %@NL@%
  18562. %@AS@%  void _far _getimage( short x1, short y1, short x2, short y2, char _huge
  18563. %@AS@%  *image );%@AE@%%@NL@%
  18564. %@NL@%
  18565. %@AS@%  void _far _getimage_w( double wx1, double wy1, double wx2, double wy2, 
  18566. %@AS@%  char _huge *image );%@AE@%%@NL@%
  18567. %@NL@%
  18568. %@AS@%  void _far _getimage_wxy( struct_wxycoord _far *pwxy1,
  18569. %@AS@%  struct_wxycoord _far *pwxy2, char _huge *image );%@AE@%%@NL@%
  18570. %@NL@%
  18571. %@AI@%x1%@AE@%, %@AI@%y1%@AE@%                            Upper-left corner of bounding rectangle
  18572.  
  18573. %@AI@%x2%@AE@%, %@AI@%y2%@AE@%                            Lower-right corner of bounding rectangle
  18574.  
  18575. %@AI@%wx1%@AE@%, %@AI@%wy1%@AE@%                          Upper-left corner of bounding rectangle
  18576.  
  18577. %@AI@%wx2%@AE@%, %@AI@%wy2%@AE@%                          Lower-right corner of bounding rectangle
  18578.  
  18579. %@AI@%pwxy1%@AE@%                             Upper-left corner of bounding rectangle
  18580.  
  18581. %@AI@%pwxy2%@AE@%                             Lower-right corner of bounding rectangle
  18582.  
  18583. %@AI@%image%@AE@%                             Storage buffer for screen image
  18584.  
  18585. %@NL@%
  18586. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18587. %@NL@%
  18588. The %@AB@%_getimage%@AE@% functions store the screen image defined by a specified
  18589. bounding rectangle into the buffer pointed to by %@AI@%image%@AE@%.  %@NL@%
  18590. %@NL@%
  18591. The %@AB@%_getimage%@AE@% function defines the bounding rectangle with the view
  18592. coordinates (%@AI@%x1%@AE@%, %@AI@%y1%@AE@%) and (%@AI@%x2%@AE@%, %@AI@%y2%@AE@%).  %@NL@%
  18593. %@NL@%
  18594. The %@AB@%_getimage_w%@AE@% function defines the bounding rectangle with the window
  18595. coordinates (%@AI@%wx1%@AE@%, %@AI@%wy1%@AE@%) and (%@AI@%wx2%@AE@%, %@AI@%wy2%@AE@%).  %@NL@%
  18596. %@NL@%
  18597. The %@AB@%_getimage_wxy%@AE@% function defines the bounding rectangle with the
  18598. window-coordinate pairs %@AI@%pwxy1%@AE@% and %@AI@%pwxy2%@AE@%.  %@NL@%
  18599. %@NL@%
  18600. The buffer must be large enough to hold the image. You can determine the
  18601. size by calling the appropriate %@AB@%_imagesize%@AE@% function at run time, or by using
  18602. the formula described on the %@AB@%_imagesize%@AE@% reference page.  %@NL@%
  18603. %@NL@%
  18604. %@NL@%
  18605. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18606. %@NL@%
  18607. None. Use %@AB@%_grstatus%@AE@% to check success.  %@NL@%
  18608. %@NL@%
  18609. %@NL@%
  18610. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18611. %@NL@%
  18612.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18613. %@NL@%
  18614. %@NL@%
  18615. %@NL@%
  18616. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18617. %@NL@%
  18618. %@AB@%_grstatus%@AE@%,  %@AB@%_imagesize%@AE@% functions,  %@AB@%_putimage%@AE@% functions  %@NL@%
  18619. %@NL@%
  18620. %@NL@%
  18621. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18622. %@NL@%
  18623. %@AS@%  /* GIMAGE.C: This example illustrates animation routines including:
  18624. %@AS@%   *          _imagesize     _getimage     _putimage
  18625. %@AS@%   */
  18626. %@AS@%  
  18627. %@AS@%  #include <conio.h>
  18628. %@AS@%  #include <stddef.h>
  18629. %@AS@%  #include <stdlib.h>
  18630. %@AS@%  #include <malloc.h>
  18631. %@AS@%  #include <graph.h>
  18632. %@AS@%  
  18633. %@AS@%  short action[5]  = { _GPSET,   _GPRESET, _GXOR,    _GOR,     _GAND     };
  18634. %@AS@%  char *descrip[5] = {  "PSET  ", "PRESET", "XOR   ", "OR    ", "AND   " };
  18635. %@AS@%  
  18636. %@AS@%  void exitfree( char _huge *buffer );
  18637. %@AS@%  
  18638. %@AS@%  void main()
  18639. %@AS@%  {
  18640. %@AS@%      char  _huge *buffer;   /* Far pointer (with _fmalloc) could be used.
  18641. %@AS@%*/
  18642. %@AS@%      long  imsize;
  18643. %@AS@%      short i, x, y = 30;
  18644. %@AS@%  
  18645. %@AS@%      if( !_setvideomode( _MAXRESMODE ) )
  18646. %@AS@%          exit( 1 );
  18647. %@AS@%  
  18648. %@AS@%      /* Measure the image to be drawn and allocate memory for it. */
  18649. %@AS@%      imsize = (size_t)_imagesize( -16, -16, +16, +16 );
  18650. %@AS@%      buffer = halloc( imsize, sizeof( char ) );
  18651. %@AS@%      if ( buffer == (char _far *)NULL )
  18652. %@AS@%          exit( 1 );
  18653. %@AS@%  
  18654. %@AS@%      _setcolor( 3 );
  18655. %@AS@%      for ( i = 0; i < 5; i++ )
  18656. %@AS@%      {
  18657. %@AS@%          /* Draw ellipse at new position and get a copy of it. */
  18658. %@AS@%          x = 50; y += 40;
  18659. %@AS@%          _ellipse( _GFILLINTERIOR, x - 15, y - 15, x + 15, y + 15 );
  18660. %@AS@%          _getimage( x - 16, y - 16, x + 16, y + 16, buffer );
  18661. %@AS@%          if( _grstatus() )
  18662. %@AS@%              exitfree( buffer );        /* Quit on error
  18663. %@AS@%*/
  18664. %@AS@%  %@AE@%%@NL@%
  18665. %@NL@%
  18666. %@AS@%  /* Display action type and copy a row of ellipses with that type. */
  18667. %@AS@%          _settextposition( 1, 1 );
  18668. %@AS@%          _outtext( descrip[i] );
  18669. %@AS@%          while( x < 260 )
  18670. %@AS@%          {
  18671. %@AS@%              x += 5;
  18672. %@AS@%              _putimage( x - 16, y - 16, buffer, action[i] );
  18673. %@AS@%              if( _grstatus() < 0 )      /* Ignore warnings, quit on errors.
  18674. %@AS@%*/
  18675. %@AS@%                  exitfree( buffer );
  18676. %@AS@%          }
  18677. %@AS@%          getch();
  18678. %@AS@%      }
  18679. %@AS@%      exitfree( buffer );
  18680. %@AS@%  }
  18681. %@AS@%  
  18682. %@AS@%  void exitfree( char _huge *buffer )
  18683. %@AS@%  {
  18684. %@AS@%      hfree( buffer );
  18685. %@AS@%      exit( !_setvideomode( _DEFAULTMODE ) );
  18686. %@AS@%  }%@AE@%%@NL@%
  18687. %@NL@%
  18688. %@NL@%
  18689. %@NL@%
  18690. %@NL@%
  18691. %@QR:_getlinestyle@%%@NL@%
  18692. %@2@%%@CR:C6A01440732 @%%@AB@%_getlinestyle%@AE@%%@EH@%%@NL@%
  18693. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18694. %@NL@%
  18695. %@NL@%
  18696. %@3@%%@AB@%Description%@CR:C6A01440733 @%%@AE@%%@EH@%%@NL@%
  18697. %@NL@%
  18698. Gets the current line style.  %@NL@%
  18699. %@NL@%
  18700. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18701. %@NL@%
  18702. %@AS@%  unsigned short _far _getlinestyle( void );%@AE@%%@NL@%
  18703. %@NL@%
  18704. %@NL@%
  18705. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18706. %@NL@%
  18707. Some graphics routines ( _lineto, %@AB@%_polygon%@AE@%, and %@AB@%_rectangle%@AE@%) output straight
  18708. lines to the screen. The type of line can be controlled with the current
  18709. line-style mask.  %@NL@%
  18710. %@NL@%
  18711. The %@AB@%_getlinestyle%@AE@% function returns the current line-style mask. The mask is
  18712. a 16-bit array in which each bit represents a pixel in the line being drawn.
  18713. If the bit is 1, the corresponding pixel is set to the color of the line
  18714. (the current color). If the bit is 0, the corresponding pixel is left
  18715. unchanged. The mask is repeated over the length of the line. The default
  18716. mask is 0xFFFF (a solid line).  %@NL@%
  18717. %@NL@%
  18718. %@NL@%
  18719. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18720. %@NL@%
  18721. If no mask has been set, %@AB@%_getlinestyle%@AE@% returns the default mask.  %@NL@%
  18722. %@NL@%
  18723. %@NL@%
  18724. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18725. %@NL@%
  18726.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18727. %@NL@%
  18728. %@NL@%
  18729. %@NL@%
  18730. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18731. %@NL@%
  18732. %@AB@%_lineto%@AE@% functions,  %@AB@%_polygon%@AE@% functions,  %@AB@%_rectangle%@AE@% functions,
  18733. %@AB@%_setlinestyle%@AE@%, %@AB@%_setwritemode%@AE@%  %@NL@%
  18734. %@NL@%
  18735. %@NL@%
  18736. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18737. %@NL@%
  18738. %@AS@%  /* GLINESTY.C: This program illustrates _setlinestyle and _getlinestyle.
  18739. %@AS@%  */
  18740. %@AS@%  
  18741. %@AS@%  #include <conio.h>
  18742. %@AS@%  #include <stdlib.h>
  18743. %@AS@%  #include <graph.h>
  18744. %@AS@%  
  18745. %@AS@%  void zigzag( short x1, short y1, short size );
  18746. %@AS@%  
  18747. %@AS@%  void main()
  18748. %@AS@%  {
  18749. %@AS@%  
  18750. %@AS@%     /* Find a valid graphics mode. */
  18751. %@AS@%     if( !_setvideomode( _MAXCOLORMODE ) )
  18752. %@AS@%        exit( 1 );
  18753. %@AS@%  
  18754. %@AS@%     /* Set line style and draw rectangle. */
  18755. %@AS@%     _setlinestyle( 0x4d );
  18756. %@AS@%     _rectangle( _GBORDER, 10, 10, 60, 60 );
  18757. %@AS@%     getch();%@AE@%%@NL@%
  18758. %@NL@%
  18759. %@AS@%  
  18760. %@AS@%     /* Draw figure with function that changes and restores line style. */
  18761. %@AS@%     zigzag( 100, 100, 90 );
  18762. %@AS@%     getch();
  18763. %@AS@%  
  18764. %@AS@%     /* Original style reused. */
  18765. %@AS@%     _rectangle( _GBORDER, 190, 190, 130, 130 );
  18766. %@AS@%     getch();
  18767. %@AS@%  
  18768. %@AS@%     _setvideomode( _DEFAULTMODE );
  18769. %@AS@%  }
  18770. %@AS@%  
  18771. %@AS@%  /* Draw box with changing line styles. Restore original style. */
  18772. %@AS@%  void zigzag( short x1, short y1, short size )
  18773. %@AS@%  {
  18774. %@AS@%     short x, y, oldcolor;
  18775. %@AS@%     unsigned short oldstyle;
  18776. %@AS@%     unsigned short style[16] = { 0x0001, 0x0003, 0x0007, 0x000f,
  18777. %@AS@%                                  0x001f, 0x003f, 0x007f, 0x00ff,
  18778. %@AS@%                                  0x01ff, 0x03ff, 0x07ff, 0x0fff,
  18779. %@AS@%                                  0x1fff, 0x3fff, 0x7fff, 0xffff };
  18780. %@AS@%  
  18781. %@AS@%     oldcolor = _getcolor();
  18782. %@AS@%     oldstyle = _getlinestyle();            /* Save old line style.
  18783. %@AS@%*/
  18784. %@AS@%     for( x = 3, y = 3; x < size; x += 3, y += 3 )
  18785. %@AS@%     {
  18786. %@AS@%        _setcolor( x % 16 );
  18787. %@AS@%        _setlinestyle( style[x % 16] );     /* Set and use new line styles
  18788. %@AS@%*/
  18789. %@AS@%        _rectangle( _GBORDER, x1 - x, y1 - y, x1 + x, y1 + y );
  18790. %@AS@%     }
  18791. %@AS@%     _setlinestyle( oldstyle );             /* Restore old line style.
  18792. %@AS@%*/
  18793. %@AS@%     _setcolor( oldcolor );
  18794. %@AS@%  }%@AE@%%@NL@%
  18795. %@NL@%
  18796. %@NL@%
  18797. %@NL@%
  18798. %@NL@%
  18799. %@QR:_getphyscoord@%%@NL@%
  18800. %@2@%%@CR:C6A01450734 @%%@AB@%_getphyscoord%@AE@%%@EH@%%@NL@%
  18801. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18802. %@NL@%
  18803. %@NL@%
  18804. %@3@%%@AB@%Description%@CR:C6A01450735 @%%@AE@%%@EH@%%@NL@%
  18805. %@NL@%
  18806. Gets physical coordinates.  %@NL@%
  18807. %@NL@%
  18808. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18809. %@NL@%
  18810. %@AS@%  struct xycoord _far _getphyscoord( short x, short y );%@AE@%%@NL@%
  18811. %@NL@%
  18812. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              View coordinates to translate
  18813.  
  18814. %@NL@%
  18815. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18816. %@NL@%
  18817. The %@AB@%_getphyscoord%@AE@% function translates the view coordinates (%@AI@%x%@AE@%, %@AI@%y%@AE@%) to
  18818. physical coordinates and returns them in an %@AB@%xycoord%@AE@% structure, defined in
  18819. GRAPH.H.  %@NL@%
  18820. %@NL@%
  18821. The %@AB@%xycoord%@AE@% structure contains the following elements:  %@NL@%
  18822. %@NL@%
  18823. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  18824. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18825. %@AB@%short xcoord%@AE@%                      %@AI@%x %@AE@%coordinate
  18826.  
  18827. %@AB@%short ycoord%@AE@%                      %@AI@%y %@AE@%coordinate
  18828.  
  18829. %@NL@%
  18830. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18831. %@NL@%
  18832. None.  %@NL@%
  18833. %@NL@%
  18834. %@NL@%
  18835. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18836. %@NL@%
  18837.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18838. %@NL@%
  18839. %@NL@%
  18840. %@NL@%
  18841. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18842. %@NL@%
  18843. %@AB@%_getviewcoord%@AE@% functions,  %@AB@%_grstatus%@AE@%,  %@AB@%_setvieworg%@AE@%,  %@AB@%_setviewport%@AE@%  %@NL@%
  18844. %@NL@%
  18845. %@NL@%
  18846. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18847. %@NL@%
  18848. See the example for %@AB@%_setwindow%@AE@%.  %@NL@%
  18849. %@NL@%
  18850. %@NL@%
  18851. %@NL@%
  18852. %@NL@%
  18853. %@QR:getpid@%%@NL@%
  18854. %@2@%%@CR:C6A01460736 @%%@AB@%getpid%@AE@%%@EH@%%@NL@%
  18855. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18856. %@NL@%
  18857. %@NL@%
  18858. %@3@%%@AB@%Description%@CR:C6A01460737 @%%@CR:C6A01460738 @%%@CR:C6A01460739 @%%@AE@%%@EH@%%@NL@%
  18859. %@NL@%
  18860. Gets the process identification.  %@NL@%
  18861. %@NL@%
  18862. %@AB@%#include <process.h>%@AE@%              Required only for function declarations
  18863.  
  18864. %@AS@%  int getpid( void );%@AE@%%@NL@%
  18865. %@NL@%
  18866. %@NL@%
  18867. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18868. %@NL@%
  18869. The %@AB@%getpid%@AE@% function returns the process ID, an integer that uniquely
  18870. identifies the calling process.  %@NL@%
  18871. %@NL@%
  18872. %@NL@%
  18873. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18874. %@NL@%
  18875. The %@AB@%getpid%@AE@% function returns the process ID. There is no error return.  %@NL@%
  18876. %@NL@%
  18877. %@NL@%
  18878. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18879. %@NL@%
  18880.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  18881. %@NL@%
  18882. %@NL@%
  18883. %@NL@%
  18884. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18885. %@NL@%
  18886. %@AB@%mktemp%@AE@%  %@NL@%
  18887. %@NL@%
  18888. %@NL@%
  18889. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18890. %@NL@%
  18891. %@AS@%  /* GETPID.C: This program uses getpid to obtain the process ID and
  18892. %@AS@%   * then prints the ID.
  18893. %@AS@%   */
  18894. %@AS@%  
  18895. %@AS@%  #include <stdio.h>
  18896. %@AS@%  #include <process.h>
  18897. %@AS@%  
  18898. %@AS@%  void main( )
  18899. %@AS@%  {
  18900. %@AS@%     /* If run from DOS, shows different ID for DOS than for DOS shell.
  18901. %@AS@%      * If execed or spawned, shows ID of parent.
  18902. %@AS@%      */
  18903. %@AS@%     printf( "\nProcess id of parent: %d\n", getpid() );
  18904. %@AS@%  }%@AE@%%@NL@%
  18905. %@NL@%
  18906. %@NL@%
  18907. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  18908. %@NL@%
  18909. %@AS@%  
  18910. %@AS@%  
  18911. %@AS@%  
  18912. %@AS@%  Process id of parent: 828%@AE@%%@NL@%
  18913. %@NL@%
  18914. %@NL@%
  18915. %@NL@%
  18916. %@NL@%
  18917. %@QR:_getpixel@%%@NL@%
  18918. %@2@%%@CR:C6A01470740 @%%@AB@%_getpixel Functions%@AE@%%@EH@%%@NL@%
  18919. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  18920. %@NL@%
  18921. %@NL@%
  18922. %@3@%%@AB@%Description%@CR:C6A01470741 @%%@AE@%%@EH@%%@NL@%
  18923. %@NL@%
  18924. Get pixel values.  %@NL@%
  18925. %@NL@%
  18926. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  18927. %@NL@%
  18928. %@AS@%  short _far _getpixel( short x, short y );%@AE@%%@NL@%
  18929. %@NL@%
  18930. %@AS@%  short _far _getpixel_w( double wx, double wy );%@AE@%%@NL@%
  18931. %@NL@%
  18932. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Pixel position
  18933.  
  18934. %@AI@%wx%@AE@%, %@AI@%wy %@AE@%                           Pixel position
  18935.  
  18936. %@NL@%
  18937. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  18938. %@NL@%
  18939. The functions in the %@AB@%_getpixel%@AE@% family return the pixel value (a color index)
  18940. at a specified location. The %@AB@%_getpixel%@AE@% function uses the view coordinate (%@AI@%x%@AE@%,
  18941. %@AI@%y%@AE@%). The %@AB@%_getpixel_w%@AE@% function uses the window coordinate (%@AI@%wx%@AE@%, %@AI@%wy%@AE@%). The range
  18942. of possible pixel values is determined by the current video mode. The color
  18943. translation of pixel values is determined by the current palette.  %@NL@%
  18944. %@NL@%
  18945. %@NL@%
  18946. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  18947. %@NL@%
  18948. If successful, the function returns the color index. If the function fails
  18949. (for example, the point lies outside the clipping region, or the program is
  18950. in a text mode), it returns -1.  %@NL@%
  18951. %@NL@%
  18952. %@NL@%
  18953. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  18954. %@NL@%
  18955.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  18956. %@NL@%
  18957. %@NL@%
  18958. %@NL@%
  18959. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  18960. %@NL@%
  18961. %@AB@%_getvideoconfig%@AE@%,  %@AB@%_grstatus%@AE@%,  %@AB@%_remapallpalette%@AE@%,  %@AB@%_remappalette%@AE@%,
  18962. %@AB@%_selectpalette%@AE@%, %@AB@% _setpixel%@AE@% functions,  %@AB@%_setvideomode%@AE@%  %@NL@%
  18963. %@NL@%
  18964. %@NL@%
  18965. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  18966. %@NL@%
  18967. %@AS@%  /* GPIXEL.C: This program assigns different colors to randomly
  18968. %@AS@%   * selected pixels.
  18969. %@AS@%   */
  18970. %@AS@%  
  18971. %@AS@%  #include <conio.h>
  18972. %@AS@%  #include <stdlib.h>
  18973. %@AS@%  #include <graph.h>
  18974. %@AS@%  
  18975. %@AS@%  void main()
  18976. %@AS@%  {
  18977. %@AS@%     short xvar, yvar;
  18978. %@AS@%     struct videoconfig vc;
  18979. %@AS@%  %@AE@%%@NL@%
  18980. %@NL@%
  18981. %@AS@%  /* Find a valid graphics mode. */
  18982. %@AS@%     if( !_setvideomode( _MAXCOLORMODE ) )
  18983. %@AS@%        exit( 1 );
  18984. %@AS@%     _getvideoconfig( &vc );
  18985. %@AS@%  
  18986. %@AS@%     /* Draw filled ellipse to turn on certain pixels. */
  18987. %@AS@%     _ellipse( _GFILLINTERIOR, vc.numxpixels / 6, vc.numypixels / 6,
  18988. %@AS@%                               vc.numxpixels / 6 * 5, vc.numypixels / 6 * 5
  18989. %@AS@%                                             );
  18990. %@AS@%  
  18991. %@AS@%     /* Draw random pixels in random colors... */
  18992. %@AS@%     while( !kbhit() )
  18993. %@AS@%     {
  18994. %@AS@%        /* ...but only if they are already on (inside the ellipse). */
  18995. %@AS@%        xvar = rand() % vc.numxpixels;
  18996. %@AS@%        yvar = rand() % vc.numypixels;
  18997. %@AS@%        if( _getpixel( xvar, yvar ) != 0 )
  18998. %@AS@%        {
  18999. %@AS@%           _setcolor( rand() % 16 );
  19000. %@AS@%           _setpixel( xvar, yvar );
  19001. %@AS@%        }
  19002. %@AS@%     }
  19003. %@AS@%  
  19004. %@AS@%     getch();          /* Throw away the keystroke. */
  19005. %@AS@%     _setvideomode( _DEFAULTMODE );
  19006. %@AS@%  } %@AE@%%@NL@%
  19007. %@NL@%
  19008. %@NL@%
  19009. %@NL@%
  19010. %@NL@%
  19011. %@QR:gets@%%@NL@%
  19012. %@2@%%@CR:C6A01480742 @%%@AB@%gets%@AE@%%@EH@%%@NL@%
  19013. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19014. %@NL@%
  19015. %@NL@%
  19016. %@3@%%@AB@%Description%@CR:C6A01480743 @%%@CR:C6A01480744 @% %@CR:C6A01480745 @%%@CR:C6A01480746 @%%@CR:C6A01480747 @%%@AE@%%@EH@%%@NL@%
  19017. %@NL@%
  19018. Gets a line from the %@AB@%stdin %@AE@%stream.  %@NL@%
  19019. %@NL@%
  19020. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  19021. %@NL@%
  19022. %@AS@%  char *gets( char *buffer );%@AE@%%@NL@%
  19023. %@NL@%
  19024. %@AI@%buffer%@AE@%                            Storage location for input string
  19025.  
  19026. %@NL@%
  19027. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19028. %@NL@%
  19029. The %@AB@%gets%@AE@% function reads a line from the standard input stream %@AB@%stdin%@AE@% and
  19030. stores it in %@AI@%buffer%@AE@%. The line consists of all characters up to and including
  19031. the first newline character (%@AB@%\n%@AE@%). The %@AB@%gets%@AE@% function then replaces the
  19032. newline character with a null character (%@AB@%'\0'%@AE@%) before returning the line. In
  19033. contrast, the %@AB@%fgets%@AE@% function retains the newline character.  %@NL@%
  19034. %@NL@%
  19035. %@NL@%
  19036. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19037. %@NL@%
  19038. If successful, the %@AB@%gets%@AE@% function returns its argument. A %@AB@%NULL%@AE@% pointer
  19039. indicates an error or end-of-file condition. Use %@AB@%ferror%@AE@% or %@AB@%feof%@AE@% to determine
  19040. which one has occurred.  %@NL@%
  19041. %@NL@%
  19042. %@NL@%
  19043. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19044. %@NL@%
  19045. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  19046. %@NL@%
  19047. %@NL@%
  19048. %@NL@%
  19049. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19050. %@NL@%
  19051. %@AB@%fgets%@AE@%, %@AB@%fputs%@AE@%, %@AB@%puts%@AE@%  %@NL@%
  19052. %@NL@%
  19053. %@NL@%
  19054. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19055. %@NL@%
  19056. %@AS@%  /* GETS.C */
  19057. %@AS@%  
  19058. %@AS@%  #include <stdio.h>
  19059. %@AS@%  
  19060. %@AS@%  void main()
  19061. %@AS@%  {
  19062. %@AS@%     char line[81];
  19063. %@AS@%  
  19064. %@AS@%     printf( "Input a string: " );
  19065. %@AS@%     gets( line );
  19066. %@AS@%     printf( "The line entered was: %s\n", line );
  19067. %@AS@%  }%@AE@%%@NL@%
  19068. %@NL@%
  19069. %@NL@%
  19070. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  19071. %@NL@%
  19072. %@AS@%  
  19073. %@AS@%  
  19074. %@AS@%  Input a string: This is a string
  19075. %@AS@%  The line entered was: This is a string %@AE@%%@NL@%
  19076. %@NL@%
  19077. %@NL@%
  19078. %@NL@%
  19079. %@NL@%
  19080. %@QR:_gettextcolor@%%@NL@%
  19081. %@2@%%@CR:C6A01490748 @%%@AB@%_gettextcolor%@AE@%%@EH@%%@NL@%
  19082. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19083. %@NL@%
  19084. %@NL@%
  19085. %@3@%%@AB@%Description%@CR:C6A01490749 @%%@AE@%%@EH@%%@NL@%
  19086. %@NL@%
  19087. Gets the current text color.  %@NL@%
  19088. %@NL@%
  19089. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19090. %@NL@%
  19091. %@AS@%  short _far _gettextcolor( void );%@AE@%%@NL@%
  19092. %@NL@%
  19093. %@NL@%
  19094. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19095. %@NL@%
  19096. The %@AB@%_gettextcolor%@AE@% function returns the color index of the current text
  19097. color. The text color is set by the %@AB@%_settextcolor%@AE@% function and affects text
  19098. output with the %@AB@%_outtext%@AE@% and %@AB@%_outmem%@AE@% functions only. The %@AB@%_setcolor%@AE@% function
  19099. sets the color for font text output using the %@AB@% _outgtext%@AE@% function.  %@NL@%
  19100. %@NL@%
  19101. The default is 7 in test modes; it is the highest legal color index of the
  19102. current palette in graphics modes.  %@NL@%
  19103. %@NL@%
  19104. %@NL@%
  19105. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19106. %@NL@%
  19107. The %@AB@%_gettextcolor%@AE@% function returns the color index of the current text
  19108. color.  %@NL@%
  19109. %@NL@%
  19110. %@NL@%
  19111. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19112. %@NL@%
  19113.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  19114. %@NL@%
  19115. %@NL@%
  19116. %@NL@%
  19117. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19118. %@NL@%
  19119. %@AB@%_getvideoconfig%@AE@%,  %@AB@%_remappalette%@AE@%,  %@AB@%_selectpalette%@AE@%,  %@AB@%_setcolor%@AE@%,  %@AB@%_settextcolor%@AE@%
  19120. %@NL@%
  19121. %@NL@%
  19122. %@NL@%
  19123. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19124. %@NL@%
  19125. See the example for %@AB@%_gettextposition%@AE@%.  %@NL@%
  19126. %@NL@%
  19127. %@NL@%
  19128. %@NL@%
  19129. %@NL@%
  19130. %@QR:_gettextcursor@%%@NL@%
  19131. %@2@%%@CR:C6A01500750 @%%@AB@%_gettextcursor%@AE@%%@EH@%%@NL@%
  19132. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19133. %@NL@%
  19134. %@NL@%
  19135. %@3@%%@AB@%Description%@CR:C6A01500751 @%%@AE@%%@EH@%%@NL@%
  19136. %@NL@%
  19137. Gets the current cursor attribute.  %@NL@%
  19138. %@NL@%
  19139. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19140. %@NL@%
  19141. %@AS@%  short _far _gettextcursor( void );%@AE@%%@NL@%
  19142. %@NL@%
  19143. %@NL@%
  19144. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19145. %@NL@%
  19146. The %@AB@%_gettextcursor%@AE@% function returns the current cursor attribute (i.e., the
  19147. shape). This function works only in text video modes.  %@NL@%
  19148. %@NL@%
  19149. %@NL@%
  19150. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19151. %@NL@%
  19152. The function returns the current cursor attribute, or -1 if an error occurs
  19153. (such as a call to the function in a graphics mode).  %@NL@%
  19154. %@NL@%
  19155. %@NL@%
  19156. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19157. %@NL@%
  19158.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  19159. %@NL@%
  19160. %@NL@%
  19161. %@NL@%
  19162. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19163. %@NL@%
  19164. %@AB@%_displaycursor%@AE@%,  %@AB@%_grstatus%@AE@%,  %@AB@%_settextcursor%@AE@%  %@NL@%
  19165. %@NL@%
  19166. %@NL@%
  19167. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19168. %@NL@%
  19169. See the example for %@AB@%_settextcursor%@AE@%.  %@NL@%
  19170. %@NL@%
  19171. %@NL@%
  19172. %@NL@%
  19173. %@NL@%
  19174. %@QR:_gettextposition@%%@NL@%
  19175. %@2@%%@CR:C6A01510752 @%%@AB@%_gettextposition%@AE@%%@EH@%%@NL@%
  19176. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19177. %@NL@%
  19178. %@NL@%
  19179. %@3@%%@AB@%Description%@CR:C6A01510753 @%%@AE@%%@EH@%%@NL@%
  19180. %@NL@%
  19181. Gets the current text position.  %@NL@%
  19182. %@NL@%
  19183. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19184. %@NL@%
  19185. %@AS@%  struct rccoord _far _gettextposition( void );%@AE@%%@NL@%
  19186. %@NL@%
  19187. %@NL@%
  19188. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19189. %@NL@%
  19190. The %@AB@%_gettextposition%@AE@% function returns the current text position as an
  19191. %@AB@%rccoord%@AE@% structure, defined in GRAPH.H.  %@NL@%
  19192. %@NL@%
  19193. The %@AB@%rccoord%@AE@% structure contains the following elements:  %@NL@%
  19194. %@NL@%
  19195. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  19196. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19197. %@AB@%short row%@AE@%                         Row coordinate
  19198.  
  19199. %@AB@%short col%@AE@%                         Column coordinate
  19200.  
  19201. %@NL@%
  19202. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19203. %@NL@%
  19204. The text position given by the coordinates (1,1) is defined as the
  19205. upper-left corner of the text window.  %@NL@%
  19206. %@NL@%
  19207. Text output from the %@AB@%_outtext%@AE@% and %@AB@%_outmem%@AE@% functions begins at the current
  19208. text position. Font text is not affected by the current text position. Font
  19209. text output begins at the current graphics output position, which is a
  19210. separate position.  %@NL@%
  19211. %@NL@%
  19212. %@NL@%
  19213. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19214. %@NL@%
  19215. None.  %@NL@%
  19216. %@NL@%
  19217. %@NL@%
  19218. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19219. %@NL@%
  19220.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  19221. %@NL@%
  19222. %@NL@%
  19223. %@NL@%
  19224. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19225. %@NL@%
  19226. %@AB@%_getcurrentposition%@AE@% functions,  %@AB@%_moveto%@AE@% functions,  %@AB@%_outmem%@AE@%,%@AB@%  _outtext%@AE@%,
  19227. %@AB@%_settextposition%@AE@%,  %@AB@%_settextwindow%@AE@%,  %@AB@%_wrapon%@AE@%  %@NL@%
  19228. %@NL@%
  19229. %@NL@%
  19230. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19231. %@NL@%
  19232. %@AS@%  /* OUTTXT.C: This example illustrates text output functions:
  19233. %@AS@%   *    _gettextcolor   _getbkcolor   _gettextposition   _outtext
  19234. %@AS@%   *    _settextcolor   _setbkcolor   _settextposition
  19235. %@AS@%   */
  19236. %@AS@%  
  19237. %@AS@%  #include <conio.h>
  19238. %@AS@%  #include <stdio.h>
  19239. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19240. %@NL@%
  19241. %@AS@%  char buffer [80];
  19242. %@AS@%  
  19243. %@AS@%  void main()
  19244. %@AS@%  {
  19245. %@AS@%  
  19246. %@AS@%     /* Save original foreground, background, and text position. */
  19247. %@AS@%     short blink, fgd, oldfgd;
  19248. %@AS@%     long  bgd, oldbgd;
  19249. %@AS@%     struct rccoord oldpos;
  19250. %@AS@%  
  19251. %@AS@%     /* Save original foreground, background, and text position. */
  19252. %@AS@%     oldfgd = _gettextcolor();
  19253. %@AS@%     oldbgd = _getbkcolor();
  19254. %@AS@%     oldpos = _gettextposition();
  19255. %@AS@%     _clearscreen( _GCLEARSCREEN );
  19256. %@AS@%  
  19257. %@AS@%     /* First time no blink, second time blinking. */
  19258. %@AS@%     for( blink = 0; blink <= 16; blink += 16 )
  19259. %@AS@%     {
  19260. %@AS@%        /* Loop through 8 background colors. */
  19261. %@AS@%        for( bgd = 0; bgd < 8; bgd++ )
  19262. %@AS@%        {
  19263. %@AS@%           _setbkcolor( bgd );
  19264. %@AS@%           _settextposition( (short)bgd + ((blink / 16) * 9) + 3, 1 );
  19265. %@AS@%           _settextcolor( 7 );
  19266. %@AS@%           sprintf(buffer, "Back: %d Fore:", bgd );
  19267. %@AS@%           _outtext( buffer );
  19268. %@AS@%  
  19269. %@AS@%           /* Loop through 16 foreground colors. */
  19270. %@AS@%           for( fgd = 0; fgd < 16; fgd++ )
  19271. %@AS@%           {
  19272. %@AS@%              _settextcolor( fgd + blink );
  19273. %@AS@%              sprintf( buffer, " %2d ", fgd + blink );
  19274. %@AS@%              _outtext( buffer );
  19275. %@AS@%           }
  19276. %@AS@%        }
  19277. %@AS@%     }
  19278. %@AS@%     getch();
  19279. %@AS@%  
  19280. %@AS@%     /* Restore original foreground, background, and text position. */
  19281. %@AS@%     _settextcolor( oldfgd );
  19282. %@AS@%     _setbkcolor( oldbgd );
  19283. %@AS@%     _clearscreen( _GCLEARSCREEN );
  19284. %@AS@%     _settextposition( oldpos.row, oldpos.col );
  19285. %@AS@%  }%@AE@%%@NL@%
  19286. %@NL@%
  19287. %@NL@%
  19288. %@NL@%
  19289. %@NL@%
  19290. %@QR:_gettextwindow@%%@NL@%
  19291. %@2@%%@CR:C6A01520754 @%%@AB@%_gettextwindow%@AE@%%@EH@%%@NL@%
  19292. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19293. %@NL@%
  19294. %@NL@%
  19295. %@3@%%@AB@%Description%@CR:C6A01520755 @% %@CR:C6A01520756 @%%@AE@%%@EH@%%@NL@%
  19296. %@NL@%
  19297. Gets the boundaries of the current text window.  %@NL@%
  19298. %@NL@%
  19299. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19300. %@NL@%
  19301. %@AS@%  void _far _gettextwindow( short _far *r1, short _far *c1, short _far *r2, 
  19302. %@AS@%  short _far *c2 );%@AE@%%@NL@%
  19303. %@NL@%
  19304. %@AI@%r1%@AE@%                                Top row of current text window
  19305.  
  19306. %@AI@%c1%@AE@%                                Leftmost column of current text window
  19307.  
  19308. %@AI@%r2%@AE@%                                Bottom row of current text window
  19309.  
  19310. %@AI@%c2%@AE@%                                Rightmost column of current text window
  19311.  
  19312. %@NL@%
  19313. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19314. %@NL@%
  19315. The %@AB@%_gettextwindow%@AE@% function finds the boundaries of the current text window.
  19316. The text window is the region of the screen to which output from the
  19317. %@AB@%_outtext%@AE@% and %@AB@%_outmem%@AE@% functions is limited. By default, this is the entire
  19318. screen, unless it has been redefined by the %@AB@%_settextwindow%@AE@% function.  %@NL@%
  19319. %@NL@%
  19320. The window defined by %@AB@%_settextwindow %@AE@%has no effect on output from the%@AB@%
  19321. %@AB@%_outgtext%@AE@% function. Text displayed with %@AB@%_outgtext%@AE@% is limited to the current
  19322. viewport.  %@NL@%
  19323. %@NL@%
  19324. %@NL@%
  19325. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19326. %@NL@%
  19327. None.  %@NL@%
  19328. %@NL@%
  19329. %@NL@%
  19330. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19331. %@NL@%
  19332.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  19333. %@NL@%
  19334. %@NL@%
  19335. %@NL@%
  19336. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19337. %@NL@%
  19338. %@AB@%_gettextposition%@AE@%,  %@AB@%_outmem%@AE@%,  %@AB@%_outtext%@AE@%,  %@AB@%_scrolltextwindow%@AE@%,
  19339. %@AB@%_settextposition%@AE@%, %@AB@%_settextwindow%@AE@%,  %@AB@%_wrapon%@AE@%  %@NL@%
  19340. %@NL@%
  19341. %@NL@%
  19342. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19343. %@NL@%
  19344. See the example for %@AB@%_scrolltextwindow%@AE@%.  %@NL@%
  19345. %@NL@%
  19346. %@NL@%
  19347. %@NL@%
  19348. %@NL@%
  19349. %@QR:_getvideoconfig@%%@NL@%
  19350. %@2@%%@CR:C6A01530757 @%%@AB@%_getvideoconfig%@AE@%%@EH@%%@NL@%
  19351. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19352. %@NL@%
  19353. %@NL@%
  19354. %@3@%%@AB@%Description%@CR:C6A01530758 @%%@AE@%%@EH@%%@NL@%
  19355. %@NL@%
  19356. Gets graphics video configuration information.  %@NL@%
  19357. %@NL@%
  19358. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19359. %@NL@%
  19360. %@AS@%  struct videoconfig _far * _far _getvideoconfig( struct videoconfig _far
  19361. %@AS@%  *config );%@AE@%%@NL@%
  19362. %@NL@%
  19363. %@AI@%config%@AE@%                            Configuration information
  19364.  
  19365. %@NL@%
  19366. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19367. %@NL@%
  19368. The %@AB@%_getvideoconfig%@AE@% function returns the current graphics environment
  19369. configuration in a %@AB@%videoconfig%@AE@% structure, defined in GRAPH.H.  %@NL@%
  19370. %@NL@%
  19371. The values returned reflect the currently active video adapter and monitor,
  19372. as well as the current video mode.  %@NL@%
  19373. %@NL@%
  19374. The %@AB@%videoconfig%@AE@% structure contains the following members, each of which is
  19375. of type %@AB@%short%@AE@%:  %@NL@%
  19376. %@NL@%
  19377. %@AB@%Member%@AE@%                            %@AB@%Contents%@AE@%
  19378. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19379. %@AB@%adapter%@AE@%                           Active display adapter
  19380.  
  19381. %@AB@%bitsperpixel%@AE@%                      Number of bits per pixel
  19382.  
  19383. %@AB@%memory%@AE@%                            Adapter video memory in kilobytes
  19384.  
  19385. %@AB@%mode%@AE@%                              Current video mode
  19386.  
  19387. %@AB@%monitor%@AE@%                           Active display monitor
  19388.  
  19389. %@AB@%numcolors%@AE@%                         Number of color indices
  19390.  
  19391. %@AB@%numtextcols%@AE@%                       Number of text columns available
  19392.  
  19393. %@AB@%numtextrows%@AE@%                       Number of text rows available
  19394.  
  19395. %@AB@%numvideopages%@AE@%                     Number of available video pages
  19396.  
  19397. %@AB@%numxpixels%@AE@%                        Number of pixels on the %@AI@%x%@AE@% axis
  19398.  
  19399. %@AB@%numypixels%@AE@%                        Number of pixels on the %@AI@%y%@AE@% axis
  19400.  
  19401. %@AB@%  %@AE@%%@NL@%
  19402. %@NL@%
  19403. The values for the %@AB@%adapter%@AE@% member of the %@AB@%videoconfig%@AE@% structure are given by
  19404. the manifest constants shown in the list below. For any applicable adapter (
  19405. %@AB@%_CGA%@AE@%, %@AB@%_EGA%@AE@%, or %@AB@%_VGA%@AE@%), the corresponding Olivetti(R) adapter ( %@AB@%_OCGA%@AE@%, %@AB@%_OEGA%@AE@%,
  19406. or %@AB@%_OVGA%@AE@%) represents a superset of graphics capabilities.  %@NL@%
  19407. %@NL@%
  19408. %@AB@%Adapter Constant%@AE@%                  %@AB@%Meaning%@AE@%
  19409. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19410. %@AB@%_CGA%@AE@%                              Color Graphics Adapter
  19411.  
  19412. %@AB@%_EGA%@AE@%                              Enhanced Graphics Adapter
  19413.  
  19414. %@AB@%_HGC%@AE@%                              Hercules(R) Graphics Card
  19415.  
  19416. %@AB@%_MCGA%@AE@%                             Multicolor Graphics Array
  19417.  
  19418. %@AB@%_MDPA%@AE@%                             Monochrome Display Printer Adapter
  19419.  
  19420. %@AB@%_OCGA%@AE@%                             Olivetti (AT&T(R)) Color Graphics 
  19421.                                   Adapter
  19422.  
  19423. %@AB@%_OEGA%@AE@%                             Olivetti (AT&T) Enhanced Graphics 
  19424.                                   Adapter
  19425.  
  19426. %@AB@%_OVGA%@AE@%                             Olivetti (AT&T) Video Graphics Array
  19427.  
  19428. %@AB@%_VGA%@AE@%                              Video Graphics Array
  19429.  
  19430. The values for the %@AB@%monitor%@AE@% member of the %@AB@%videoconfig%@AE@% structure are given by
  19431. the manifest constants listed below:  %@NL@%
  19432. %@NL@%
  19433. %@AB@%Monitor Constant%@AE@%                  %@AB@%Meaning%@AE@%
  19434. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19435. %@AB@%_ANALOG%@AE@%                           Analog monochrome and color
  19436.  
  19437. %@AB@%_ANALOGCOLOR%@AE@%                      Analog color only
  19438.  
  19439. %@AB@%_ANALOGMONO%@AE@%                       Analog monochrome only
  19440.  
  19441. %@AB@%_COLOR%@AE@%                            Color (or enhanced monitor emulating a 
  19442.                                   color monitor)
  19443.  
  19444. %@AB@%_ENHCOLOR%@AE@%                         Enhanced color
  19445.  
  19446. %@AB@%_MONO%@AE@%                             Monochrome monitor
  19447.  
  19448. In every text mode, including monochrome, the %@AB@%_getvideoconfig%@AE@% function
  19449. returns the value 32 for the number of available colors. The value 32
  19450. indicates the range of values (0 -31) accepted by the %@AB@%_settextcolor%@AE@%
  19451. function. This includes 16 normal colors (0 -15) and 16 blinking colors (16
  19452. -31). Blinking is selected by adding 16 to the normal color index. Because
  19453. monochrome text mode has fewer unique display attributes, some color indices
  19454. are redundant. However, because blinking is selected in the same manner,
  19455. monochrome text mode has the same range (0 -31) as other text modes.  %@NL@%
  19456. %@NL@%
  19457. %@NL@%
  19458. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19459. %@NL@%
  19460. The %@AB@%_getvideoconfig%@AE@% function returns the video configuration information in
  19461. a structure, as noted above. There is no error return.  %@NL@%
  19462. %@NL@%
  19463. %@NL@%
  19464. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19465. %@NL@%
  19466.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  19467. %@NL@%
  19468. %@NL@%
  19469. %@NL@%
  19470. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19471. %@NL@%
  19472. %@AB@%_setvideomode%@AE@%,  %@AB@%_setvideomoderows%@AE@%  %@NL@%
  19473. %@NL@%
  19474. %@NL@%
  19475. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19476. %@NL@%
  19477. %@AS@%  /* GVIDCFG.C: This program displays information about the current
  19478. %@AS@%   * video configuration.
  19479. %@AS@%   */
  19480. %@AS@%  
  19481. %@AS@%  #include <stdio.h>
  19482. %@AS@%  #include <graph.h>
  19483. %@AS@%  
  19484. %@AS@%  void main()
  19485. %@AS@%  {
  19486. %@AS@%     struct videoconfig vc;
  19487. %@AS@%     short  c;
  19488. %@AS@%     char   b[500];                        /* Buffer for string */
  19489. %@AS@%  
  19490. %@AS@%     _getvideoconfig( &vc );
  19491. %@AS@%  
  19492. %@AS@%     /* Write all information to a string, then output string. */
  19493. %@AS@%     c  = sprintf( b,     "X pixels:     %d\n", vc.numxpixels );
  19494. %@AS@%     c += sprintf( b + c, "Y pixels:     %d\n", vc.numypixels );
  19495. %@AS@%     c += sprintf( b + c, "Text columns: %d\n", vc.numtextcols );
  19496. %@AS@%     c += sprintf( b + c, "Text rows:    %d\n", vc.numtextrows );
  19497. %@AS@%     c += sprintf( b + c, "Colors:       %d\n", vc.numcolors );
  19498. %@AS@%     c += sprintf( b + c, "Bits/pixel:   %d\n", vc.bitsperpixel );
  19499. %@AS@%     c += sprintf( b + c, "Video pages:  %d\n", vc.numvideopages );
  19500. %@AS@%     c += sprintf( b + c, "Mode:         %d\n", vc.mode );
  19501. %@AS@%     c += sprintf( b + c, "Adapter:      %d\n", vc.adapter );
  19502. %@AS@%     c += sprintf( b + c, "Monitor:      %d\n", vc.monitor );
  19503. %@AS@%     c += sprintf( b + c, "Memory:       %d\n", vc.memory );
  19504. %@AS@%     _outtext( b );
  19505. %@AS@%  }%@AE@%%@NL@%
  19506. %@NL@%
  19507. %@NL@%
  19508. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  19509. %@NL@%
  19510. %@AS@%  
  19511. %@AS@%  
  19512. %@AS@%  X pixels:     0
  19513. %@AS@%  Y pixels:     0
  19514. %@AS@%  Text columns: 80
  19515. %@AS@%  Text rows:    25
  19516. %@AS@%  Colors:       32
  19517. %@AS@%  Bits/pixel:   0
  19518. %@AS@%  Video pages:  1
  19519. %@AS@%  Mode:         3
  19520. %@AS@%  Adapter:      8
  19521. %@AS@%  Monitor:      24
  19522. %@AS@%  Memory:       256%@AE@%%@NL@%
  19523. %@NL@%
  19524. %@NL@%
  19525. %@NL@%
  19526. %@NL@%
  19527. %@QR:_getviewcoord@%%@NL@%
  19528. %@2@%%@CR:C6A01540759 @%%@AB@%_getviewcoord Functions%@AE@%%@EH@%%@NL@%
  19529. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19530. %@NL@%
  19531. %@NL@%
  19532. %@3@%%@AB@%Description %@CR:C6A01540760 @%%@AE@%%@EH@%%@NL@%
  19533. %@NL@%
  19534. Translate coordinates to view coordinates.  %@NL@%
  19535. %@NL@%
  19536. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19537. %@NL@%
  19538. %@AS@%  struct xycoord _far _getviewcoord( short x, short y );%@AE@%%@NL@%
  19539. %@NL@%
  19540. %@AS@%  struct xycoord _far _getviewcoord_w( double wx, double wy );%@AE@%%@NL@%
  19541. %@NL@%
  19542. %@AS@%  struct xycoord _far _getviewcoord_wxy( struct _wxycoord _far *pwxy1 );%@AE@%%@NL@%
  19543. %@NL@%
  19544. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Physical point to translate
  19545.  
  19546. %@AI@%wx%@AE@%, %@AI@%wy%@AE@%                            Window point to translate
  19547.  
  19548. %@AI@%pwxy1%@AE@%                             Window point to translate
  19549.  
  19550. %@NL@%
  19551. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19552. %@NL@%
  19553. The %@AB@%_getviewcoord%@AE@% routines translate the specified coordinates (%@AI@%x%@AE@%, %@AI@%y%@AE@%) from
  19554. one coordinate system to view coordinates and then return them in an %@AB@%xycoord%@AE@%
  19555. structure, defined in GRAPH.H. The %@AB@%xycoord %@AE@%structure contains the following
  19556. elements:  %@NL@%
  19557. %@NL@%
  19558. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  19559. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19560. %@AB@%short xcoord%@AE@%                      %@AI@%x%@AE@% coordinate
  19561.  
  19562. %@AB@%short ycoord%@AE@%                      %@AI@%y%@AE@% coordinate
  19563.  
  19564. The various %@AB@%_getviewcoord%@AE@% routines translate in the following manner:  %@NL@%
  19565. %@NL@%
  19566. %@AB@%Routine%@AE@%                           %@AB@%Translation%@AE@%
  19567. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19568. %@AB@%_getviewcoord%@AE@%                     Physical coordinates (%@AI@%x%@AE@%, %@AI@%y%@AE@%) to view 
  19569.                                   coordinates
  19570.  
  19571. %@AB@%_getviewcoord_w%@AE@%                   Window coordinates (%@AI@%wx%@AE@%, %@AI@%wy%@AE@%) to view 
  19572.                                   coordinates
  19573.  
  19574. %@AB@%_getviewcoord_wxy%@AE@%                 Window coordinates structure (%@AI@%pwxy1%@AE@%) to 
  19575.                                   view coordinates
  19576.  
  19577. ────────────────────────────────────────────────────────────────────────────%@NL@%
  19578. C 5.1 Version Difference
  19579. %@AI@%%@AI@%In Microsoft C version 5.1, the function %@AE@%%@AI@%%@AB@%_getviewcoord%@AE@%%@AE@%%@AI@% was called %@AE@%%@AI@%%@AB@%
  19580. %@AB@%_getlogcoord%@AE@%%@AE@%%@AI@%.%@AE@%%@AE@%%@NL@%
  19581. ────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  19582. %@NL@%
  19583. %@NL@%
  19584. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19585. %@NL@%
  19586. The %@AB@%_getviewcoord%@AE@% function returns the coordinates as noted above. There is
  19587. no error  return.  %@NL@%
  19588. %@NL@%
  19589. %@NL@%
  19590. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19591. %@NL@%
  19592.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  19593. %@NL@%
  19594. %@NL@%
  19595. %@NL@%
  19596. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19597. %@NL@%
  19598. %@AB@%_getphyscoord%@AE@%,  %@AB@%_getwindowcoord,  _grstatus  %@AE@%%@NL@%
  19599. %@NL@%
  19600. %@NL@%
  19601. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19602. %@NL@%
  19603. See the example for %@AB@%_setwindow%@AE@%.%@AB@%  %@AE@%%@NL@%
  19604. %@NL@%
  19605. %@NL@%
  19606. %@NL@%
  19607. %@NL@%
  19608. %@QR:_getvisualpage@%%@NL@%
  19609. %@2@%%@CR:C6A01550761 @%%@AB@%_getvisualpage%@AE@%%@EH@%%@NL@%
  19610. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19611. %@NL@%
  19612. %@NL@%
  19613. %@3@%%@AB@%Description%@CR:C6A01550762 @%%@AE@%%@EH@%%@NL@%
  19614. %@NL@%
  19615. Gets the current visual page number.  %@NL@%
  19616. %@NL@%
  19617. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19618. %@NL@%
  19619. %@AS@%  short _far _getvisualpage( void );%@AE@%%@NL@%
  19620. %@NL@%
  19621. %@NL@%
  19622. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19623. %@NL@%
  19624. The %@AB@%_getvisualpage%@AE@% function returns the current visual page number.  %@NL@%
  19625. %@NL@%
  19626. %@NL@%
  19627. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19628. %@NL@%
  19629. The function returns the number of the current visual page. All hardware
  19630. combinations support at least one page (page number 0). In OS/2, only page 0
  19631. is available.  %@NL@%
  19632. %@NL@%
  19633. %@NL@%
  19634. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19635. %@NL@%
  19636.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  19637. %@NL@%
  19638. %@NL@%
  19639. %@NL@%
  19640. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19641. %@NL@%
  19642. %@AB@%_getactivepage%@AE@%,  %@AB@%_gettextcolor%@AE@%,  %@AB@%_gettextposition%@AE@%,  %@AB@%_outtext%@AE@%,
  19643. %@AB@%_setactivepage%@AE@%, %@AB@%_settextcolor%@AE@%,  %@AB@%_settextposition%@AE@%, %@AB@% _settextwindow%@AE@%,
  19644. %@AB@%_setvideomode%@AE@%, %@AB@%_setvisualpage%@AE@%,  %@AB@%_wrapon%@AE@%  %@NL@%
  19645. %@NL@%
  19646. %@NL@%
  19647. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19648. %@NL@%
  19649. See the example for %@AB@%_getactivepage%@AE@%.  %@NL@%
  19650. %@NL@%
  19651. %@NL@%
  19652. %@NL@%
  19653. %@NL@%
  19654. %@QR:getw@%%@NL@%
  19655. %@2@%%@CR:C6A01560763 @%%@AB@%getw%@AE@%%@EH@%%@NL@%
  19656. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19657. %@NL@%
  19658. %@NL@%
  19659. %@3@%%@AB@%Description%@CR:C6A01560764 @%%@CR:C6A01560765 @% %@CR:C6A01560766 @%%@CR:C6A01560767 @% %@CR:C6A01560768 @%%@AE@%%@EH@%%@NL@%
  19660. %@NL@%
  19661. Gets an integer from a stream.  %@NL@%
  19662. %@NL@%
  19663. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  19664. %@NL@%
  19665. %@AS@%  int getw( FILE *stream );%@AE@%%@NL@%
  19666. %@NL@%
  19667. %@AI@%stream%@AE@%                            Pointer to %@AB@%FILE structure%@AE@%
  19668.  
  19669. %@NL@%
  19670. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19671. %@NL@%
  19672. The %@AB@%getw%@AE@% function reads the next binary value of type %@AB@%int%@AE@% from the file
  19673. associated with %@AI@%stream%@AE@% and increments the associated file pointer (if there
  19674. is one) to point to the next unread character. The %@AB@%getw%@AE@% function does not
  19675. assume any special alignment of items in the stream.  %@NL@%
  19676. %@NL@%
  19677. %@NL@%
  19678. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19679. %@NL@%
  19680. The %@AB@%getw%@AE@% function returns the integer value read. A return value of %@AB@%EOF may
  19681. %@AB@%indicate an error or end-of-file. However, since the EOF valu%@AE@%e is also a
  19682. legitimate integer value, %@AB@%feof%@AE@% or %@AB@%ferror%@AE@% should be used to verify an
  19683. end-of-file or error condition.  %@NL@%
  19684. %@NL@%
  19685. %@NL@%
  19686. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19687. %@NL@%
  19688.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  19689. %@NL@%
  19690. %@NL@%
  19691. The %@AB@%getw%@AE@% function is provided primarily for compatibility with previous
  19692. libraries. Note that portability problems may occur with %@AB@%getw%@AE@%, since the
  19693. size of the %@AB@%int%@AE@% type and the ordering of bytes within the %@AB@%int%@AE@% type differ
  19694. across systems.  %@NL@%
  19695. %@NL@%
  19696. %@NL@%
  19697. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19698. %@NL@%
  19699. %@AB@%putw%@AE@%  %@NL@%
  19700. %@NL@%
  19701. %@NL@%
  19702. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19703. %@NL@%
  19704. %@AS@%  /* GETW.C: This program uses getw to read a word from a stream,
  19705. %@AS@%   * then performs an error check.
  19706. %@AS@%   */
  19707. %@AS@%  
  19708. %@AS@%  #include <stdio.h>
  19709. %@AS@%  #include <stdlib.h>
  19710. %@AS@%  
  19711. %@AS@%  void main()
  19712. %@AS@%  {
  19713. %@AS@%  
  19714. %@AS@%     FILE *stream;
  19715. %@AS@%     int i;
  19716. %@AS@%  %@AE@%%@NL@%
  19717. %@NL@%
  19718. %@AS@%  if( (stream = fopen( "getw.c", "rb" )) == NULL )
  19719. %@AS@%        printf( "Couldn't open file\n" );
  19720. %@AS@%     else
  19721. %@AS@%     {
  19722. %@AS@%        /* Read a word from the stream: */
  19723. %@AS@%        i = getw( stream );
  19724. %@AS@%  
  19725. %@AS@%        /* If there is an error... */
  19726. %@AS@%        if( ferror( stream ) )
  19727. %@AS@%        {
  19728. %@AS@%           printf( "getw failed\n" );
  19729. %@AS@%           clearerr( stream );
  19730. %@AS@%        }
  19731. %@AS@%        else
  19732. %@AS@%           printf( "First data word in file: 0x%.4x\n", i );
  19733. %@AS@%        fclose( stream );
  19734. %@AS@%     }
  19735. %@AS@%  }%@AE@%%@NL@%
  19736. %@NL@%
  19737. %@NL@%
  19738. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  19739. %@NL@%
  19740. %@AS@%  
  19741. %@AS@%  
  19742. %@AS@%  First data word in file: 0x2a2f %@AE@%%@NL@%
  19743. %@NL@%
  19744. %@NL@%
  19745. %@NL@%
  19746. %@NL@%
  19747. %@QR:_getwindowcoord@%%@NL@%
  19748. %@2@%%@CR:C6A01570769 @%%@AB@%_getwindowcoord%@AE@%%@EH@%%@NL@%
  19749. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19750. %@NL@%
  19751. %@NL@%
  19752. %@3@%%@AB@%Description%@CR:C6A01570770 @%%@AE@%%@EH@%%@NL@%
  19753. %@NL@%
  19754. Translates view coordinates to window coordinates.  %@NL@%
  19755. %@NL@%
  19756. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  19757. %@NL@%
  19758. %@AS@%  struct _wxycoord _far _getwindowcoord( short x, short y );%@AE@%%@NL@%
  19759. %@NL@%
  19760. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Physical point to translate
  19761.  
  19762. %@NL@%
  19763. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19764. %@NL@%
  19765. The %@AB@%_getwindowcoord%@AE@% function translates the view coordinates (%@AI@%x%@AE@%, %@AI@%y%@AE@%) to
  19766. window coordinates and returns them in the %@AB@%_wxycoord%@AE@% structure, defined in
  19767. GRAPH.H.  %@NL@%
  19768. %@NL@%
  19769. The %@AB@%_wxycoord %@AE@%structure contains the following elements:  %@NL@%
  19770. %@NL@%
  19771. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  19772. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19773. %@AB@%double wx%@AE@%                         %@AI@%x%@AE@% coordinate
  19774.  
  19775. %@AB@%double wy%@AE@%                         %@AI@%y%@AE@% coordinate
  19776.  
  19777. %@NL@%
  19778. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19779. %@NL@%
  19780. The function returns the coordinates in the %@AB@%_wxycoord%@AE@% structure. There is no
  19781. error return.  %@NL@%
  19782. %@NL@%
  19783. %@NL@%
  19784. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19785. %@NL@%
  19786.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  19787. %@NL@%
  19788. %@NL@%
  19789. %@NL@%
  19790. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19791. %@NL@%
  19792. %@AB@%_getphyscoord%@AE@%,  %@AB@%_getviewcoord%@AE@% functions, %@AB@% _moveto%@AE@% functions,  %@AB@%_setwindow%@AE@%  %@NL@%
  19793. %@NL@%
  19794. %@NL@%
  19795. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19796. %@NL@%
  19797. See the example for %@AB@%_setwindow%@AE@%.  %@NL@%
  19798. %@NL@%
  19799. %@NL@%
  19800. %@NL@%
  19801. %@NL@%
  19802. %@QR:_getwritemode@%%@NL@%
  19803. %@2@%%@CR:C6A01580771 @%%@AB@%_getwritemode%@AE@%%@EH@%%@NL@%
  19804. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19805. %@NL@%
  19806. %@NL@%
  19807. %@3@%%@AB@%Description%@CR:C6A01580772 @% %@CR:C6A01580773 @%%@AE@%%@EH@%%@NL@%
  19808. %@NL@%
  19809. Gets the current logical mode for line drawing.  %@NL@%
  19810. %@NL@%
  19811. %@AS@%  #include  <graph.h>%@AE@%%@NL@%
  19812. %@NL@%
  19813. %@AS@%  short _far _getwritemode( void );%@AE@%%@NL@%
  19814. %@NL@%
  19815. %@NL@%
  19816. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19817. %@NL@%
  19818. The %@AB@%_getwritemode%@AE@% function returns the current logical write mode, which is
  19819. used when drawing lines with the %@AB@%_lineto%@AE@%,%@AB@% _polygon%@AE@%, and%@AB@% _rectangle%@AE@%
  19820. functions.  %@NL@%
  19821. %@NL@%
  19822. The default value is %@AB@%_GPSET%@AE@%, which causes lines to be drawn in the current
  19823. graphics color. The other possible return values are %@AB@%_GXOR%@AE@%, %@AB@%_GAND%@AE@%, %@AB@%_GOR%@AE@%, and
  19824. %@AB@%_GPRESET%@AE@%. See %@AB@%_putimage%@AE@% for more details on these manifest constants.  %@NL@%
  19825. %@NL@%
  19826. %@NL@%
  19827. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19828. %@NL@%
  19829. The %@AB@%_getwritemode%@AE@% function returns the current logical write mode, or -1 if
  19830. not in graphics mode.  %@NL@%
  19831. %@NL@%
  19832. %@NL@%
  19833. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19834. %@NL@%
  19835.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  19836. %@NL@%
  19837. %@NL@%
  19838. %@NL@%
  19839. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19840. %@NL@%
  19841. %@AB@%_grstatus%@AE@%,  %@AB@%_lineto%@AE@% functions,  %@AB@%_putimage%@AE@% functions,  %@AB@%_rectangle%@AE@% functions,
  19842. %@AB@%_setcolor%@AE@%,  %@AB@%_setlinestyle%@AE@%,  %@AB@%_setwritemode%@AE@%  %@NL@%
  19843. %@NL@%
  19844. %@NL@%
  19845. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19846. %@NL@%
  19847. %@AS@%  /* GWRMODE.C: This program illustrates _getwritemode and _setwritemode. */
  19848. %@AS@%  
  19849. %@AS@%  #include <conio.h>
  19850. %@AS@%  #include <stdlib.h>
  19851. %@AS@%  #include <graph.h>
  19852. %@AS@%  
  19853. %@AS@%  short wmodes[5]  = { _GPSET,   _GPRESET, _GXOR,    _GOR,     _GAND    };
  19854. %@AS@%  char *wmstr[5]   = { "PSET  ", "PRESET", "XOR   ", "OR    ", "AND   " };
  19855. %@AS@%  
  19856. %@AS@%  void box( short x, short y, short size, short writemode, short fillmode );
  19857. %@AS@%  
  19858. %@AS@%  void main()
  19859. %@AS@%  {
  19860. %@AS@%     short i, x, y;
  19861. %@AS@%  %@AE@%%@NL@%
  19862. %@NL@%
  19863. %@AS@%  /* Find a valid graphics mode. */
  19864. %@AS@%     if( !_setvideomode( _MAXCOLORMODE ) )
  19865. %@AS@%        exit( 1 );
  19866. %@AS@%  
  19867. %@AS@%     x = y = 70;
  19868. %@AS@%     box( x, y, 50, _GPSET, _GFILLINTERIOR );
  19869. %@AS@%     _setcolor( 2 );
  19870. %@AS@%     box( x, y, 40, _GPSET, _GFILLINTERIOR );
  19871. %@AS@%     for( i = 0; i < 5; i++ )
  19872. %@AS@%     {
  19873. %@AS@%        _settextposition( 1, 1 );
  19874. %@AS@%        _outtext( wmstr[i] );
  19875. %@AS@%        box( x += 12, y += 12, 50, wmodes[i], _GBORDER );
  19876. %@AS@%        getch();
  19877. %@AS@%     }
  19878. %@AS@%     _setvideomode( _DEFAULTMODE );
  19879. %@AS@%  }
  19880. %@AS@%  
  19881. %@AS@%  void box( short x, short y, short size, short writemode, short fillmode )
  19882. %@AS@%  {
  19883. %@AS@%      short wm, side;
  19884. %@AS@%  
  19885. %@AS@%      wm = _getwritemode();           /* Save write mode and set new. */
  19886. %@AS@%      _setwritemode( writemode );
  19887. %@AS@%      _rectangle( fillmode, x - size, y - size, x + size, y + size );
  19888. %@AS@%      _setwritemode( wm );            /* Restore original write mode. */
  19889. %@AS@%  }%@AE@%%@NL@%
  19890. %@NL@%
  19891. %@NL@%
  19892. %@NL@%
  19893. %@NL@%
  19894. %@QR:gmtime@%%@NL@%
  19895. %@2@%%@CR:C6A01590774 @%%@AB@%gmtime%@AE@%%@EH@%%@NL@%
  19896. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19897. %@NL@%
  19898. %@NL@%
  19899. %@3@%%@AB@%Description%@CR:C6A01590775 @%%@CR:C6A01590776 @%%@CR:C6A01590777 @% %@CR:C6A01590778 @%%@CR:C6A01590779 @%%@AE@%%@EH@%%@NL@%
  19900. %@NL@%
  19901. Converts a time value to a structure.  %@NL@%
  19902. %@NL@%
  19903. %@AS@%  #include <time.h>%@AE@%%@NL@%
  19904. %@NL@%
  19905. %@AS@%  struct tm *gmtime( const time_t *timer );%@AE@%%@NL@%
  19906. %@NL@%
  19907. %@AI@%timer%@AE@%                             Pointer to stored time
  19908.  
  19909. %@NL@%
  19910. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  19911. %@NL@%
  19912. The %@AB@%gmtime%@AE@% function converts the %@AI@%timer%@AE@% value to a structure. The %@AI@%timer%@AE@%
  19913. argument represents the seconds elapsed since 00:00:00, January 1, 1970,
  19914. Greenwich mean time. This value is usually obtained from a call to the %@AB@%timer
  19915. %@AB@%%@AE@%function.%@AB@%  %@AE@%%@NL@%
  19916. %@NL@%
  19917. The %@AB@%gmtime%@AE@% function breaks down the %@AI@%timer%@AE@% value and stores it in a structure
  19918. of type %@AB@%tm%@AE@%, defined in TIME.H. (See %@AB@%asctime%@AE@% for a description of the
  19919. structure members.) The structure result reflects Greenwich mean time, not
  19920. local time.  %@NL@%
  19921. %@NL@%
  19922. The fields of the structure type %@AB@%tm%@AE@% store the following values, each of
  19923. which is an %@AB@%int%@AE@%:  %@NL@%
  19924. %@NL@%
  19925. %@AB@%Field%@AE@%                             %@AB@%Value Stored%@AE@%
  19926. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  19927. %@AB@%tm_sec%@AE@%                            Seconds
  19928.  
  19929. %@AB@%tm_min%@AE@%                            Minutes
  19930.  
  19931. %@AB@%tm_hour%@AE@%                           Hours (0-24)
  19932.  
  19933. %@AB@%tm_mday%@AE@%                           Day of month (1-31)
  19934.  
  19935. %@AB@%tm_mon%@AE@%                            Month (0-11; January = 0)
  19936.  
  19937. %@AB@%tm_year%@AE@%                           Year (current year minus 1900)
  19938.  
  19939. %@AB@%tm_wday%@AE@%                           Day of week (0-6; Sunday = 0)
  19940.  
  19941. %@AB@%tm_yday%@AE@%                           Day of year (0-365; January 1 = 0)
  19942.  
  19943. %@AB@%tm_isdst%@AE@%                          Always 0 for %@AB@%gmtime%@AE@%
  19944.  
  19945. The %@AB@%gmtime, mktime, %@AE@%and%@AB@% localtime%@AE@% functions use a single statically
  19946. allocated structure to hold the result. Each call to one of these routines
  19947. destroys the result of any previous call.  %@NL@%
  19948. %@NL@%
  19949. DOS and OS/2 do not accommodate dates prior to 1980. If %@AI@%timer%@AE@% represents a
  19950. date prior to 1980, %@AB@%gmtime%@AE@% returns %@AB@%NULL%@AE@%.    %@NL@%
  19951. %@NL@%
  19952. %@NL@%
  19953. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  19954. %@NL@%
  19955. The %@AB@%gmtime%@AE@% function returns a pointer to the structure result. There is no
  19956. error return.  %@NL@%
  19957. %@NL@%
  19958. %@NL@%
  19959. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  19960. %@NL@%
  19961. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  19962. %@NL@%
  19963. %@NL@%
  19964. %@NL@%
  19965. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  19966. %@NL@%
  19967. %@AB@%asctime%@AE@%, %@AB@%ctime%@AE@%, %@AB@%ftime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%time  %@AE@%%@NL@%
  19968. %@NL@%
  19969. %@NL@%
  19970. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  19971. %@NL@%
  19972. %@AS@%  /* GMTIME.C: This program uses gmtime to convert a long-integer
  19973. %@AS@%   * representation of Greenwich mean time to a structure named newtime,
  19974. %@AS@%   * then uses asctime to convert this structure to an output string.
  19975. %@AS@%   */
  19976. %@AS@%  
  19977. %@AS@%  #include <time.h>
  19978. %@AS@%  #include <stdio.h>
  19979. %@AS@%  
  19980. %@AS@%  void main()
  19981. %@AS@%  {
  19982. %@AS@%     struct tm *newtime;
  19983. %@AS@%     long ltime;
  19984. %@AS@%  
  19985. %@AS@%     time( <ime );
  19986. %@AS@%  
  19987. %@AS@%     /* Obtain Greenwich mean time: */
  19988. %@AS@%     newtime = gmtime( <ime );
  19989. %@AS@%     printf( "Greenwich mean time is %s\n", asctime( newtime ) );
  19990. %@AS@%  }%@AE@%%@NL@%
  19991. %@NL@%
  19992. %@NL@%
  19993. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  19994. %@NL@%
  19995. %@AS@%  
  19996. %@AS@%  
  19997. %@AS@%  Greenwich mean time is Fri Jun 16 16:37:53 1989 %@AE@%%@NL@%
  19998. %@NL@%
  19999. %@NL@%
  20000. %@NL@%
  20001. %@NL@%
  20002. %@QR:_grstatus@%%@NL@%
  20003. %@2@%%@CR:C6A01600780 @%%@AB@%_grstatus%@AE@%%@EH@%%@NL@%
  20004. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20005. %@NL@%
  20006. %@NL@%
  20007. %@3@%%@AB@%Description%@CR:C6A01600781 @% %@CR:C6A01600782 @%%@AE@%%@EH@%%@NL@%
  20008. %@NL@%
  20009. Returns the status of the most recent graphics function call.  %@NL@%
  20010. %@NL@%
  20011. %@AS@%  #include  <graph.h>%@AE@%%@NL@%
  20012. %@NL@%
  20013. %@AS@%  short _far _grstatus( void );%@AE@%%@NL@%
  20014. %@NL@%
  20015. %@NL@%
  20016. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20017. %@NL@%
  20018. The %@AB@%_grstatus%@AE@% function returns the status of the most recently used graphics
  20019. function. The %@AB@%_grstatus%@AE@% function can be used immediately following a call to
  20020. a graphics routine to determine if errors or warnings were generated. Return
  20021. values less than 0 are errors, and values greater than 0 are warnings.  %@NL@%
  20022. %@NL@%
  20023. The following manifest constants are defined in the GRAPH.H header file for
  20024. use with the %@AB@%_grstatus%@AE@% function:  %@NL@%
  20025. %@NL@%
  20026. %@TH:  34  1511 02 07 23 48 @%
  20027. %@AB@%Value%@AE@%  %@AB@%Constant%@AE@%               %@AB@%Meaning%@AE@%
  20028. %@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20029. 0      %@AB@%_GROK%@AE@%                  Success
  20030.  
  20031. -1     %@AB@%_GRERROR%@AE@%               Graphics error
  20032.  
  20033. -2     %@AB@%_GRMODENOTSUPPORTED%@AE@%    Requested video mode not supported
  20034.  
  20035. -3     %@AB@%_GRNOTINPROPERMODE%@AE@%     Requested routine only works in certain video 
  20036.                               modes
  20037.  
  20038. -4     %@AB@%_GRINVALIDPARAMETER%@AE@%    One or more parameters invalid
  20039.  
  20040. -5     %@AB@%_GRFONTFILENOTFOUND%@AE@%    No matching font file found
  20041.  
  20042. -6     %@AB@%_GRINVALIDFONTFILE%@AE@%     One or more font files invalid
  20043.  
  20044. -7     %@AB@%_GRCORRUPTEDFONTFILE%@AE@%   One or more font files inconsistent
  20045.  
  20046. -8     %@AB@%_GRINSUFFICIENTMEMORY%@AE@%  Not enough memory to allocate buffer or to 
  20047.                               complete a %@AB@%_floodfill%@AE@% operation
  20048.  
  20049. -9     %@AB@%_GRINVALIDIMAGEBUFFER%@AE@%  Image buffer data inconsistent
  20050.  
  20051. 1      %@AB@%_GRMOOUTPUT%@AE@%            No action taken
  20052.  
  20053. 2      %@AB@%_GRCLIPPED%@AE@%             Output was clipped to viewport
  20054.  
  20055. 3      %@AB@%_GRPARAMETERALTERED%@AE@%    One or more input parameters was altered to be
  20056.                               within range, or pairs of parameters were 
  20057.                               interchanged to be in the proper order
  20058.  
  20059. %@AB@%──────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20060.  
  20061. %@TE:  34  1511 02 07 23 48 @%
  20062.  
  20063. After a graphics call, use an %@AB@%if %@AE@%statement to compare the return value of
  20064. %@AB@%_grstatus%@AE@% to %@AB@%_GROK%@AE@%. For example:  %@NL@%
  20065. %@NL@%
  20066. %@AS@%  if( _grstatus < _GROK )
  20067. %@AS@%      /*handle graphics error*/ ;%@AE@%%@NL@%
  20068. %@NL@%
  20069. The functions listed below cannot cause errors, and they all set %@AB@%_grstatus%@AE@%
  20070. to %@AB@%GROK%@AE@%:  %@NL@%
  20071. %@NL@%
  20072. %@TH:   9   456 01 17 18 41 @%
  20073. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20074. %@AB@%_displaycursor%@AE@%   %@AB@%_gettextposition%@AE@%  %@AB@%_outmem%@AE@%
  20075.  
  20076. %@AB@%_getactivepage%@AE@%   %@AB@%_gettextwindow%@AE@%    %@AB@%_outtext%@AE@%
  20077.  
  20078. %@AB@%_getgtextvector%@AE@%  %@AB@%_getvideoconfig%@AE@%   %@AB@%_unregisterfonts%@AE@%
  20079.  
  20080. %@AB@%_gettextcolor%@AE@%    %@AB@%_getvisualpage%@AE@%    %@AB@%_wrapon%@AE@%
  20081.  
  20082. %@TE:   9   456 01 17 18 41 @%
  20083.  
  20084.  See the list below for the graphics functions that affect %@AB@%_grstatus%@AE@%. The
  20085. list shows error or warning messages that can be set by the graphics
  20086. function. In addition to the error codes listed, all of these functions can
  20087. produce the %@AB@%_GRERROR%@AE@% error code.  %@NL@%
  20088. %@NL@%
  20089. %@TH: 126  9075 03 36 83 33 @%
  20090. %@AB@%Function%@AE@%                            Possible _grstatus                                                                 %@AB@%Possible _grstatus%@AE@%
  20091. %@AB@%G%@AE@%                                   Error Codes                                                                        %@AB@%Warning Codes%@AE@%
  20092. %@AB@%────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20093. %@AB@%_arc%@AE@% functions                      %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRNOOUTPUT,%@AE@%
  20094.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%                                                                %@AB@%_GRCLIPPED%@AE@%
  20095.  
  20096. %@AB@%_clearscreen%@AE@%                        %@AB@%_GRNOTINPROPERMODE,%@AE@%
  20097.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%
  20098.  
  20099. %@AB@%_ellipse%@AE@% functions                  %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRNOOUTPUT,%@AE@%
  20100.                                     %@AB@%_GRINVALIDPARAMETER,%@AE@%                                                               %@AB@%_GRCLIPPED%@AE@%
  20101.                                     %@AB@%_GRINSUFFICIENTMEMORY%@AE@%                                                              
  20102.  
  20103. %@AB@%_getarcinfo %@AE@%                        %@AB@%_GRNOTINPROPERMODE%@AE@%
  20104.  
  20105. %@AB@%_getcurrentposition%@AE@%                 %@AB@%_GRNOTINPROPERMODE%@AE@%
  20106. functions                           
  20107.  
  20108. %@AB@%_getfontinfo%@AE@%                        (%@AB@% _GRERROR%@AE@% only)
  20109.  
  20110. %@AB@%_getgtextextent%@AE@%                     (%@AB@% _GRERROR%@AE@% only)
  20111.  
  20112. %@AB@%_getgtextvector%@AE@%                     %@AB@%_GRPARAMETERALTERED%@AE@%
  20113.  
  20114. %@AB@%_getimage%@AE@%                           %@AB@%_GRNOTINPROPERMODE%@AE@%                                                                 %@AB@%_GRPARAMETERALTERED%@AE@%
  20115.  
  20116. %@AB@%_getphyscoord%@AE@%                       %@AB@%_GRNOTINPROPERMODE%@AE@%
  20117.  
  20118. %@AB@%_getpixel%@AE@%                           %@AB@%_GRNOTINPROPERMODE%@AE@%
  20119.  
  20120. %@AB@%_gettextcursor%@AE@%                      %@AB@%_GRNOTINPROPERMODE%@AE@%
  20121.  
  20122. %@AB@%_getviewcoord %@AE@%functions             %@AB@%_GRNOTINPROPERMODE%@AE@%
  20123.  
  20124. %@AI@%Continued on next page%@AE@%              
  20125.  
  20126. %@AB@%_getwindowcoord %@AE@%                    %@AB@%_GRNOTINPROPERMODE%@AE@%
  20127.  
  20128. %@AB@%_getwritemode%@AE@%                       %@AB@%_GRNOTINPROPERMODE%@AE@%
  20129.  
  20130. %@AB@%_imagesize%@AE@% functions                %@AB@%_GRNOTINPROPERMODE%@AE@%
  20131.  
  20132. %@AB@%_lineto%@AE@% functions                   %@AB@%_GRNOTINPROPERMODE%@AE@%                                                                 %@AB@%_GRNOOUTPUT,%@AE@%
  20133.                                                                                                                        %@AB@%_GRCLIPPED%@AE@%
  20134.  
  20135. %@AB@%_moveto%@AE@% functions                   %@AB@%_GRNOTINPROPERMODE%@AE@%
  20136.  
  20137. %@AB@%_outgtex%@AE@%t                           %@AB@%_GRNOTINPROPERMODE%@AE@%                                                                 %@AB@%_GRCLIPPED,%@AE@%
  20138.                                                                                                                        %@AB@%_GRNOOUTPUT%@AE@%
  20139.  
  20140. %@AB@%_pie%@AE@% functions                      %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRNOOUTPUT,%@AE@%
  20141.                                     %@AB@%_GRINVALIDPARAMETER,%@AE@%                                                               %@AB@%_GRCLIPPED%@AE@%
  20142.                                     %@AB@%_GRINSUFFICIENTMEMORY%@AE@%                                                              
  20143.  
  20144. %@AB@%_polygon%@AE@% functions                  %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRNOOUTPUT,%@AE@%
  20145.                                     %@AB@%_GRINVALIDPARAMETER,%@AE@%                                                               %@AB@%_GRCLIPPED%@AE@%
  20146.                                     %@AB@%_GRINSUFFICIENTMEMORY%@AE@%                                                              
  20147.  
  20148. %@AB@%_putimage%@AE@% functions                 %@AB@%_GRERROR,%@AE@%                                                                          %@AB@%_GRPARAMETERALTERED,%@AE@%
  20149.                                     %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRNOOUTPUT%@AE@%
  20150.                                     %@AB@%_GRINVALIDPARAMETER,%@AE@%                                                               
  20151.                                     %@AB@%_GRINVALIDIMAGEBUFFER%@AE@%                                                              
  20152.  
  20153. %@AB@%_rectangle%@AE@% functions                %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRNOOUTPUT,%@AE@%
  20154.                                     %@AB@%_GRINVALIDPARAMETER,%@AE@%                                                               %@AB@%_GRCLIPPED%@AE@%
  20155.                                     %@AB@%_GRINSUFFICIENTMEMORY%@AE@%                                                              
  20156.  
  20157. %@AB@%_registerfonts%@AE@%                      %@AB@%_GRCORRUPTEDFONTFILE,%@AE@%
  20158.                                     %@AB@%_GRFONTFILENOTFOUND,%@AE@%
  20159.                                     %@AB@%_GRINSUFFICIENTMEMORY,%@AE@%
  20160.                                     %@AB@%_GRINVALIDFONTFILE%@AE@%
  20161.  
  20162. %@AB@%_scrolltextwindow%@AE@%                                                                                                      %@AB@%_GRNOOUTPUT%@AE@%
  20163.  
  20164. %@AB@%_selectpalette%@AE@%                      %@AB@%_GRNOTINPROPERMODE,%@AE@%
  20165.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%
  20166.  
  20167. %@AB@%_setactivepage%@AE@%                      %@AB@%_GRINVALIDPARAMETER%@AE@%
  20168.  
  20169. %@AB@%_setbkcolor%@AE@%                         %@AB@%_GRINVALIDPARAMETER%@AE@%                                                                %@AB@%_GRPARAMETERALTERED%@AE@%
  20170.  
  20171. %@AB@%_setcliprgn%@AE@%                         %@AB@%_GRNOTINPROPERMODE%@AE@%                                                                 %@AB@%_GRPARAMETERALTERED%@AE@%
  20172.  
  20173. %@AB@%_setcolor%@AE@%                           %@AB@%_GRNOTINPROPERMODE%@AE@%                                                                 %@AB@%_GRPARAMETERALTERED%@AE@%
  20174.  
  20175. %@AB@%_setfont%@AE@%                            %@AB@%_GRERROR,%@AE@%
  20176.                                     %@AB@%_GRFONTFILENOTFOUND,%@AE@%
  20177.                                     %@AB@%_GRINSUFFICIENTMEMORY,%@AE@%
  20178.                                     %@AB@%_GRPARAMETERALTERED%@AE@%
  20179.  
  20180. %@AI@%Continued on next page%@AE@%              
  20181.  
  20182. %@AB@%_setgtextvector%@AE@%                     %@AB@%_GRPARAMETERALTERED%@AE@%
  20183.  
  20184. %@AB@%_settextcolor%@AE@%                                                                                                          %@AB@%_GRPARAMETERALTERED%@AE@%
  20185.  
  20186. %@AB@%_settextcursor%@AE@%                      %@AB@%_GRNOTINPROPERMODE%@AE@%
  20187.  
  20188. %@AB@%_settextposition%@AE@%                                                                                                       %@AB@%_GRPARAMETERALTERED%@AE@%
  20189.  
  20190. %@AB@%_settextrows%@AE@%                        %@AB@%_GRINVALIDPARAMETER%@AE@%                                                                %@AB@%_GRPARAMETERALTERED%@AE@%
  20191.  
  20192. %@AB@%_settextwindow%@AE@%                                                                                                         %@AB@%_GRPARAMETERALTERED%@AE@%
  20193.  
  20194. %@AB@%_setvideomode%@AE@%                       %@AB@%_GRERROR,%@AE@%
  20195.                                     %@AB@%_GRMODENOTSUPPORTED,%@AE@%
  20196.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%
  20197.  
  20198. %@AB@%_setvideomoderows%@AE@%                   %@AB@%_GRERROR,%@AE@%
  20199.                                     %@AB@%_GRMODENOTSUPPORTED,%@AE@%
  20200.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%
  20201.  
  20202. %@AB@%_setvieworg%@AE@%                         %@AB@%_GRNOTINPROPERMODE%@AE@%
  20203.  
  20204. %@AB@%_setviewport%@AE@%                        %@AB@%_GRNOTINPROPERMODE%@AE@%                                                                 %@AB@%_GRPARAMETERALTERED%@AE@%
  20205.  
  20206. %@AB@%_setvisualpage%@AE@%                      %@AB@%_GRINVALIDPARAMETER%@AE@%
  20207.  
  20208. %@AB@%_setwindow%@AE@%                          %@AB@%_GRNOTINPROPERMODE,%@AE@%                                                                %@AB@%_GRPARAMETERALTERED%@AE@%
  20209.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%                                                                
  20210.  
  20211. %@AB@%_setwritemode%@AE@%                       %@AB@%_GRNOTINPROPERMODE,%@AE@%
  20212.                                     %@AB@%_GRINVALIDPARAMETER%@AE@%
  20213.  
  20214. %@AB@%────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20215.  
  20216. %@TE: 126  9075 03 36 83 33 @%
  20217.  
  20218. %@NL@%
  20219. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20220. %@NL@%
  20221. The %@AB@%_grstatus%@AE@% function returns the status of the most recently used graphics
  20222. function.  %@NL@%
  20223. %@NL@%
  20224. %@NL@%
  20225. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20226. %@NL@%
  20227. %@AB@%_arc%@AE@% functions,  %@AB@%_ellipse%@AE@% functions,  %@AB@%_floodfill%@AE@%,  %@AB@%_lineto%@AE@% functions,  %@AB@%_pie%@AE@%
  20228. functions, %@AB@%_remapallpalette%@AE@%,  %@AB@%_setactivepage%@AE@%,  %@AB@%_setbkcolor%@AE@%,  %@AB@%_setcolor%@AE@%,
  20229. %@AB@%_setpixel%@AE@% functions, %@AB@%_settextcolor%@AE@%,  %@AB@%_settextcursor%@AE@%,  %@AB@%_setvisualpage%@AE@%,
  20230. %@AB@%_setwindow%@AE@%,  %@AB@%_setwritemode%@AE@%  %@NL@%
  20231. %@NL@%
  20232. %@NL@%
  20233. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20234. %@NL@%
  20235.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  20236. %@NL@%
  20237. %@NL@%
  20238. %@NL@%
  20239. %@NL@%
  20240. %@NL@%
  20241. %@QR:halloc@%%@NL@%
  20242. %@2@%%@CR:C6A01610783 @%%@AB@%halloc%@AE@%%@EH@%%@NL@%
  20243. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20244. %@NL@%
  20245. %@NL@%
  20246. %@3@%%@AB@%Description%@CR:C6A01610784 @%%@CR:C6A01610785 @%%@AE@%%@EH@%%@NL@%
  20247. %@NL@%
  20248. Allocates a huge memory block.  %@NL@%
  20249. %@NL@%
  20250. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  20251.  
  20252. %@AS@%  void _huge *halloc( long num, size_t size );%@AE@%%@NL@%
  20253. %@NL@%
  20254. %@AI@%num%@AE@%                               Number of elements
  20255.  
  20256. %@AI@%size%@AE@%                              Length in bytes of each element
  20257.  
  20258. %@NL@%
  20259. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20260. %@NL@%
  20261. The %@AB@%halloc%@AE@% function allocates a huge array from the operating system
  20262. consisting of %@AI@%num%@AE@% elements, each of which is %@AI@%size%@AE@% bytes long. Each element
  20263. is initialized to 0. If the size of the array is greater than 128K (131,072
  20264. bytes), the size of an array element must then be a power of 2.  %@NL@%
  20265. %@NL@%
  20266. %@NL@%
  20267. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20268. %@NL@%
  20269. The %@AB@%halloc%@AE@% function returns a %@AB@%void huge%@AE@% pointer to the allocated space,
  20270. which is guaranteed to be suitably aligned for storage of any type of
  20271. object. To get a pointer to a type other than %@AB@%void huge%@AE@%, use a type cast on
  20272. the return value. If the request cannot be satisfied, the return value is
  20273. %@AB@%NULL%@AE@%.  %@NL@%
  20274. %@NL@%
  20275. %@NL@%
  20276. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20277. %@NL@%
  20278.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  20279. %@NL@%
  20280. %@NL@%
  20281. %@NL@%
  20282. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20283. %@NL@%
  20284. %@AB@%calloc%@AE@% functions, %@AB@%free%@AE@% functions, %@AB@%hfree%@AE@%, %@AB@%malloc%@AE@% functions  %@NL@%
  20285. %@NL@%
  20286. %@NL@%
  20287. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  20288. %@NL@%
  20289. %@AS@%  /* HALLOC.C: This program uses halloc to allocate space for 30,000 long
  20290. %@AS@%   * integers, then uses hfree to deallocate the memory.
  20291. %@AS@%   */
  20292. %@AS@%  
  20293. %@AS@%  #include <stdio.h>
  20294. %@AS@%  #include <stdlib.h>
  20295. %@AS@%  #include <malloc.h>
  20296. %@AS@%  
  20297. %@AS@%  void main()
  20298. %@AS@%  {
  20299. %@AS@%     long _huge *hbuf;%@AE@%%@NL@%
  20300. %@NL@%
  20301. %@AS@%  /* Allocate huge buffer */
  20302. %@AS@%     hbuf = (long _huge *)halloc( 30000L, sizeof( long ) );
  20303. %@AS@%     if ( hbuf == NULL )
  20304. %@AS@%        printf( "Insufficient memory available\n" );
  20305. %@AS@%     else
  20306. %@AS@%        printf( "Memory successfully allocated\n" );
  20307. %@AS@%  
  20308. %@AS@%     /* Free huge buffer */
  20309. %@AS@%     hfree( hbuf );
  20310. %@AS@%  }%@AE@%%@NL@%
  20311. %@NL@%
  20312. %@NL@%
  20313. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  20314. %@NL@%
  20315. %@AS@%  
  20316. %@AS@%  
  20317. %@AS@%  Memory successfully allocated %@AE@%%@NL@%
  20318. %@NL@%
  20319. %@NL@%
  20320. %@NL@%
  20321. %@NL@%
  20322. %@QR:_hard@%%@NL@%
  20323. %@2@%%@CR:C6A01620786 @%%@AB@%_hard Functions%@AE@%%@EH@%%@NL@%
  20324. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20325. %@NL@%
  20326. %@NL@%
  20327. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  20328. %@NL@%
  20329. Handle critical error conditions.  %@NL@%
  20330. %@NL@%
  20331. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  20332. %@NL@%
  20333. %@AS@%  void _harderr( void( _far *handler )());%@AE@%%@NL@%
  20334. %@NL@%
  20335. %@AS@%  void _hardresume( int result );%@AE@%%@NL@%
  20336. %@NL@%
  20337. %@AS@%  void _hardretn( int error );%@AE@%%@NL@%
  20338. %@NL@%
  20339. %@AI@%handler %@AE@%%@AB@%( )%@AE@%                       New INT 0x24 handler
  20340.  
  20341. %@AI@%result %@AE@%                           Handler return parameter
  20342.  
  20343. %@AI@%error%@AE@%                             Error to return from
  20344.  
  20345. %@NL@%
  20346. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20347. %@NL@%
  20348. These three functions are used to handle critical error conditions that use
  20349. DOS interrupt 0x24. The %@AB@%_harderr%@AE@% function installs a new critical-error
  20350. handler for interrupt 0x24.  %@NL@%
  20351. %@NL@%
  20352. The %@AB@%_hardresume%@AE@% and %@AB@%_hardreturn%@AE@% functions control how the program will
  20353. return from the new critical-error handler installed by %@AB@%_harderr%@AE@%. The
  20354. %@AB@%_hardresume%@AE@% function returns to DOS from a user-installed critical-error
  20355. handler, and the %@AB@%_hardreturn%@AE@% function returns directly to the application
  20356. program from a user-installed critical-error handler.  %@NL@%
  20357. %@NL@%
  20358. The %@AB@%_harderr%@AE@% function does not directly install the handler pointed to by
  20359. %@AI@%handler%@AE@%; instead, %@AB@%_harderr%@AE@% installs a handler that calls the function
  20360. referenced by %@AI@%handler%@AE@%. The handler calls the function with the following
  20361. parameters:   %@NL@%
  20362. %@NL@%
  20363. %@AS@%  handler(unsigned deverror, unsigned errcode, unsigned far *devhdr);
  20364. %@AS@%   %@AE@%%@NL@%
  20365. %@NL@%
  20366. The %@AI@%deverror%@AE@% argument is the device error code. It contains the AX register
  20367. value passed by DOS to the INT 0x24 handler. The %@AI@%errcode%@AE@% argument is the DI
  20368. register value that DOS passes to the handler. The low-order byte of %@AI@%errcode%@AE@%
  20369. can be one of the following values:  %@NL@%
  20370. %@NL@%
  20371. %@AB@%Code%@AE@%                              %@AB@%Meaning%@AE@%
  20372. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20373. %@AB@%0%@AE@%                                 Attempt to write to a write-protected 
  20374.                                   disk
  20375.  
  20376. %@AB@%1%@AE@%                                 Unknown unit
  20377.  
  20378. %@AB@%2%@AE@%                                 Drive not ready
  20379.  
  20380. %@AB@%3%@AE@%                                 Unknown command
  20381.  
  20382. %@AB@%4%@AE@%                                 Cyclic-redundancy-check error in data
  20383.  
  20384. %@AB@%5%@AE@%                                 Bad drive-request structure length
  20385.  
  20386. %@AB@%6%@AE@%                                 Seek error
  20387.  
  20388. %@AB@%7%@AE@%                                 Unknown media type
  20389.  
  20390. %@AB@%8%@AE@%                                 Sector not found
  20391.  
  20392. %@AB@%9%@AE@%                                 Printer out of paper
  20393.  
  20394. %@AB@%10%@AE@%                                Write fault
  20395.  
  20396. %@AB@%11%@AE@%                                Read fault
  20397.  
  20398. %@AB@%12%@AE@%                                General failure
  20399.  
  20400. The %@AI@%devhdr%@AE@% argument is a far pointer to a device header that contains
  20401. descriptive information about the device on which the error occurred. The
  20402. user-defined handler must not change the information in the device-header
  20403. control block.  %@NL@%
  20404. %@NL@%
  20405. %@NL@%
  20406. %@4@%%@AB@%Errors on Disk Devices%@AE@%%@EH@%%@NL@%
  20407. %@NL@%
  20408. If the error occurred on a disk device, the high-order bit (bit 15) of the
  20409. %@AI@%deverror%@AE@% argument will be set to 0, and the %@AI@%deverror%@AE@% argument will indicate
  20410. the following:  %@NL@%
  20411. %@NL@%
  20412. %@AB@%Bit%@AE@%                               %@AB@%Meaning%@AE@%
  20413. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20414. %@AB@%15%@AE@%                                Disk error if false (0).
  20415.  
  20416. %@AB@%14%@AE@%                                Not used.
  20417.  
  20418. %@AB@%13%@AE@%                                "Ignore" response not allowed if false 
  20419.                                   (0).
  20420.  
  20421. %@AB@%12%@AE@%                                "Retry" response not allowed if false 
  20422.                                   (0).
  20423.  
  20424. %@AB@%11%@AE@%                                "Fail" response not allowed if false 
  20425.                                   (0). Note that DOS changes "fail" to 
  20426.                                   "abort".
  20427.  
  20428. %@AB@%10, 9%@AE@%
  20429.  
  20430.                                   %@AB@%Code%@AE@%      %@AB@%Location%@AE@%
  20431. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20432.                                   %@AB@%00%@AE@%          DOS
  20433.  
  20434.                                   %@AB@%01%@AE@%          File allocation table
  20435.  
  20436.                                   %@AB@%10%@AE@%          Directory
  20437.  
  20438.                                   %@AB@%11%@AE@%          Data area
  20439.  
  20440. %@AB@%%@AE@%                                  
  20441. %@AB@%8%@AE@%                                 Read error if false; write error if 
  20442.                                   true.
  20443.  
  20444. The low-order byte of %@AI@%deverror%@AE@% indicates the drive in which the error
  20445. occurred (0 = drive A, 1 = drive B, etc.).  %@NL@%
  20446. %@NL@%
  20447. %@NL@%
  20448. %@4@%%@AB@%Errors on Other Devices%@AE@%%@EH@%%@NL@%
  20449. %@NL@%
  20450. If the error occurs on a device other than a disk drive, the high-order bit
  20451. (bit 15) of the %@AI@%deverror%@AE@% argument is 1. The attribute word located at offset
  20452. 4 in the device-header block indicates the type of device that had the
  20453. error. If bit 15 of the attribute word is 0, the error is a bad memory image
  20454. of the file allocation table. If the bit is 1, the error occurred on a
  20455. character device and bits 0-3 of the attribute word indicate the type of
  20456. device, as shown in the following list:  %@NL@%
  20457. %@NL@%
  20458. %@AB@%Bit%@AE@%                               %@AB@%Meaning%@AE@%
  20459. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20460. %@AB@%0%@AE@%                                 Current standard input
  20461.  
  20462. %@AB@%1%@AE@%                                 Current standard output
  20463.  
  20464. %@AB@%2%@AE@%                                 Current null device
  20465.  
  20466. %@AB@%3%@AE@%                                 Current clock device
  20467.  
  20468. %@NL@%
  20469. %@4@%%@AB@%Restrictions on Handler Functions%@AE@%%@EH@%%@NL@%
  20470. %@NL@%
  20471. The user-defined handler function can issue only system calls 0x01 through
  20472. 0x0C, or 0x59. Thus, many of the standard C run-time functions (such as
  20473. stream I/O and low-level I/O) cannot be used in a hardware error handler.
  20474. Function 0x59 can be used to obtain further information about the error that
  20475. occurred.  %@NL@%
  20476. %@NL@%
  20477. %@NL@%
  20478. %@4@%%@AB@%Using _hardresume and _harderr%@AE@%%@EH@%%@NL@%
  20479. %@NL@%
  20480. %@AB@%If the handler returns, it can do so%@AE@% - %@NL@%
  20481.   1.  From the %@AB@%return%@AE@% statement%@NL@%
  20482. %@NL@%
  20483.   2.  From the %@AB@%_hardresume%@AE@% function%@NL@%
  20484. %@NL@%
  20485.   3.  From the %@AB@%_hardretn%@AE@% function%@NL@%
  20486. %@NL@%
  20487. %@NL@%
  20488.  
  20489. If the handler returns from %@AB@%_hardresume%@AE@% or from a %@AB@%return%@AE@% statement, the
  20490. handler returns to DOS.  %@NL@%
  20491. %@NL@%
  20492. The %@AB@%_hardresume%@AE@% function should be called only from within the user-defined
  20493. hardware error-handler function. The result supplied to %@AB@%_hardresume%@AE@% must be
  20494. one of the following constants:  %@NL@%
  20495. %@NL@%
  20496. %@AB@%Constant%@AE@%                          %@AB@%Action%@AE@%
  20497. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20498. %@AB@%_HARDERR_ABORT%@AE@%                    Abort the program by issuing INT 0x23
  20499.  
  20500. %@AB@%_HARDERR_FAIL%@AE@%                     Fail the system call that is in progress
  20501.                                   (this is not supported on DOS 2. x)
  20502.  
  20503. %@AB@%_HARDERR_IGNORE%@AE@%                   Ignore the error
  20504.  
  20505. %@AB@%_HARDERR_RETRY%@AE@%                    Retry the operation
  20506.  
  20507. The %@AB@%_hardretn%@AE@% function allows the user-defined hardware error handler to
  20508. return directly to the application program rather than returning to DOS. The
  20509. application resumes at the point just after the failing I/O function
  20510. request. The %@AB@%_hardretn%@AE@% function should be called only from within a
  20511. user-defined hardware error-handler function.  %@NL@%
  20512. %@NL@%
  20513. The error parameter of %@AB@%_hardretn%@AE@% should be a DOS error code, as opposed to
  20514. the XENIX-style error code that is available in %@AB@%errno%@AE@%. Refer to %@AI@%MS-DOS
  20515. %@AI@%Encyclopedia%@AE@% (Duncan, ed.; Redmond, Wa.: Microsoft Press, 1988) or%@AI@%
  20516. %@AI@%Programmer's PC Sourcebook%@AE@% (Hogan; Redmond, Wa.: Microsoft Press, 1988) for
  20517. information about the DOS error codes that may be returned by a given DOS
  20518. function call.  %@NL@%
  20519. %@NL@%
  20520. If the failing I/O function request is an INT 0x21 function greater than or
  20521. equal to function 0x38, %@AB@%_hardretn%@AE@% will then return to the application with
  20522. the carry flag set and the AX register set to the %@AB@%_hardretn%@AE@% %@AI@%error%@AE@% parameter.
  20523. If the failing INT 0x21 function request is less than function 0x38 and the
  20524. function can return an error, the AL register will be set to 0xFF on return
  20525. to the application. If the failing INT 0x21 does not have a way of returning
  20526. an error condition (which is true of certain INT 0x21 functions below 0x38),
  20527. the error parameter of %@AB@%_hardretn%@AE@% is not used, and no error code is returned
  20528. to the application.  %@NL@%
  20529. %@NL@%
  20530. %@NL@%
  20531. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20532. %@NL@%
  20533. None.  %@NL@%
  20534. %@NL@%
  20535. %@NL@%
  20536. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20537. %@NL@%
  20538.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  20539. %@NL@%
  20540. %@NL@%
  20541. %@NL@%
  20542. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20543. %@NL@%
  20544. %@AB@%_chain_intr%@AE@%, %@AB@% _dos_getvect%@AE@%, %@AB@% _dos_setvect%@AE@%  %@NL@%
  20545. %@NL@%
  20546. %@NL@%
  20547. %@NL@%
  20548. %@NL@%
  20549. %@QR:_heapadd@%%@NL@%
  20550. %@2@%%@CR:C6A01630787 @%%@AB@%_heapadd Functions%@AE@%%@EH@%%@NL@%
  20551. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20552. %@NL@%
  20553. %@NL@%
  20554. %@3@%%@AB@%Description%@CR:C6A01630788 @%%@CR:C6A01630789 @% %@CR:C6A01630790 @% %@CR:C6A01630791 @%%@AE@%%@EH@%%@NL@%
  20555. %@NL@%
  20556. Add memory to the heap %@AB@%(_heapadd)%@AE@% or to the based heap %@AB@%(_bheapadd)%@AE@%.  %@NL@%
  20557. %@NL@%
  20558. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  20559.  
  20560. %@AS@%  int _heapadd( void _far *memblock, size_t size );%@AE@%%@NL@%
  20561. %@NL@%
  20562. %@AS@%  int _bheapadd( _segment seg, void _based (void) *memblock, size_t size );%@AE@%%@NL@%
  20563. %@NL@%
  20564. %@AI@%seg%@AE@%                               Based-heap segment selector
  20565.  
  20566. %@AI@%buffer%@AE@%                            Pointer to heap memory
  20567.  
  20568. %@AI@%size%@AE@%                              Size in bytes of memory to add
  20569.  
  20570. %@NL@%
  20571. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20572. %@NL@%
  20573. The %@AB@%_heapadd%@AE@% and %@AB@%_bheapadd%@AE@% functions add an unused piece of memory to the
  20574. heap. The %@AB@%_bheapadd%@AE@% function adds the memory to the based heap specified by
  20575. %@AI@%seg%@AE@%. The %@AB@%_heapadd%@AE@% function looks at the segment value and, if it is DGROUP,
  20576. adds the memory to the near heap. Otherwise, %@AB@%_heapadd%@AE@% adds the memory to the
  20577. far heap.  %@NL@%
  20578. %@NL@%
  20579. %@NL@%
  20580. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20581. %@NL@%
  20582. These functions return 0 if successful, or -1 if an error occurred.  %@NL@%
  20583. %@NL@%
  20584. %@NL@%
  20585. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20586. %@NL@%
  20587.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  20588. %@NL@%
  20589. %@NL@%
  20590. %@NL@%
  20591. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20592. %@NL@%
  20593. %@AB@%free%@AE@% functions, %@AB@%halloc%@AE@%, %@AB@%hfree%@AE@%, %@AB@%malloc%@AE@% functions, %@AB@%realloc%@AE@% functions  %@NL@%
  20594. %@NL@%
  20595. %@NL@%
  20596. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  20597. %@NL@%
  20598. %@AS@%  /* HEAPMIN.C: This program illustrates heap management using
  20599. %@AS@%   * _heapadd and _heapmin.
  20600. %@AS@%   */
  20601. %@AS@%  
  20602. %@AS@%  #include <stdio.h>
  20603. %@AS@%  #include <conio.h>
  20604. %@AS@%  #include <process.h>
  20605. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  20606. %@NL@%
  20607. %@AS@%  void heapdump( char *msg );     /* Prototype */
  20608. %@AS@%  
  20609. %@AS@%  char s1[] = { "Here are some strings that we use at first, then don't\n"
  20610. %@AS@%};
  20611. %@AS@%  char s2[] = { "need any more. We'll give their space to the heap.\n" };
  20612. %@AS@%  
  20613. %@AS@%  void main()
  20614. %@AS@%  {
  20615. %@AS@%      int *p[3], i;
  20616. %@AS@%  
  20617. %@AS@%      printf( "%s%s", s1, s2 );
  20618. %@AS@%      heapdump( "Initial heap" );
  20619. %@AS@%  
  20620. %@AS@%      /* Give space of used strings to heap. */
  20621. %@AS@%      _heapadd( s1, sizeof( s1 ) );
  20622. %@AS@%      _heapadd( s2, sizeof( s2 ) );
  20623. %@AS@%      heapdump( "After adding used strings" );
  20624. %@AS@%  
  20625. %@AS@%      /* Allocate some blocks. Some may use string blocks from _heapadd. */
  20626. %@AS@%      for( i = 0; i < 2; i++ )
  20627. %@AS@%          if( (p[i] = (int *)calloc( 10 * (i + 1), sizeof( int ) )) == NULL
  20628. %@AS@%)
  20629. %@AS@%          {
  20630. %@AS@%              --i;
  20631. %@AS@%              break;
  20632. %@AS@%          }
  20633. %@AS@%      heapdump( "After allocating memory" );
  20634. %@AS@%  
  20635. %@AS@%      /* Free some of the blocks. */
  20636. %@AS@%      free( p[1] );
  20637. %@AS@%      free( p[2] );
  20638. %@AS@%      heapdump( "After freeing memory" );
  20639. %@AS@%  
  20640. %@AS@%      /* Minimize heap. */
  20641. %@AS@%      _heapmin();
  20642. %@AS@%      heapdump( "After compacting heap" );
  20643. %@AS@%  }
  20644. %@AS@%  
  20645. %@AS@%  /* Walk through heap entries, displaying information about each block. */
  20646. %@AS@%  void heapdump( char *msg )
  20647. %@AS@%  {
  20648. %@AS@%      struct _heapinfo hi;
  20649. %@AS@%  
  20650. %@AS@%      printf( "%s\n", msg );
  20651. %@AS@%      hi._pentry = NULL;
  20652. %@AS@%      while( _heapwalk( &hi ) == _HEAPOK )
  20653. %@AS@%          printf( "\t%s block at %Fp of size %u\t\n",
  20654. %@AS@%                  hi._useflag == _USEDENTRY ? "USED" : "FREE",
  20655. %@AS@%                  hi._pentry,
  20656. %@AS@%                  hi._size );
  20657. %@AS@%      getch();
  20658. %@AS@%  }%@AE@%%@NL@%
  20659. %@NL@%
  20660. %@NL@%
  20661. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  20662. %@NL@%
  20663. %@AS@%  
  20664. %@AS@%  
  20665. %@AS@%  Here are some strings that we use at first, then don't
  20666. %@AS@%  need any more. We'll give their space to the heap.
  20667. %@AS@%  Initial heap
  20668. %@AS@%     USED block at 2D39:0E9C of size 364   
  20669. %@AS@%     USED block at 2D39:100A of size 36   
  20670. %@AS@%     USED block at 2D39:1030 of size 512   
  20671. %@AS@%     FREE block at 2D39:1232 of size 460   
  20672. %@AS@%  After adding used strings
  20673. %@AS@%     FREE block at 2D39:0044 of size 52   
  20674. %@AS@%     FREE block at 2D39:007A of size 50   
  20675. %@AS@%     USED block at 2D39:00AE of size 3564   
  20676. %@AS@%     USED block at 2D39:0E9C of size 364   
  20677. %@AS@%     USED block at 2D39:100A of size 36   
  20678. %@AS@%     USED block at 2D39:1030 of size 512   
  20679. %@AS@%     FREE block at 2D39:1232 of size 460   
  20680. %@AS@%  After allocating memory
  20681. %@AS@%     USED block at 2D39:0044 of size 20   
  20682. %@AS@%     USED block at 2D39:005A of size 40   
  20683. %@AS@%     FREE block at 2D39:0084 of size 40   
  20684. %@AS@%     USED block at 2D39:00AE of size 3564   
  20685. %@AS@%     USED block at 2D39:0E9C of size 364   
  20686. %@AS@%     USED block at 2D39:100A of size 36   
  20687. %@AS@%     USED block at 2D39:1030 of size 512   
  20688. %@AS@%     FREE block at 2D39:1232 of size 460   
  20689. %@AS@%  After freeing memory
  20690. %@AS@%     USED block at 2D39:0044 of size 20   
  20691. %@AS@%     FREE block at 2D39:005A of size 40   
  20692. %@AS@%     FREE block at 2D39:0084 of size 40   
  20693. %@AS@%     USED block at 2D39:00AE of size 3564   
  20694. %@AS@%     USED block at 2D39:0E9C of size 364   
  20695. %@AS@%     USED block at 2D39:100A of size 36   
  20696. %@AS@%     USED block at 2D39:1030 of size 512   
  20697. %@AS@%     FREE block at 2D39:1232 of size 460   
  20698. %@AS@%  After compacting heap
  20699. %@AS@%     USED block at 2D39:0044 of size 20   
  20700. %@AS@%     FREE block at 2D39:005A of size 82   
  20701. %@AS@%     USED block at 2D39:00AE of size 3564   
  20702. %@AS@%     USED block at 2D39:0E9C of size 364   
  20703. %@AS@%     USED block at 2D39:100A of size 36   
  20704. %@AS@%     USED block at 2D39:1030 of size 512   
  20705. %@AS@%     FREE block at 2D39:1232 of size 12   %@AE@%%@NL@%
  20706. %@NL@%
  20707. %@NL@%
  20708. %@NL@%
  20709. %@NL@%
  20710. %@QR:_heapchk@%%@NL@%
  20711. %@2@%%@CR:C6A01640792 @%%@AB@%_heapchk Functions%@AE@%%@EH@%%@NL@%
  20712. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20713. %@NL@%
  20714. %@NL@%
  20715. %@3@%%@AB@%Description%@CR:C6A01640793 @%%@CR:C6A01640794 @% %@CR:C6A01640795 @% %@CR:C6A01640796 @% %@CR:C6A01640797 @% %@CR:C6A01640798 @% %@CR:C6A01640799 @%%@CR:C6A01640800 @% %@CR:C6A01640801 @% %@CR:C6A01640802 @%%@AE@%%@EH@%%@NL@%
  20716. %@NL@%
  20717. Run consistency checks on the heap.  %@NL@%
  20718. %@NL@%
  20719. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  20720. %@NL@%
  20721. %@AS@%  int _heapchk( void );%@AE@%%@NL@%
  20722. %@NL@%
  20723. %@AS@%  int _bheapchk( _segment seg );%@AE@%%@NL@%
  20724. %@NL@%
  20725. %@AS@%  int _fheapchk( void );%@AE@%%@NL@%
  20726. %@NL@%
  20727. %@AS@%  int _nheapchk( void );%@AE@%%@NL@%
  20728. %@NL@%
  20729. %@AI@%seg %@AE@%                              Specified base heap
  20730.  
  20731. %@NL@%
  20732. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20733. %@NL@%
  20734. The %@AB@%_heapchk%@AE@% routines help to debug heap-related problems by checking for
  20735. minimal consistency of the heap.  %@NL@%
  20736. %@NL@%
  20737. Each function checks a particular heap, as listed below:  %@NL@%
  20738. %@NL@%
  20739. %@AB@%Function%@AE@%                          %@AB@%Heap Checked%@AE@%
  20740. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20741. %@AB@%_heapchk%@AE@%                          Depends on data model of program
  20742.  
  20743. %@AB@%_bheapchk%@AE@%                         Based heap specified by %@AI@%seg%@AE@% value
  20744.  
  20745. %@AB@%_fheapchk%@AE@%                         Far heap (outside the default data 
  20746.                                   segment)
  20747.  
  20748. %@AB@%_nheapchk%@AE@%                         Near heap (inside the default data 
  20749.                                   segment)
  20750.  
  20751. In large data models (that is, compact-, large-, and huge-model programs),
  20752. %@AB@%_heapchk%@AE@% maps to %@AB@%_fheapchk%@AE@%. In small data models (tiny-, small-, and
  20753. medium-model programs), %@AB@%_heapchk%@AE@% maps to %@AB@%_nheapchk%@AE@%.  %@NL@%
  20754. %@NL@%
  20755. %@NL@%
  20756. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20757. %@NL@%
  20758. All four routines return an integer value that is one of the following
  20759. manifest constants (defined in MALLOC.H):  %@NL@%
  20760. %@NL@%
  20761. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  20762. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20763. %@AB@%_HEAPBADBEGIN%@AE@%                     Initial header information cannot be 
  20764.                                   found, or it is bad
  20765.  
  20766. %@AB@%_HEAPBADNODE%@AE@%                      Bad node has been found, or the heap is 
  20767.                                   damaged
  20768.  
  20769. %@AB@%_HEAPEMPTY%@AE@%                        Heap has not been initialized
  20770.  
  20771. %@AB@%_HEAPOK%@AE@%                           Heap appears to be consistent
  20772.  
  20773. %@NL@%
  20774. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20775. %@NL@%
  20776.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  20777. %@NL@%
  20778. %@NL@%
  20779. %@NL@%
  20780. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20781. %@NL@%
  20782. %@AB@%_heapset%@AE@% functions,  %@AB@%_heapwalk%@AE@% functions  %@NL@%
  20783. %@NL@%
  20784. %@NL@%
  20785. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  20786. %@NL@%
  20787. %@AS@%  /* HEAPCHK.C: This program checks the heap for consistency
  20788. %@AS@%   * and prints an appropriate message.
  20789. %@AS@%   */
  20790. %@AS@%  
  20791. %@AS@%  #include <malloc.h>
  20792. %@AS@%  #include <stdio.h>
  20793. %@AS@%  
  20794. %@AS@%  void main()
  20795. %@AS@%  {
  20796. %@AS@%     int  heapstatus;
  20797. %@AS@%     char *buffer;
  20798. %@AS@%  
  20799. %@AS@%     /* Allocate and deallocate some memory */
  20800. %@AS@%     if( (buffer = (char *)malloc( 100 )) != NULL )
  20801. %@AS@%        free( buffer );
  20802. %@AS@%  
  20803. %@AS@%     /* Check heap status */
  20804. %@AS@%     heapstatus = _heapchk();
  20805. %@AS@%     switch( heapstatus )
  20806. %@AS@%     {
  20807. %@AS@%        case _HEAPOK:
  20808. %@AS@%           printf(" OK - heap is fine\n" );
  20809. %@AS@%           break;
  20810. %@AS@%        case _HEAPEMPTY:
  20811. %@AS@%           printf(" OK - heap is empty\n" );
  20812. %@AS@%           break;
  20813. %@AS@%        case _HEAPBADBEGIN:
  20814. %@AS@%           printf( "ERROR - bad start of heap\n" );
  20815. %@AS@%           break;
  20816. %@AS@%        case _HEAPBADNODE:
  20817. %@AS@%           printf( "ERROR - bad node in heap\n" );
  20818. %@AS@%           break;
  20819. %@AS@%     }
  20820. %@AS@%  }%@AE@%%@NL@%
  20821. %@NL@%
  20822. %@NL@%
  20823. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  20824. %@NL@%
  20825. %@AS@%  
  20826. %@AS@%  
  20827. %@AS@%   OK - heap is fine %@AE@%%@NL@%
  20828. %@NL@%
  20829. %@NL@%
  20830. %@NL@%
  20831. %@NL@%
  20832. %@QR:_heapmin@%%@NL@%
  20833. %@2@%%@CR:C6A01650803 @%%@AB@%_heapmin Functions%@AE@%%@EH@%%@NL@%
  20834. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20835. %@NL@%
  20836. %@NL@%
  20837. %@3@%%@AB@%Description%@CR:C6A01650804 @%%@CR:C6A01650805 @% %@CR:C6A01650806 @% %@CR:C6A01650807 @% %@CR:C6A01650808 @% %@CR:C6A01650809 @% %@CR:C6A01650810 @% %@CR:C6A01650811 @%%@CR:C6A01650812 @% %@CR:C6A01650813 @%%@AE@%%@EH@%%@NL@%
  20838. %@NL@%
  20839. Release unused heap memory to the operating system.  %@NL@%
  20840. %@NL@%
  20841. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  20842. %@NL@%
  20843. %@AS@%  int _heapmin( void );%@AE@%%@NL@%
  20844. %@NL@%
  20845. %@AS@%  int _bheapmin( _segment seg )%@AE@%%@NL@%
  20846. %@NL@%
  20847. %@AS@%  int _fheapmin( void );%@AE@%%@NL@%
  20848. %@NL@%
  20849. %@AS@%  int _nheapmin( void );%@AE@%%@NL@%
  20850. %@NL@%
  20851. %@AI@%seg%@AE@%                               Specified based-heap selector
  20852.  
  20853. %@NL@%
  20854. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20855. %@NL@%
  20856. The %@AB@%_heapmin%@AE@% functions minimize the heap by releasing unused heap memory to
  20857. the operating system.  %@NL@%
  20858. %@NL@%
  20859. The various %@AB@%_heapmin%@AE@% functions release unused memory in these heaps:  %@NL@%
  20860. %@NL@%
  20861. %@AB@%Function %@AE@%                         %@AB@%Heap Minimized%@AE@%
  20862. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20863. %@AB@%_heapmin%@AE@%                          Depends on data model of program
  20864.  
  20865. %@AB@%_bheapmin%@AE@%                         Based heap specified by %@AI@%seg%@AE@% value; %@AB@%%@AE@%
  20866.                                   %@AB@%_NULLSEG%@AE@% specifies all based heaps
  20867.  
  20868. %@AB@%_fheapmin%@AE@%                         Far heap (outside default data segment)
  20869.  
  20870. %@AB@%_nheapmin%@AE@%                         Near heap (inside default data segment)
  20871.  
  20872. In large data models (that is, compact-, large-, and huge-model programs),
  20873. %@AB@%_heapmin%@AE@% maps to %@AB@%_fheapmin%@AE@%. In small data models (tiny-, small-, and
  20874. medium-model programs), %@AB@%_heapmin%@AE@% maps to %@AB@%_nheapmin%@AE@%.  %@NL@%
  20875. %@NL@%
  20876. Based-heap segments are never freed (i.e., unlinked from the based heap list
  20877. and released back to the operating system) by the %@AB@%_bheapmin%@AE@% function. The
  20878. %@AB@%_bfreeseg%@AE@% function is used for that purpose.  %@NL@%
  20879. %@NL@%
  20880. %@NL@%
  20881. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20882. %@NL@%
  20883. The %@AB@%_heapmin%@AE@% functions return 0 if the function completed successfully, or
  20884. -1 in the case of an error.  %@NL@%
  20885. %@NL@%
  20886. %@NL@%
  20887. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20888. %@NL@%
  20889.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  20890. %@NL@%
  20891. %@NL@%
  20892. %@NL@%
  20893. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20894. %@NL@%
  20895. %@AB@%_bfreeseg%@AE@%, %@AB@%free%@AE@% functions, %@AB@%malloc%@AE@% functions  %@NL@%
  20896. %@NL@%
  20897. %@NL@%
  20898. %@NL@%
  20899. %@NL@%
  20900. %@QR:_heapset@%%@NL@%
  20901. %@2@%%@CR:C6A01660814 @%%@AB@%_heapset Functions%@AE@%%@EH@%%@NL@%
  20902. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20903. %@NL@%
  20904. %@NL@%
  20905. %@3@%%@AB@%Description%@CR:C6A01660815 @% %@CR:C6A01660816 @% %@CR:C6A01660817 @%%@CR:C6A01660818 @% %@CR:C6A01660819 @%%@CR:C6A01660820 @% %@CR:C6A01660821 @%%@CR:C6A01660822 @%%@AE@%%@EH@%%@NL@%
  20906. %@NL@%
  20907. Check heaps for minimal consistency and set the free entries to a specified
  20908. value.  %@NL@%
  20909. %@NL@%
  20910. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  20911. %@NL@%
  20912. %@AS@%  int _heapset( unsigned int fill );%@AE@%%@NL@%
  20913. %@NL@%
  20914. %@AS@%  int _bheapset( _segment seg, unsigned int fill );%@AE@%%@NL@%
  20915. %@NL@%
  20916. %@AS@%  int _fheapset( unsigned int fill );%@AE@%%@NL@%
  20917. %@NL@%
  20918. %@AS@%  int _nheapset( unsigned int fill );%@AE@%%@NL@%
  20919. %@NL@%
  20920. %@AI@%fill%@AE@%                              Fill character
  20921.  
  20922. %@AI@%seg%@AE@%                               Specified based-heap segment selector
  20923.  
  20924. %@NL@%
  20925. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  20926. %@NL@%
  20927. The %@AB@%_heapset%@AE@% family of routines helps debug heap-related problems in
  20928. programs by showing free memory locations or nodes unintentionally
  20929. overwritten.  %@NL@%
  20930. %@NL@%
  20931. The %@AB@%_heapset%@AE@% routines first check for minimal consistency on the heap in a
  20932. manner identical to that of the %@AB@%_heapchk%@AE@% functions. After the consistency
  20933. check, the %@AB@%_heapset%@AE@% functions set each byte of the heap's free entries to
  20934. the %@AI@%fill%@AE@% value. This known value shows which memory locations of the heap
  20935. contain free nodes and which locations contain data that were
  20936. unintentionally written to freed memory.  %@NL@%
  20937. %@NL@%
  20938. The various %@AB@%_heapset%@AE@% functions check and fill these heaps:  %@NL@%
  20939. %@NL@%
  20940. %@AB@%Function%@AE@%                          %@AB@%Heap Filled%@AE@%
  20941. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20942. %@AB@%_heapset%@AE@%                          Depends on data model of program
  20943.  
  20944. %@AB@%_bheapset%@AE@%                         Based heap specified by %@AI@%seg%@AE@% value; %@AB@%%@AE@%
  20945.                                   %@AB@%_NULLSEG %@AE@%specifies all based heaps
  20946.  
  20947. %@AB@%_fheapset%@AE@%                         Far heap (outside default data segment)
  20948.  
  20949. %@AB@%_nheapset%@AE@%                         Near heap (inside default data segment)
  20950.  
  20951. In large data models (that is, compact-, large-, and huge-model programs),
  20952. %@AB@%_heapset%@AE@% maps to %@AB@%_fheapset%@AE@%. In small data models (tiny-, small-, and
  20953. medium-model programs), %@AB@%_heapset%@AE@% maps to %@AB@%_nheapset%@AE@%.  %@NL@%
  20954. %@NL@%
  20955. %@NL@%
  20956. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  20957. %@NL@%
  20958. All four routines return an %@AB@%int%@AE@% whose value is one of the following manifest
  20959. constants (defined in MALLOC.H):  %@NL@%
  20960. %@NL@%
  20961. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  20962. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  20963. %@AB@%_HEAPBADBEGIN%@AE@%                     Initial header information cannot be 
  20964.                                   found, or it is invalid 
  20965.  
  20966. %@AB@%_HEAPBADNODE%@AE@%                      Bad node has been found, or the heap is 
  20967.                                   damaged
  20968.  
  20969. %@AB@%_HEAPEMPTY%@AE@%                        Heap has not been initialized 
  20970.  
  20971. %@AB@%_HEAPOK%@AE@%                           Heap appears to be consistent
  20972.  
  20973. %@AB@%%@AE@%
  20974.  
  20975. %@NL@%
  20976. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  20977. %@NL@%
  20978.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  20979. %@NL@%
  20980. %@NL@%
  20981. %@NL@%
  20982. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  20983. %@NL@%
  20984. %@AB@%_heapchk%@AE@% functions,  %@AB@%_heapwalk%@AE@% functions  %@NL@%
  20985. %@NL@%
  20986. %@NL@%
  20987. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  20988. %@NL@%
  20989. %@AS@%  /* HEAPSET.C: This program checks the heap and fills in free entries
  20990. %@AS@%   * with the character 'Z'.
  20991. %@AS@%   */
  20992. %@AS@%  
  20993. %@AS@%  #include <malloc.h>
  20994. %@AS@%  #include <stdio.h>
  20995. %@AS@%  #include <stdlib.h>
  20996. %@AS@%  
  20997. %@AS@%  void main()
  20998. %@AS@%  {
  20999. %@AS@%     int heapstatus;
  21000. %@AS@%     char *buffer;%@AE@%%@NL@%
  21001. %@NL@%
  21002. %@AS@%  if( (buffer = malloc( 1 )) == NULL )   /* Make sure heap is initialized */
  21003. %@AS@%        exit( 0 );
  21004. %@AS@%     heapstatus = _heapset( 'Z' );          /* Fill in free entries */
  21005. %@AS@%     switch( heapstatus )
  21006. %@AS@%     {
  21007. %@AS@%        case _HEAPOK:
  21008. %@AS@%           printf( "OK - heap is fine\n" );
  21009. %@AS@%           break;
  21010. %@AS@%        case _HEAPEMPTY:
  21011. %@AS@%           printf( "OK - heap is empty\n" );
  21012. %@AS@%           break;
  21013. %@AS@%        case _HEAPBADBEGIN:
  21014. %@AS@%           printf( "ERROR - bad start of heap\n" );
  21015. %@AS@%           break;
  21016. %@AS@%        case _HEAPBADNODE:
  21017. %@AS@%           printf( "ERROR - bad node in heap\n" );
  21018. %@AS@%           break;
  21019. %@AS@%     }
  21020. %@AS@%     free( buffer );
  21021. %@AS@%  }%@AE@%%@NL@%
  21022. %@NL@%
  21023. %@NL@%
  21024. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21025. %@NL@%
  21026. %@AS@%  
  21027. %@AS@%  
  21028. %@AS@%  OK - heap is fine %@AE@%%@NL@%
  21029. %@NL@%
  21030. %@NL@%
  21031. %@NL@%
  21032. %@NL@%
  21033. %@QR:_heapwalk@%%@NL@%
  21034. %@2@%%@CR:C6A01670823 @%%@AB@%_heapwalk Functions%@AE@%%@EH@%%@NL@%
  21035. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21036. %@NL@%
  21037. %@NL@%
  21038. %@3@%%@AB@%Description%@CR:C6A01670824 @%%@CR:C6A01670825 @% %@CR:C6A01670826 @%%@CR:C6A01670827 @% %@CR:C6A01670828 @% %@CR:C6A01670829 @%%@CR:C6A01670830 @% %@CR:C6A01670831 @%%@AE@%%@EH@%%@NL@%
  21039. %@NL@%
  21040. Traverse the heap and return information about the next entry.  %@NL@%
  21041. %@NL@%
  21042. %@AS@%  include <malloc.h>%@AE@%%@NL@%
  21043. %@NL@%
  21044. %@AS@%  int _heapwalk( _HEAPINFO *entryinfo );%@AE@%%@NL@%
  21045. %@NL@%
  21046. %@AS@%  int _bheapwalk( _segment seg, _HEAPINFO *entryinfo );%@AE@%%@NL@%
  21047. %@NL@%
  21048. %@AS@%  int _fheapwalk( _HEAPINFO *entryinfo );%@AE@%%@NL@%
  21049. %@NL@%
  21050. %@AS@%  int _nheapwalk(_HEAPINFO *entryinfo);%@AE@%%@NL@%
  21051. %@NL@%
  21052. %@AI@%entryinfo%@AE@%                         Buffer to contain heap information
  21053.  
  21054. %@AI@%seg%@AE@%                               Based-heap segment selector
  21055.  
  21056. %@NL@%
  21057. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21058. %@NL@%
  21059. The %@AB@%_heapwalk%@AE@% family of routines helps debug heap-related problems in
  21060. programs.  %@NL@%
  21061. %@NL@%
  21062. The %@AB@%_heapwalk%@AE@% routines walk through the heap, traversing one entry per call,
  21063. and return a pointer to a %@AB@%_heapinfo%@AE@% structure that contains information
  21064. about the next heap entry. The %@AB@%_heapinfo%@AE@% structure, defined in MALLOC.H,
  21065. contains the following elements:  %@NL@%
  21066. %@NL@%
  21067. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  21068. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21069. %@AB@%int far *_pentry%@AE@%                  Heap entry pointer
  21070.  
  21071. %@AB@%size_t  _size%@AE@%                     Size of heap entry
  21072.  
  21073. %@AB@%int _useflag%@AE@%                      Entry "in use" flag
  21074.  
  21075. A call to %@AB@%_heapwalk%@AE@% that returns %@AB@%_HEAPOK%@AE@% stores the size of the entry in the
  21076. %@AB@%_size%@AE@% field and sets the %@AB@%_useflag%@AE@% field to either %@AB@%_FREEENTRY%@AE@% or %@AB@%_USEDENTRY%@AE@%
  21077. (both are constants defined in MALLOC.H). To obtain this information about
  21078. the first entry in the heap, pass the %@AB@%_heapwalk%@AE@% routine a pointer to a
  21079. %@AB@%_heapinfo%@AE@% structure whose %@AB@%_pentry%@AE@% field is %@AB@%NULL%@AE@%.  %@NL@%
  21080. %@NL@%
  21081. The various %@AB@%_heapwalk%@AE@% functions walk through and gather information on these
  21082. heaps:  %@NL@%
  21083. %@NL@%
  21084. %@AB@%Function%@AE@%                          %@AB@%Heap Walked%@AE@%
  21085. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21086. %@AB@%_heapwalk%@AE@%                         Depends on data model of program
  21087.  
  21088. %@AB@%_bheapwalk%@AE@%                        Based heap specified by %@AI@%seg%@AE@% value; %@AB@%%@AE@%
  21089.                                   %@AB@%_NULLSEG%@AE@% specifies all based heaps
  21090.  
  21091. %@AB@%_fheapwalk%@AE@%                        Far heap (outside default data segment)
  21092.  
  21093. %@AB@%_nheapwalk%@AE@%                        Near heap (inside default data segment)
  21094.  
  21095. In large data models (that is, compact-, large-, and huge-model programs),
  21096. %@AB@%_heapwalk%@AE@% maps to %@AB@%_fheapwalk%@AE@%. In small data models (tiny-, small-, and
  21097. medium-model programs), %@AB@%_heapwalk%@AE@% maps to %@AB@%_nheapwalk%@AE@%.  %@NL@%
  21098. %@NL@%
  21099. %@NL@%
  21100. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21101. %@NL@%
  21102. All three routines return one of the following manifest constants (defined
  21103. in MALLOC.H):  %@NL@%
  21104. %@NL@%
  21105. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  21106. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21107. %@AB@%_HEAPBADBEGIN%@AE@%                     The initial header information cannot be
  21108.                                   found, or it is invalid.
  21109.  
  21110. %@AB@%_HEAPBADNODE%@AE@%                      A bad node has been found, or the heap 
  21111.                                   is damaged.
  21112.  
  21113. %@AB@%_HEAPBADPTR%@AE@%                       The %@AB@%_pentry%@AE@% field of the %@AB@%_heapinfo%@AE@% 
  21114.                                   structure does not contain a valid 
  21115.                                   pointer into the heap.
  21116.  
  21117. %@AB@%_HEAPEND%@AE@%                          The end of the heap has been reached 
  21118.                                   successfully.
  21119.  
  21120. %@AB@%_HEAPEMPTY%@AE@%                        The heap has not been initialized.
  21121.  
  21122. %@AB@%_HEAPOK%@AE@%                           No errors so far; the %@AB@%_heapinfo%@AE@% 
  21123.                                   structure contains information about the
  21124.                                   next entry.
  21125.  
  21126. %@NL@%
  21127. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21128. %@NL@%
  21129.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  21130. %@NL@%
  21131. %@NL@%
  21132. %@NL@%
  21133. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21134. %@NL@%
  21135. %@AB@%_heapchk%@AE@% functions,  %@AB@%_heapset%@AE@% functions  %@NL@%
  21136. %@NL@%
  21137. %@NL@%
  21138. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21139. %@NL@%
  21140. %@AS@%  /* HEAPWALK.C: This program "walks" the heap, starting at the beginning
  21141. %@AS@%   * (_pentry = NULL). It prints out each heap entry's use, location,
  21142. %@AS@%   * and size. It also prints out information about the overall state
  21143. %@AS@%   * of the heap as soon as _heapwalk returns a value other than _HEAPOK.
  21144. %@AS@%   */
  21145. %@AS@%  
  21146. %@AS@%  #include <stdio.h>
  21147. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  21148. %@NL@%
  21149. %@AS@%  void heapdump( void );
  21150. %@AS@%  
  21151. %@AS@%  void main()
  21152. %@AS@%  {
  21153. %@AS@%     char *buffer;
  21154. %@AS@%  
  21155. %@AS@%     heapdump();
  21156. %@AS@%     if( (buffer = malloc( 59 )) != NULL )
  21157. %@AS@%     {
  21158. %@AS@%        heapdump();
  21159. %@AS@%        free( buffer );
  21160. %@AS@%     }
  21161. %@AS@%     heapdump();
  21162. %@AS@%  }
  21163. %@AS@%  
  21164. %@AS@%  void heapdump( void )
  21165. %@AS@%  {
  21166. %@AS@%     struct _heapinfo hinfo;
  21167. %@AS@%     int heapstatus;
  21168. %@AS@%  
  21169. %@AS@%     hinfo._pentry = NULL;
  21170. %@AS@%     while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK )
  21171. %@AS@%     {
  21172. %@AS@%        printf( "%6s block at %Fp of size %4.4X\n",
  21173. %@AS@%           ( hinfo._useflag == _USEDENTRY ? "USED" : "FREE" ),
  21174. %@AS@%           hinfo._pentry, hinfo._size );
  21175. %@AS@%     }
  21176. %@AS@%  
  21177. %@AS@%     switch( heapstatus )
  21178. %@AS@%     {
  21179. %@AS@%        case _HEAPEMPTY:
  21180. %@AS@%           printf( "OK - empty heap\n" );
  21181. %@AS@%           break;
  21182. %@AS@%        case _HEAPEND:
  21183. %@AS@%           printf( "OK - end of heap\n" );
  21184. %@AS@%           break;
  21185. %@AS@%        case _HEAPBADPTR:
  21186. %@AS@%           printf( "ERROR - bad pointer to heap\n" );
  21187. %@AS@%           break;
  21188. %@AS@%        case _HEAPBADBEGIN:
  21189. %@AS@%           printf( "ERROR - bad start of heap\n" );
  21190. %@AS@%           break;
  21191. %@AS@%        case _HEAPBADNODE:
  21192. %@AS@%           printf( "ERROR - bad node in heap\n" );
  21193. %@AS@%           break;
  21194. %@AS@%     }
  21195. %@AS@%  }%@AE@%%@NL@%
  21196. %@NL@%
  21197. %@NL@%
  21198. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21199. %@NL@%
  21200. %@AS@%  
  21201. %@AS@%  
  21202. %@AS@%    USED block at 0067:103E of size 000E
  21203. %@AS@%    USED block at 0067:104E of size 01F4
  21204. %@AS@%    USED block at 0067:1244 of size 0026
  21205. %@AS@%    USED block at 0067:126C of size 0200
  21206. %@AS@%    FREE block at 0067:146E of size 0B90
  21207. %@AS@%  OK - end of heap
  21208. %@AS@%    USED block at 0067:103E of size 000E
  21209. %@AS@%    USED block at 0067:104E of size 01F4
  21210. %@AS@%    USED block at 0067:1244 of size 0026
  21211. %@AS@%    USED block at 0067:126C of size 0200
  21212. %@AS@%    USED block at 0067:146E of size 003C
  21213. %@AS@%    FREE block at 0067:14AC of size 0B52
  21214. %@AS@%  OK - end of heap
  21215. %@AS@%    USED block at 0067:103E of size 000E
  21216. %@AS@%    USED block at 0067:104E of size 01F4
  21217. %@AS@%    USED block at 0067:1244 of size 0026
  21218. %@AS@%    USED block at 0067:126C of size 0200
  21219. %@AS@%    FREE block at 0067:146E of size 003C
  21220. %@AS@%    FREE block at 0067:14AC of size 0B52
  21221. %@AS@%  OK - end of heap %@AE@%%@NL@%
  21222. %@NL@%
  21223. %@NL@%
  21224. %@NL@%
  21225. %@NL@%
  21226. %@QR:hfree@%%@NL@%
  21227. %@2@%%@CR:C6A01680832 @%%@AB@%hfree%@AE@%%@EH@%%@NL@%
  21228. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21229. %@NL@%
  21230. %@NL@%
  21231. %@3@%%@AB@%Description%@CR:C6A01680833 @%%@CR:C6A01680834 @%%@AE@%%@EH@%%@NL@%
  21232. %@NL@%
  21233. Frees a huge memory block.  %@NL@%
  21234. %@NL@%
  21235. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  21236.  
  21237. %@AS@%  void hfree( void _huge *memblock );%@AE@%%@NL@%
  21238. %@NL@%
  21239. %@AI@%memblock%@AE@%                          Pointer to allocated memory block
  21240.  
  21241. %@NL@%
  21242. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21243. %@NL@%
  21244. The %@AB@%hfree%@AE@% function deallocates a memory block; the freed memory is returned
  21245. to the operating system. The %@AI@%memblock%@AE@% argument points to a memory block
  21246. previously allocated through a call to %@AB@%halloc%@AE@%. The number of bytes freed is
  21247. the number of bytes specified when the block was allocated.  %@NL@%
  21248. %@NL@%
  21249. Note that attempting to free an invalid %@AI@%memblock%@AE@% argument (one not allocated
  21250. with %@AB@%halloc%@AE@%) may affect subsequent allocation and cause errors.  %@NL@%
  21251. %@NL@%
  21252. %@NL@%
  21253. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21254. %@NL@%
  21255. None.  %@NL@%
  21256. %@NL@%
  21257. %@NL@%
  21258. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21259. %@NL@%
  21260.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  21261. %@NL@%
  21262. %@NL@%
  21263. %@NL@%
  21264. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21265. %@NL@%
  21266. %@AB@%halloc%@AE@%  %@NL@%
  21267. %@NL@%
  21268. %@NL@%
  21269. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21270. %@NL@%
  21271. %@AS@%  /* HALLOC.C: This program uses halloc to allocate space for 30,000 long
  21272. %@AS@%   * integers, then uses hfree to deallocate the memory.
  21273. %@AS@%   */
  21274. %@AS@%  
  21275. %@AS@%  #include <stdio.h>
  21276. %@AS@%  #include <stdlib.h>
  21277. %@AS@%  #include <malloc.h>
  21278. %@AS@%  
  21279. %@AS@%  void main()
  21280. %@AS@%  {
  21281. %@AS@%     long _huge *hbuf;
  21282. %@AS@%  
  21283. %@AS@%     /* Allocate huge buffer */
  21284. %@AS@%     hbuf = (long _huge *)halloc( 30000L, sizeof( long ) );
  21285. %@AS@%     if ( hbuf == NULL )
  21286. %@AS@%        printf( "Insufficient memory available\n" );
  21287. %@AS@%     else
  21288. %@AS@%        printf( "Memory successfully allocated\n" );%@AE@%%@NL@%
  21289. %@NL@%
  21290. %@AS@%  /* Free huge buffer */
  21291. %@AS@%     hfree( hbuf );
  21292. %@AS@%  }%@AE@%%@NL@%
  21293. %@NL@%
  21294. %@NL@%
  21295. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21296. %@NL@%
  21297. %@AS@%  
  21298. %@AS@%  
  21299. %@AS@%  Memory successfully allocated %@AE@%%@NL@%
  21300. %@NL@%
  21301. %@NL@%
  21302. %@NL@%
  21303. %@NL@%
  21304. %@QR:hypot@%%@QR:hypotl@%%@NL@%
  21305. %@2@%%@CR:C6A01690835 @%%@AB@%hypot, hypotl%@AE@%%@EH@%%@NL@%
  21306. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21307. %@NL@%
  21308. %@NL@%
  21309. %@3@%%@AB@%Description%@CR:C6A01690836 @%%@CR:C6A01690837 @%%@CR:C6A01690838 @% %@CR:C6A01690839 @%%@CR:C6A01690840 @% %@CR:C6A01690841 @%%@AE@%%@EH@%%@NL@%
  21310. %@NL@%
  21311. Calculate the hypotenuse.  %@NL@%
  21312. %@NL@%
  21313. %@AS@%  #include <math.h>%@AE@%%@NL@%
  21314. %@NL@%
  21315. %@AS@%  double hypot( double x, double y );%@AE@%%@NL@%
  21316. %@NL@%
  21317. %@AS@%  long double hypotl( long double x, long double y );%@AE@%%@NL@%
  21318. %@NL@%
  21319. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              Floating-point values
  21320.  
  21321. %@NL@%
  21322. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21323. %@NL@%
  21324. The %@AB@%hypot%@AE@% and %@AB@%hypotl%@AE@% functions calculate the length of the hypotenuse of a
  21325. right triangle, given the length of the two sides %@AI@%x%@AE@% and %@AI@%y%@AE@% (or %@AI@%xl%@AE@% and %@AI@%yl%@AE@%). A
  21326. call to %@AB@%hypot%@AE@% is equivalent to the following:   %@NL@%
  21327. %@NL@%
  21328. %@AS@%  sqrt(x*x + y*y);
  21329. %@AS@%   %@AE@%%@NL@%
  21330. %@NL@%
  21331. The %@AB@%hypotl%@AE@% function uses the 80-bit, 10-byte coprocessor form of arguments
  21332. and return values. See the reference page on the long double functions for
  21333. more details on this data type.  %@NL@%
  21334. %@NL@%
  21335. %@NL@%
  21336. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21337. %@NL@%
  21338. The functions return the length of the hypotenuse. If an overflow results,
  21339. the functions return %@AB@%HUGE_VAL%@AE@% and set %@AB@%errno%@AE@% to %@AB@%ERANGE.%@AE@%  %@NL@%
  21340. %@NL@%
  21341. %@NL@%
  21342. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21343. %@NL@%
  21344. %@AB@%hypot%@AE@%  %@NL@%
  21345. %@NL@%
  21346.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  21347. %@NL@%
  21348. %@NL@%
  21349. %@AB@%hypotl%@AE@%  %@NL@%
  21350. %@NL@%
  21351.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  21352. %@NL@%
  21353. %@NL@%
  21354. %@NL@%
  21355. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21356. %@NL@%
  21357. %@AB@%cabs%@AE@%  %@NL@%
  21358. %@NL@%
  21359. %@NL@%
  21360. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21361. %@NL@%
  21362. %@AS@%  /* HYPOT.C: This program prints the hypotenuse of a right triangle. */
  21363. %@AS@%  
  21364. %@AS@%  #include <math.h>
  21365. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  21366. %@NL@%
  21367. %@AS@%  void main()
  21368. %@AS@%  {
  21369. %@AS@%     double x = 3.0, y = 4.0;
  21370. %@AS@%  
  21371. %@AS@%     printf( "If a right triangle has sides %2.1f and %2.1f, "
  21372. %@AS@%             "its hypotenuse is %2.1f\n", x, y, hypot( x, y ) );
  21373. %@AS@%  }%@AE@%%@NL@%
  21374. %@NL@%
  21375. %@NL@%
  21376. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21377. %@NL@%
  21378. %@AS@%  
  21379. %@AS@%  
  21380. %@AS@%  If a right triangle has sides 3.0 and 4.0, its hypotenuse is 5.0%@AE@%%@NL@%
  21381. %@NL@%
  21382. %@NL@%
  21383. %@NL@%
  21384. %@NL@%
  21385. %@QR:_imagesize@%%@NL@%
  21386. %@2@%%@CR:C6A01700842 @%%@AB@%_imagesize Functions%@AE@%%@EH@%%@NL@%
  21387. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21388. %@NL@%
  21389. %@NL@%
  21390. %@3@%%@AB@%Description%@CR:C6A01700843 @%%@AE@%%@EH@%%@NL@%
  21391. %@NL@%
  21392. Get amount of memory required to store graphics images.  %@NL@%
  21393. %@NL@%
  21394. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  21395. %@NL@%
  21396. %@AS@%  long _far _imagesize( short x1, short y1, short x2, short y2 );%@AE@%%@NL@%
  21397. %@NL@%
  21398. %@AS@%  long _far _imagesize_w( double wx1, double wy1, double wx2, double wy2 );%@AE@%%@NL@%
  21399. %@NL@%
  21400. %@AS@%  long _far _imagesize_wxy( struct _wxycoord _far *pwxy1, 
  21401. %@AS@%  struct _wxycoord _far *pwxy2 );%@AE@%%@NL@%
  21402. %@NL@%
  21403. %@AI@%x1%@AE@%, %@AI@%y1%@AE@%                            Upper-left corner of bounding rectangle
  21404.  
  21405. %@AI@%x2%@AE@%, %@AI@%y2%@AE@%                            Lower-right corner of bounding rectangle
  21406.  
  21407. %@AI@%wx1%@AE@%, %@AI@%wy1%@AE@%                          Upper-left corner of bounding rectangle
  21408.  
  21409. %@AI@%wx2%@AE@%, %@AI@%wy2%@AE@%                          Lower-right corner of bounding rectangle
  21410.  
  21411. %@AI@%pwxy1%@AE@%                             Upper-left corner of bounding rectangle
  21412.  
  21413. %@AI@%pwxy2%@AE@%                             Lower-right corner of bounding rectangle
  21414.  
  21415. %@NL@%
  21416. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21417. %@NL@%
  21418. The functions in the %@AB@%_imagesize%@AE@% family return the number of bytes needed to
  21419. store the image defined by the bounding rectangle and specified by the
  21420. coordinates given in the function call.  %@NL@%
  21421. %@NL@%
  21422. The %@AB@%_imagesize%@AE@% function defines the bounding rectangle in terms of
  21423. view-coordinate points (%@AI@%x1%@AE@%, %@AI@%y1%@AE@%) and (%@AI@%x2%@AE@%, %@AI@%y2%@AE@%).  %@NL@%
  21424. %@NL@%
  21425. The %@AB@%_imagesize_w%@AE@% function defines the bounding rectangle in terms of
  21426. window-coordinate points (%@AI@%x1%@AE@%, %@AI@%y1%@AE@%) and (%@AI@%x2%@AE@%, %@AI@%y2%@AE@%).  %@NL@%
  21427. %@NL@%
  21428. The %@AB@%_imagesize_wxy%@AE@% function defines the bounding rectangle in terms of the
  21429. window-coordinate pairs %@AI@%pwxy1%@AE@% and %@AI@%pwxy2%@AE@%.  %@NL@%
  21430. %@NL@%
  21431. The number of bytes needed to store the image is determined by the following
  21432. formula:  %@NL@%
  21433. %@NL@%
  21434. %@AS@%  xwid = abs(x1-x2)+1;
  21435. %@AS@%  ywid = abs(y1-y2)+1;
  21436. %@AS@%  size = 4+((long)((xwid*bits_per_pixel+7)/8)*(long)ywid);%@AE@%%@NL@%
  21437. %@NL@%
  21438. A call to %@AB@%_getvideoconfig%@AE@% stores the %@AS@% bits_per_pixel %@AE@% information in the
  21439. %@AB@%bitsperpixel%@AE@% field of a %@AB@%videoconfig%@AE@% structure.  %@NL@%
  21440. %@NL@%
  21441. %@NL@%
  21442. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21443. %@NL@%
  21444. The function returns the storage size of the image in bytes. There is no
  21445. error return.  %@NL@%
  21446. %@NL@%
  21447. %@NL@%
  21448. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21449. %@NL@%
  21450.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  21451. %@NL@%
  21452. %@NL@%
  21453. %@NL@%
  21454. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21455. %@NL@%
  21456. %@AB@%_getimage %@AE@%functions,  %@AB@%_getvideoconfig%@AE@%,  %@AB@%_putimage%@AE@% functions  %@NL@%
  21457. %@NL@%
  21458. %@NL@%
  21459. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21460. %@NL@%
  21461. See the example for %@AB@%_getimage%@AE@%.  %@NL@%
  21462. %@NL@%
  21463. %@NL@%
  21464. %@NL@%
  21465. %@NL@%
  21466. %@QR:inp@%%@QR:inpw@%%@NL@%
  21467. %@2@%%@CR:C6A01710844 @%%@AB@%inp, inpw%@AE@%%@EH@%%@NL@%
  21468. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21469. %@NL@%
  21470. %@NL@%
  21471. %@3@%%@AB@%Description%@CR:C6A01710845 @%%@CR:C6A01710846 @% %@CR:C6A01710847 @%%@CR:C6A01710848 @%%@AE@%%@EH@%%@NL@%
  21472. %@NL@%
  21473. Input a byte (%@AB@%inp%@AE@%) or a word (%@AB@%inpw%@AE@%) from a port.  %@NL@%
  21474. %@NL@%
  21475. %@AB@%#include <conio.h>%@AE@%                Required only for function declarations
  21476.  
  21477. %@AS@%  int inp( unsigned port );%@AE@%%@NL@%
  21478. %@NL@%
  21479. %@AS@%  unsigned inpw( unsigned port );%@AE@%%@NL@%
  21480. %@NL@%
  21481. %@AI@%port%@AE@%                              Port number
  21482.  
  21483. %@NL@%
  21484. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21485. %@NL@%
  21486. The %@AB@%inp%@AE@% and %@AB@%inpw%@AE@% functions read a byte and a word, respectively, from the
  21487. specified input port. The input value can be any unsigned integer in the
  21488. range 0 - 65,535.  %@NL@%
  21489. %@NL@%
  21490. To use %@AB@%inp%@AE@% and %@AB@%inpw%@AE@% in OS/2 protected mode, you must use a .DEF file to
  21491. declare the IOSEG segment that the run-time library uses to perform
  21492. input/output on the port. In addition, the intrinsic (/Oi) versions of these
  21493. functions do not work unless you put the code in a segment that is marked
  21494. with the %@AB@%IOPL%@AE@% keyword in the .DEF file.  %@NL@%
  21495. %@NL@%
  21496. Because you cannot do IOPL from a regular code segment, the run-time library
  21497. declares a separate code segment called %@AB@%_IOSEG%@AE@%. In order to use %@AB@%inp%@AE@%, %@AB@%inpw%@AE@%,
  21498. %@AB@%outp%@AE@%, or %@AB@%outpw%@AE@% in any of the protected-mode run-time libraries (?LIBCP,
  21499. LLIBCDLL, LLIBCMT, or CDLLOBJS-based DLL), you must have a .DEF file
  21500. containing this line:  %@NL@%
  21501. %@NL@%
  21502. %@AS@%  SEGMENTS _IOSEG CLASS 'IOSEG_CODE' IOPL%@AE@%%@NL@%
  21503. %@NL@%
  21504. %@NL@%
  21505. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21506. %@NL@%
  21507. The functions return the byte or word read from %@AI@%port%@AE@%. There is no error
  21508. return.  %@NL@%
  21509. %@NL@%
  21510. %@NL@%
  21511. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21512. %@NL@%
  21513.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS2   UNIX   XENIX%@NL@%
  21514. %@NL@%
  21515. %@NL@%
  21516. %@NL@%
  21517. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21518. %@NL@%
  21519. %@AB@%outp%@AE@%, %@AB@%outpw%@AE@%  %@NL@%
  21520. %@NL@%
  21521. %@NL@%
  21522. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21523. %@NL@%
  21524. See the example for %@AB@%outp%@AE@%.  %@NL@%
  21525. %@NL@%
  21526. %@NL@%
  21527. %@NL@%
  21528. %@NL@%
  21529. %@QR:int86@%%@NL@%
  21530. %@2@%%@CR:C6A01720849 @%%@AB@%int86%@AE@%%@EH@%%@NL@%
  21531. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21532. %@NL@%
  21533. %@NL@%
  21534. %@3@%%@AB@%Description%@CR:C6A01720850 @%%@CR:C6A01720851 @% %@CR:C6A01720852 @% %@CR:C6A01720853 @%%@AE@%%@EH@%%@NL@%
  21535. %@NL@%
  21536. Executes the 8086 interrupt.  %@NL@%
  21537. %@NL@%
  21538. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  21539. %@NL@%
  21540. %@AS@%  int int86( int intnum, union REGS *inregs, union REGS *outregs );%@AE@%%@NL@%
  21541. %@NL@%
  21542. %@AI@%intnum%@AE@%                            Interrupt number
  21543.  
  21544. %@AI@%inregs%@AE@%                            Register values on call
  21545.  
  21546. %@AI@%outregs%@AE@%                           Register values on return
  21547.  
  21548. %@NL@%
  21549. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21550. %@NL@%
  21551. The %@AB@%int86%@AE@% function executes the 8086-processor-family interrupt specified by
  21552. the interrupt number %@AI@%intnum%@AE@%. Before executing the interrupt, %@AB@%int86%@AE@% copies
  21553. the contents of %@AI@%inregs%@AE@% to the corresponding registers. After the interrupt
  21554. returns, the function copies the current register values to %@AI@%outregs%@AE@%. It also
  21555. copies the status of the system carry flag to the %@AB@%cflag%@AE@% field in the %@AI@%outregs%@AE@%
  21556. argument. The %@AI@%inregs%@AE@% and %@AI@%outregs%@AE@% arguments are unions of type %@AB@%REGS%@AE@%. The
  21557. union type is defined in the include file DOS.H.  %@NL@%
  21558. %@NL@%
  21559. Do not use the %@AB@%int86%@AE@% function to call interrupts that modify the DS
  21560. register. Instead, use the %@AB@%int86x%@AE@% function. The %@AB@%int86x%@AE@% function loads the DS
  21561. and ES registers from the %@AI@%segregs%@AE@% parameter and also stores the DS and ES
  21562. registers into %@AI@%segregs%@AE@% after the function call.  %@NL@%
  21563. %@NL@%
  21564. The %@AB@%REGS%@AE@% type is defined in the include file DOS.H.  %@NL@%
  21565. %@NL@%
  21566. %@NL@%
  21567. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21568. %@NL@%
  21569. The return value is the value in the AX register after the interrupt
  21570. returns. If the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@% is nonzero, an error has occurred; in
  21571. such cases, the %@AB@%_doserrno%@AE@% variable is also set to the corresponding error
  21572. code.  %@NL@%
  21573. %@NL@%
  21574. %@NL@%
  21575. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21576. %@NL@%
  21577.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  21578. %@NL@%
  21579. %@NL@%
  21580. %@NL@%
  21581. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21582. %@NL@%
  21583. %@AB@%bdos%@AE@%, %@AB@%int86x%@AE@%,%@AB@% intdos%@AE@%, %@AB@%intdosx%@AE@%  %@NL@%
  21584. %@NL@%
  21585. %@NL@%
  21586. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21587. %@NL@%
  21588. %@AS@%  /* INT86.C: This program uses int86 to call the BIOS video service
  21589. %@AS@%   * (INT 10H) to get information about the cursor.
  21590. %@AS@%   */
  21591. %@AS@%  
  21592. %@AS@%  #include <dos.h>
  21593. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  21594. %@NL@%
  21595. %@AS@%  void main()
  21596. %@AS@%  {
  21597. %@AS@%     union REGS inregs, outregs;
  21598. %@AS@%  
  21599. %@AS@%     /* Set up to get cursor information. */
  21600. %@AS@%     inregs.h.ah = 3;       /* Get Cursor Position function */
  21601. %@AS@%     inregs.h.bh = 0;       /* Page 0 */
  21602. %@AS@%  
  21603. %@AS@%     /* Execute video interrupt: */
  21604. %@AS@%     int86( 0x10, &inregs, &outregs );
  21605. %@AS@%  
  21606. %@AS@%     /* Display results. */
  21607. %@AS@%     printf( "Cursor position\n\tRow: %d\n\tColumn: %d\n",
  21608. %@AS@%             outregs.h.dh, outregs.h.dl );
  21609. %@AS@%     printf( "Cursor shape\n\tStart: %d\n\tEnd: %d\n",
  21610. %@AS@%             outregs.h.ch, outregs.h.cl );
  21611. %@AS@%  }%@AE@%%@NL@%
  21612. %@NL@%
  21613. %@NL@%
  21614. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21615. %@NL@%
  21616. %@AS@%  
  21617. %@AS@%  
  21618. %@AS@%  Cursor position
  21619. %@AS@%          Row: 2
  21620. %@AS@%          Column: 0
  21621. %@AS@%  Cursor shape
  21622. %@AS@%          Start: 6
  21623. %@AS@%          End: 7%@AE@%%@NL@%
  21624. %@NL@%
  21625. %@NL@%
  21626. %@NL@%
  21627. %@NL@%
  21628. %@QR:int86x@%%@NL@%
  21629. %@2@%%@CR:C6A01730854 @%%@AB@%int86x%@AE@%%@EH@%%@NL@%
  21630. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21631. %@NL@%
  21632. %@NL@%
  21633. %@3@%%@AB@%Description%@CR:C6A01730855 @%%@CR:C6A01730856 @% %@CR:C6A01730857 @%%@CR:C6A01730858 @%%@AE@%%@EH@%%@NL@%
  21634. %@NL@%
  21635. Executes the 8086 interrupt; accepts segment-register values.  %@NL@%
  21636. %@NL@%
  21637. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  21638. %@NL@%
  21639. %@AS@%  int int86x( int intnum, union REGS *inregs, union REGS *outregs, 
  21640. %@AS@%  struct SREGS *segregs );%@AE@%%@NL@%
  21641. %@NL@%
  21642. %@AI@%intnum%@AE@%                            Interrupt number
  21643.  
  21644. %@AI@%inregs%@AE@%                            Register values on call
  21645.  
  21646. %@AI@%outregs%@AE@%                           Register values on return
  21647.  
  21648. %@AI@%segregs%@AE@%                           Segment-register values on call
  21649.  
  21650. %@NL@%
  21651. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21652. %@NL@%
  21653. The %@AB@%int86x%@AE@% function executes the 8086-processor-family interrupt specified
  21654. by the interrupt number %@AI@%intnum%@AE@%. Unlike the %@AB@%int86%@AE@% function, %@AB@%int86x%@AE@% accepts
  21655. segment-register values in %@AI@%segregs%@AE@%, enabling programs that use large-model
  21656. data segments or far pointers to specify which segment or pointer should be
  21657. used during the system call.  %@NL@%
  21658. %@NL@%
  21659. Before executing the specified interrupt, %@AB@%int86x%@AE@% copies the contents of
  21660. %@AI@%inregs%@AE@% and %@AI@%segregs%@AE@% to the corresponding registers. Only the DS and ES
  21661. register values in %@AI@%segregs%@AE@% are used. After the interrupt returns, the
  21662. function copies the current register values to %@AI@%outregs%@AE@%, cop-ies the current
  21663. ES and DS values to %@AI@%segregs%@AE@%, and restores DS. It also copies the status of
  21664. the system carry flag to the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@%.  %@NL@%
  21665. %@NL@%
  21666. The %@AB@%REGS%@AE@% and %@AB@%SREGS%@AE@% types are defined in the include file DOS.H.  %@NL@%
  21667. %@NL@%
  21668. Segment values for the %@AI@%segregs%@AE@% argument can be obtained by using either the
  21669. %@AB@%segread%@AE@% function or the %@AB@%FP_SEG%@AE@% macro.  %@NL@%
  21670. %@NL@%
  21671. %@NL@%
  21672. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21673. %@NL@%
  21674. The return value is the value in the AX register after the interrupt
  21675. returns. If the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@% is nonzero, an error has occurred; in
  21676. such cases, the %@AB@%_doserrno%@AE@% variable is also set to the corresponding error
  21677. code.  %@NL@%
  21678. %@NL@%
  21679. %@NL@%
  21680. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21681. %@NL@%
  21682.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  21683. %@NL@%
  21684. %@NL@%
  21685. %@NL@%
  21686. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21687. %@NL@%
  21688. %@AB@%bdos, FP_SEG%@AE@%, %@AB@%int86%@AE@%,%@AB@% intdos%@AE@%, %@AB@%intdosx%@AE@%, %@AB@%segread%@AE@%  %@NL@%
  21689. %@NL@%
  21690. %@NL@%
  21691. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21692. %@NL@%
  21693. %@AS@%  /* INT86X.C: In this program, int86x executes an INT 21H instruction
  21694. %@AS@%   * to invoke DOS system call 43H (change file attributes). The program
  21695. %@AS@%   * uses int86x because the file, which is referenced with a far pointer,
  21696. %@AS@%   * may be in a segment other than the default data segment. Thus, the
  21697. %@AS@%   * program must explicitly set the DS register with the SREGS structure.
  21698. %@AS@%   */
  21699. %@AS@%  
  21700. %@AS@%  #include <signal.h>
  21701. %@AS@%  #include <dos.h>
  21702. %@AS@%  #include <stdio.h>
  21703. %@AS@%  #include <process.h>
  21704. %@AS@%  
  21705. %@AS@%  char _far *filename = "int86x.c";
  21706. %@AS@%  
  21707. %@AS@%  void main()
  21708. %@AS@%  {
  21709. %@AS@%     union  REGS inregs, outregs;
  21710. %@AS@%     struct SREGS segregs;
  21711. %@AS@%     int    result;
  21712. %@AS@%  
  21713. %@AS@%     inregs.h.ah = 0x43;      /* DOS function to change attributes    */
  21714. %@AS@%     inregs.h.al = 0;         /* Subfunction 0 to get attributes)     */
  21715. %@AS@%     inregs.x.dx = FP_OFF( filename );   /* DS:DX points to file name */
  21716. %@AS@%     segregs.ds  = FP_SEG( filename );
  21717. %@AS@%     result = int86x( 0x21, &inregs, &outregs, &segregs );
  21718. %@AS@%     if( outregs.x.cflag )
  21719. %@AS@%        printf( "Can't get file attributes; error no. %d\n", result);
  21720. %@AS@%     else
  21721. %@AS@%        printf( "Attribs = 0x%.4x\n", outregs.x.cx );
  21722. %@AS@%  }%@AE@%%@NL@%
  21723. %@NL@%
  21724. %@NL@%
  21725. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21726. %@NL@%
  21727. %@AS@%  
  21728. %@AS@%  
  21729. %@AS@%  Attribs = 0x0020%@AE@%%@NL@%
  21730. %@NL@%
  21731. %@NL@%
  21732. %@NL@%
  21733. %@NL@%
  21734. %@QR:intdos@%%@NL@%
  21735. %@2@%%@CR:C6A01740859 @%%@AB@%intdos%@AE@%%@EH@%%@NL@%
  21736. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21737. %@NL@%
  21738. %@NL@%
  21739. %@3@%%@AB@%Description%@CR:C6A01740860 @%%@CR:C6A01740861 @% %@CR:C6A01740862 @%%@CR:C6A01740863 @%%@AE@%%@EH@%%@NL@%
  21740. %@NL@%
  21741. Executes the DOS system call.  %@NL@%
  21742. %@NL@%
  21743. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  21744. %@NL@%
  21745. %@AS@%  int intdos( union REGS *inregs, union REGS *outregs );%@AE@%%@NL@%
  21746. %@NL@%
  21747. %@AI@%inregs%@AE@%                            Register values on call
  21748.  
  21749. %@AI@%outregs%@AE@%                           Register values on return
  21750.  
  21751. %@NL@%
  21752. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21753. %@NL@%
  21754. The %@AB@%intdos%@AE@% function invokes the DOS system call specified by register values
  21755. defined in %@AI@%inregs%@AE@% and returns the effect of the system call in %@AI@%outregs%@AE@%. The
  21756. %@AI@%inregs%@AE@% and %@AI@%outregs%@AE@% arguments are unions of type %@AB@%REGS%@AE@%. The %@AB@%REGS %@AE@%type is
  21757. defined in the include file DOS.H.  %@NL@%
  21758. %@NL@%
  21759. To invoke a system call, %@AB@%intdos%@AE@% executes an INT 21H instruction. Before
  21760. executing the instruction, the function copies the contents of %@AI@%inregs%@AE@% to the
  21761. corresponding registers. After the INT instruction returns, %@AB@%intdos%@AE@% copies
  21762. the current register values to %@AI@%outregs%@AE@%. It also copies the status of the
  21763. system carry flag to the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@%. A nonzero %@AB@%cflag%@AE@% field
  21764. indicates the flag was set by the system call and also indicates an error
  21765. condition.  %@NL@%
  21766. %@NL@%
  21767. The %@AB@%intdos%@AE@% function is used to invoke DOS system calls that take arguments
  21768. for input or output in registers other than DX (DH/DL) and AL. The %@AB@%intdos%@AE@%
  21769. function is also used to invoke system calls that indicate errors by setting
  21770. the carry flag. Under any other conditions, the %@AB@%bdos%@AE@% function can be used.  %@NL@%
  21771. %@NL@%
  21772. Do not use the %@AB@%intdos%@AE@% function to call interrupts that modify the DS
  21773. register. Instead, use the %@AB@%intdosx%@AE@% or %@AB@%int86x%@AE@% function.  %@NL@%
  21774. %@NL@%
  21775. %@NL@%
  21776. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21777. %@NL@%
  21778. The %@AB@%intdos%@AE@% function returns the value of the AX register after the system
  21779. call is completed. If the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@% is nonzero, an error has
  21780. occurred and %@AB@%_doserrno%@AE@% is also set to the corresponding error code.  %@NL@%
  21781. %@NL@%
  21782. %@NL@%
  21783. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21784. %@NL@%
  21785.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  21786. %@NL@%
  21787. %@NL@%
  21788. %@NL@%
  21789. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21790. %@NL@%
  21791. %@AB@%bdos%@AE@%, %@AB@%intdosx%@AE@%  %@NL@%
  21792. %@NL@%
  21793. %@NL@%
  21794. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21795. %@NL@%
  21796. %@AS@%  /* INTDOS.C: This program uses intdos to invoke DOS system call 2AH
  21797. %@AS@%   * (gets the current date).
  21798. %@AS@%   */
  21799. %@AS@%  
  21800. %@AS@%  #include <dos.h>
  21801. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  21802. %@NL@%
  21803. %@AS@%  void main()
  21804. %@AS@%  {
  21805. %@AS@%     union REGS inregs, outregs;
  21806. %@AS@%  
  21807. %@AS@%     inregs.h.ah = 0x2a;           /* DOS Get Date function: */
  21808. %@AS@%     intdos( &inregs, &outregs );
  21809. %@AS@%     printf( "Date: %d/%d/%d\n", outregs.h.dh, outregs.h.dl, outregs.x.cx );
  21810. %@AS@%  }%@AE@%%@NL@%
  21811. %@NL@%
  21812. %@NL@%
  21813. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21814. %@NL@%
  21815. %@AS@%  
  21816. %@AS@%  
  21817. %@AS@%  Date: 6/16/1989%@AE@%%@NL@%
  21818. %@NL@%
  21819. %@NL@%
  21820. %@NL@%
  21821. %@NL@%
  21822. %@QR:intdosx@%%@NL@%
  21823. %@2@%%@CR:C6A01750864 @%%@AB@%intdosx%@AE@%%@EH@%%@NL@%
  21824. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21825. %@NL@%
  21826. %@NL@%
  21827. %@3@%%@AB@%Description%@CR:C6A01750865 @%%@CR:C6A01750866 @% %@CR:C6A01750867 @%%@CR:C6A01750868 @%%@AE@%%@EH@%%@NL@%
  21828. %@NL@%
  21829. Executes the DOS system call; accepts segment-register values.  %@NL@%
  21830. %@NL@%
  21831. %@AS@%  #include <dos.h>%@AE@%%@NL@%
  21832. %@NL@%
  21833. %@AS@%  int intdosx( union REGS *inregs, union REGS *outregs, struct SREGS
  21834. %@AS@%  *segregs );%@AE@%%@NL@%
  21835. %@NL@%
  21836. %@AI@%inregs%@AE@%                            Register values on call
  21837.  
  21838. %@AI@%outregs%@AE@%                           Register values on return
  21839.  
  21840. %@AI@%segregs%@AE@%                           Segment-register values on call
  21841.  
  21842. %@NL@%
  21843. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21844. %@NL@%
  21845. The %@AB@%intdosx%@AE@% function invokes the DOS system call specified by register
  21846. values defined in %@AI@%inregs%@AE@% and returns the results of the system call in
  21847. %@AI@%outregs%@AE@%. Unlike the %@AB@%intdos%@AE@% function, %@AB@%intdosx%@AE@% accepts segment-register values
  21848. in %@AI@%segregs%@AE@%, enabling programs that use large-model data segments or far
  21849. pointers to specify which segment or pointer should be used during the
  21850. system call. The %@AB@%REGS%@AE@% and %@AB@%SREGS%@AE@% types are defined in the include file DOS.H.
  21851. %@NL@%
  21852. %@NL@%
  21853. To invoke a system call, %@AB@%intdosx%@AE@% executes an INT 21H instruction. Before
  21854. executing the instruction, the function copies the contents of %@AI@%inregs%@AE@% and
  21855. %@AI@%segregs%@AE@% to the corresponding registers. Only the DS and ES register values
  21856. in %@AI@%segregs%@AE@% are used. After the INT instruction returns, %@AB@%intdosx%@AE@% copies the
  21857. current register values to %@AI@%outregs%@AE@% and restores DS. It also copies the
  21858. status of the system carry flag to the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@%. A nonzero
  21859. %@AB@%cflag%@AE@% field indicates the flag was set by the system call and also indicates
  21860. an error condition.  %@NL@%
  21861. %@NL@%
  21862. The %@AB@%intdosx%@AE@% function is used to invoke DOS system calls that take an
  21863. argument in the ES register or that take a DS register value different from
  21864. the default data segment.  %@NL@%
  21865. %@NL@%
  21866. Segment values for the %@AI@%segregs%@AE@% argument can be obtained by using either the
  21867. %@AB@%segread %@AE@%function or the %@AB@%FP_SEG%@AE@% macro.  %@NL@%
  21868. %@NL@%
  21869. %@NL@%
  21870. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  21871. %@NL@%
  21872. The %@AB@%intdosx%@AE@% function returns the value of the AX register after the system
  21873. call is completed. If the %@AB@%cflag%@AE@% field in %@AI@%outregs%@AE@% is nonzero, an error has
  21874. occurred; in such cases, %@AB@%_doserrno%@AE@% is also set to the corresponding error
  21875. code.  %@NL@%
  21876. %@NL@%
  21877. %@NL@%
  21878. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  21879. %@NL@%
  21880.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  21881. %@NL@%
  21882. %@NL@%
  21883. %@NL@%
  21884. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  21885. %@NL@%
  21886. %@AB@%bdos%@AE@%, %@AB@%FP_SEG%@AE@%, %@AB@%intdos%@AE@%, %@AB@%segread%@AE@%  %@NL@%
  21887. %@NL@%
  21888. %@NL@%
  21889. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  21890. %@NL@%
  21891. %@AS@%  /* INTDOSX.C */
  21892. %@AS@%  #include <dos.h>
  21893. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  21894. %@NL@%
  21895. %@AS@%  char _far *buffer = "Dollar-sign terminated string\n\r\n\r$";
  21896. %@AS@%  
  21897. %@AS@%  void main()
  21898. %@AS@%  {
  21899. %@AS@%     union  REGS inregs, outregs;
  21900. %@AS@%     struct SREGS segregs;
  21901. %@AS@%  
  21902. %@AS@%     /* Print a $-terminated string on the screen using DOS function 0x09.
  21903. %@AS@%*/
  21904. %@AS@%     inregs.h.ah = 0x9;
  21905. %@AS@%     inregs.x.dx = FP_OFF( buffer );
  21906. %@AS@%     segregs.ds  = FP_SEG( buffer );
  21907. %@AS@%     intdosx( &inregs, &outregs, &segregs );
  21908. %@AS@%  }%@AE@%%@NL@%
  21909. %@NL@%
  21910. %@NL@%
  21911. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  21912. %@NL@%
  21913. %@AS@%  
  21914. %@AS@%  
  21915. %@AS@%  Dollar-sign terminated string%@AE@%%@NL@%
  21916. %@NL@%
  21917. %@NL@%
  21918. %@NL@%
  21919. %@NL@%
  21920. %@QR:is@%%@NL@%
  21921. %@2@%%@CR:C6A01760869 @%%@AB@%is Functions%@AE@%%@EH@%%@NL@%
  21922. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21923. %@NL@%
  21924. %@NL@%
  21925. %@3@%%@AB@%Description%@CR:C6A01760870 @%%@CR:C6A01760871 @% %@CR:C6A01760872 @% %@CR:C6A01760873 @%%@CR:C6A01760874 @%%@CR:C6A01760875 @%%@CR:C6A01760876 @% %@CR:C6A01760877 @%%@CR:C6A01760878 @% %@CR:C6A01760879 @% %@CR:C6A01760880 @% %@EH@%
  21926. %@AB@%%@CR:C6A01760881 @% %@CR:C6A01760882 @% %@CR:C6A01760883 @% %@CR:C6A01760884 @% %@CR:C6A01760885 @%%@CR:C6A01760886 @%%@AE@%%@NL@%
  21927. %@NL@%
  21928. Test characters for specified conditions.  %@NL@%
  21929. %@NL@%
  21930. %@AS@%  #include <ctype.h>%@AE@%%@NL@%
  21931. %@NL@%
  21932. %@AS@%  int isalnum( int c );%@AE@%%@NL@%
  21933. %@NL@%
  21934. %@AS@%  int isalpha( int c );%@AE@%%@NL@%
  21935. %@NL@%
  21936. %@AS@%  int isascii( int c );%@AE@%%@NL@%
  21937. %@NL@%
  21938. %@AS@%  int iscntrl( int c );%@AE@%%@NL@%
  21939. %@NL@%
  21940. %@AS@%  int isdigit( int c );%@AE@%%@NL@%
  21941. %@NL@%
  21942. %@AS@%  int isgraph( int c );%@AE@%%@NL@%
  21943. %@NL@%
  21944. %@AS@%  int islower( int c );%@AE@%%@NL@%
  21945. %@NL@%
  21946. %@AS@%  int isprint( int c );%@AE@%%@NL@%
  21947. %@NL@%
  21948. %@AS@%  int ispunct( int c );%@AE@%%@NL@%
  21949. %@NL@%
  21950. %@AS@%  int isspace( int c );%@AE@%%@NL@%
  21951. %@NL@%
  21952. %@AS@%  int isupper( int c );%@AE@%%@NL@%
  21953. %@NL@%
  21954. %@AS@%  int isxdigit( int c );%@AE@%%@NL@%
  21955. %@NL@%
  21956. %@AI@%c%@AE@%                                 Integer to be tested
  21957.  
  21958. %@NL@%
  21959. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  21960. %@NL@%
  21961. Each function in the %@AB@%is%@AE@% family tests a given integer value, returning a
  21962. nonzero value if the integer satisfies the test condition and 0 if it does
  21963. not. The ASCII character set is assumed.  %@NL@%
  21964. %@NL@%
  21965. The %@AB@%is%@AE@% functions and their test conditions are listed below:  %@NL@%
  21966. %@NL@%
  21967. %@AB@%Function%@AE@%                          %@AB@%Test Condition%@AE@%
  21968. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  21969. %@AB@%isalnum%@AE@%                           Alphanumeric ('A'-'Z', 'a'-'z', or 
  21970.                                   '0'-'9')
  21971.  
  21972. %@AB@%isalpha%@AE@%                           Letter ('A'-'Z' or 'a'-'z')
  21973.  
  21974. %@AB@%isascii%@AE@%                           ASCII character (0x00 - 0x7F)
  21975.  
  21976. %@AB@%iscntrl%@AE@%                           Control character (0x00 - 0x1F or 0x7F)
  21977.  
  21978. %@AB@%isdigit%@AE@%                           Digit ('0'-'9')
  21979.  
  21980. %@AB@%isgraph%@AE@%                           Printable character except space (' ')
  21981.  
  21982. %@AB@%islower%@AE@%                           Lowercase letter ('a'-'z')
  21983.  
  21984. %@AB@%isprint%@AE@%                           Printable character (0x20 - 0x7E)
  21985.  
  21986. %@AB@%ispunct%@AE@%                           Punctuation character
  21987.  
  21988. %@AB@%isspace%@AE@%                           White-space character (0x09 - 0x0D or 
  21989.                                   0x20)
  21990.  
  21991. %@AB@%isupper%@AE@%                           Uppercase letter ('A'-'Z')
  21992.  
  21993. %@AB@%isxdigit%@AE@%                          Hexadecimal digit ('A'-'F','a'-'f', or 
  21994.                                   '0'-'9')
  21995.  
  21996. The %@AB@%isascii%@AE@% routine produces meaningful results for all integer values.
  21997. However, the remaining routines produce a defined result only for integer
  21998. values corresponding to the ASCII character set (that is, only where %@AB@%isascii%@AE@%
  21999. holds true) or for the non-ASCII value %@AB@%EOF%@AE@% (defined in STDIO.H).  %@NL@%
  22000. %@NL@%
  22001. These routines are implemented both as functions and as macros. For details
  22002. on choosing a function or a macro implementation, see Section 1.4, "Choosing
  22003. Between Functions and Macros."  %@NL@%
  22004. %@NL@%
  22005. %@NL@%
  22006. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22007. %@NL@%
  22008. These routines return a nonzero value if the integer satisfies the test
  22009. condition and 0 if it does not.  %@NL@%
  22010. %@NL@%
  22011. %@NL@%
  22012. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22013. %@NL@%
  22014. %@AB@%isalnum%@AE@%,%@AB@% isalpha%@AE@%, %@AB@%iscntrl%@AE@%, %@AB@%isdigit%@AE@%, %@AB@%isgraph%@AE@%, %@AB@%islower%@AE@%, %@AB@%isprint%@AE@%, %@AB@%ispunct%@AE@%,
  22015. %@AB@%isspace%@AE@%, %@AB@%isupper%@AE@%, %@AB@%isxdigit%@AE@%  %@NL@%
  22016. %@NL@%
  22017. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  22018. %@NL@%
  22019. %@NL@%
  22020. %@AB@%isascii%@AE@%  %@NL@%
  22021. %@NL@%
  22022.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  22023. %@NL@%
  22024. %@NL@%
  22025. %@NL@%
  22026. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22027. %@NL@%
  22028. %@AB@%toascii%@AE@%, %@AB@%tolower%@AE@%,%@AB@% toupper %@AE@%functions%@AB@%  %@AE@%%@NL@%
  22029. %@NL@%
  22030. %@NL@%
  22031. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22032. %@NL@%
  22033. %@AS@%  /* ISFAM.C: This program tests all characters between 0x0 and 0x7F,
  22034. %@AS@%   * then displays each character with abbreviations for the character-type
  22035. %@AS@%   * codes that apply.
  22036. %@AS@%   */
  22037. %@AS@%  
  22038. %@AS@%  #include <stdio.h>
  22039. %@AS@%  #include <ctype.h>%@AE@%%@NL@%
  22040. %@NL@%
  22041. %@AS@%  void main()
  22042. %@AS@%  {
  22043. %@AS@%     int ch;
  22044. %@AS@%     for( ch = 0; ch <= 0x7F; ch++ )
  22045. %@AS@%     {
  22046. %@AS@%        printf( "%.2x ", ch );
  22047. %@AS@%        printf( " %c", isprint( ch )  ? ch   : '\0' );
  22048. %@AS@%        printf( "%4s", isalnum( ch )  ? "AN" : "" );
  22049. %@AS@%        printf( "%3s", isalpha( ch )  ? "A"  : "" );
  22050. %@AS@%        printf( "%3s", isascii( ch )  ? "AS" : "" );
  22051. %@AS@%        printf( "%3s", iscntrl( ch )  ? "C"  : "" );
  22052. %@AS@%        printf( "%3s", isdigit( ch )  ? "D"  : "" );
  22053. %@AS@%        printf( "%3s", isgraph( ch )  ? "G"  : "" );
  22054. %@AS@%        printf( "%3s", islower( ch )  ? "L"  : "" );
  22055. %@AS@%        printf( "%3s", ispunct( ch )  ? "PU" : "" );
  22056. %@AS@%        printf( "%3s", isspace( ch )  ? "S"  : "" );
  22057. %@AS@%        printf( "%3s", isprint( ch )  ? "PR" : "" );
  22058. %@AS@%        printf( "%3s", isupper( ch )  ? "U"  : "" );
  22059. %@AS@%        printf( "%3s", isxdigit( ch ) ? "X"  : "" );
  22060. %@AS@%        printf( "\n" );
  22061. %@AS@%     }
  22062. %@AS@%  }%@AE@%%@NL@%
  22063. %@NL@%
  22064. %@NL@%
  22065. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22066. %@NL@%
  22067. %@AS@%  
  22068. %@AS@%  
  22069. %@AS@%  00          AS  C
  22070. %@AS@%  01          AS  C
  22071. %@AS@%  02          AS  C
  22072. %@AS@%  .
  22073. %@AS@%  .
  22074. %@AS@%  .
  22075. %@AS@%  38  8  AN    AS     D  G          PR     X
  22076. %@AS@%  39  9  AN    AS     D  G          PR     X
  22077. %@AS@%  3a  :        AS        G    PU    PR
  22078. %@AS@%  3b  ;        AS        G    PU    PR
  22079. %@AS@%  3c  <        AS        G    PU    PR
  22080. %@AS@%  3d  =        AS        G    PU    PR
  22081. %@AS@%  3e  >        AS        G    PU    PR
  22082. %@AS@%  3f  ?        AS        G    PU    PR
  22083. %@AS@%  40  @        AS        G    PU    PR
  22084. %@AS@%  41  A  AN  A AS        G          PR  U  X
  22085. %@AS@%  42  B  AN  A AS        G          PR  U  X
  22086. %@AS@%  .
  22087. %@AS@%  .
  22088. %@AS@%  .%@AE@%%@NL@%
  22089. %@NL@%
  22090. %@NL@%
  22091. %@NL@%
  22092. %@NL@%
  22093. %@QR:isatty@%%@NL@%
  22094. %@2@%%@CR:C6A01770887 @%%@AB@%isatty%@AE@%%@EH@%%@NL@%
  22095. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22096. %@NL@%
  22097. %@NL@%
  22098. %@3@%%@AB@%Description%@CR:C6A01770888 @%%@CR:C6A01770889 @%%@CR:C6A01770890 @% %@CR:C6A01770891 @%%@AE@%%@EH@%%@NL@%
  22099. %@NL@%
  22100. Checks for a character device.  %@NL@%
  22101. %@NL@%
  22102. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  22103.  
  22104. %@AS@%  int isatty( int handle );%@AE@%%@NL@%
  22105. %@NL@%
  22106. %@AI@%handle%@AE@%                            Handle referring to device to be tested
  22107.  
  22108. %@NL@%
  22109. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22110. %@NL@%
  22111. The %@AB@%isatty%@AE@% function determines whether %@AI@%handle%@AE@% is associated with a character
  22112. device (a terminal, console, printer, or serial port).  %@NL@%
  22113. %@NL@%
  22114. %@NL@%
  22115. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22116. %@NL@%
  22117. The %@AB@%isatty%@AE@% function returns a nonzero value if the device is a character
  22118. device. Otherwise, the return value is 0.  %@NL@%
  22119. %@NL@%
  22120. %@NL@%
  22121. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22122. %@NL@%
  22123.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  22124. %@NL@%
  22125. %@NL@%
  22126. %@NL@%
  22127. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22128. %@NL@%
  22129. %@AS@%  /* ISATTY.C: This program checks to see whether stdout has been
  22130. %@AS@%   * redirected to a file.
  22131. %@AS@%   */
  22132. %@AS@%  
  22133. %@AS@%  #include <stdio.h>
  22134. %@AS@%  #include <io.h>
  22135. %@AS@%  
  22136. %@AS@%  void main()
  22137. %@AS@%  {
  22138. %@AS@%     if( isatty( fileno( stdout ) ) )
  22139. %@AS@%        printf( "stdout has not been redirected to a file\n" );
  22140. %@AS@%     else
  22141. %@AS@%        printf( "stdout has been redirected to a file\n");
  22142. %@AS@%  }%@AE@%%@NL@%
  22143. %@NL@%
  22144. %@NL@%
  22145. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22146. %@NL@%
  22147. %@AS@%  
  22148. %@AS@%  
  22149. %@AS@%  stdout has not been redirected to a file%@AE@%%@NL@%
  22150. %@NL@%
  22151. %@NL@%
  22152. %@NL@%
  22153. %@NL@%
  22154. %@QR:itoa@%%@NL@%
  22155. %@2@%%@CR:C6A01780892 @%%@AB@%itoa%@AE@%%@EH@%%@NL@%
  22156. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22157. %@NL@%
  22158. %@NL@%
  22159. %@3@%%@AB@%Description%@CR:C6A01780893 @%%@CR:C6A01780894 @% %@CR:C6A01780895 @%%@CR:C6A01780896 @%%@AE@%%@EH@%%@NL@%
  22160. %@NL@%
  22161. Converts an integer to a string.  %@NL@%
  22162. %@NL@%
  22163. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  22164.  
  22165. %@AS@%  char *itoa( int value, char *string, int radix );%@AE@%%@NL@%
  22166. %@NL@%
  22167. %@AI@%value%@AE@%                             Number to be converted
  22168.  
  22169. %@AI@%string%@AE@%                            String result
  22170.  
  22171. %@AI@%radix%@AE@%                             Base of %@AI@%value%@AE@%
  22172.  
  22173. %@NL@%
  22174. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22175. %@NL@%
  22176. The %@AB@%itoa%@AE@% function converts the digits of the given %@AI@%value%@AE@% argument to a
  22177. null-terminated character string and stores the result (up to 17 bytes) in
  22178. %@AI@%string.%@AE@% The %@AI@%radix%@AE@% argument specifies the base of %@AI@%value%@AE@%; it must be in the
  22179. range 2-36. If %@AI@%radix%@AE@% equals 10 and %@AI@%value%@AE@% is negative, the first character of
  22180. the stored string is the minus sign (-).  %@NL@%
  22181. %@NL@%
  22182. %@NL@%
  22183. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22184. %@NL@%
  22185. The %@AB@%itoa%@AE@% function returns a pointer to %@AI@%string%@AE@%. There is no error return.  %@NL@%
  22186. %@NL@%
  22187. %@NL@%
  22188. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22189. %@NL@%
  22190.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  22191. %@NL@%
  22192. %@NL@%
  22193. %@NL@%
  22194. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22195. %@NL@%
  22196. %@AB@%ltoa%@AE@%, %@AB@%ultoa%@AE@%  %@NL@%
  22197. %@NL@%
  22198. %@NL@%
  22199. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22200. %@NL@%
  22201. %@AS@%  /* ITOA.C: This program converts integers of various sizes to strings
  22202. %@AS@%   * in various radixes.
  22203. %@AS@%   */
  22204. %@AS@%  
  22205. %@AS@%  #include <stdlib.h>
  22206. %@AS@%  #include <stdio.h>
  22207. %@AS@%  
  22208. %@AS@%  void main()
  22209. %@AS@%  {
  22210. %@AS@%     char buffer[20];
  22211. %@AS@%     int  i = 3445;
  22212. %@AS@%     long l = -344115L;
  22213. %@AS@%     unsigned long ul = 1234567890UL;%@AE@%%@NL@%
  22214. %@NL@%
  22215. %@AS@%  itoa( i, buffer, 10 );
  22216. %@AS@%     printf( "String of integer %d (radix 10): %s\n", i, buffer );
  22217. %@AS@%     itoa( i, buffer, 16 );
  22218. %@AS@%     printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
  22219. %@AS@%     itoa( i, buffer, 2  );
  22220. %@AS@%     printf( "String of integer %d (radix 2): %s\n", i, buffer );
  22221. %@AS@%  
  22222. %@AS@%     ltoa( l, buffer, 16 );
  22223. %@AS@%     printf( "String of long int %ld (radix 16): 0x%s\n", l, buffer );
  22224. %@AS@%  
  22225. %@AS@%     ultoa( ul, buffer, 16 );
  22226. %@AS@%     printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul, buffer );
  22227. %@AS@%  }%@AE@%%@NL@%
  22228. %@NL@%
  22229. %@NL@%
  22230. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22231. %@NL@%
  22232. %@AS@%  
  22233. %@AS@%  
  22234. %@AS@%  String of integer 3445 (radix 10): 3445
  22235. %@AS@%  String of integer 3445 (radix 16): 0xd75
  22236. %@AS@%  String of integer 3445 (radix 2): 110101110101
  22237. %@AS@%  String of long int -344115 (radix 16): 0xfffabfcd
  22238. %@AS@%  String of unsigned long 1234567890 (radix 16): 0x499602d2%@AE@%%@NL@%
  22239. %@NL@%
  22240. %@NL@%
  22241. %@NL@%
  22242. %@NL@%
  22243. %@QR:kbhit@%%@NL@%
  22244. %@2@%%@CR:C6A01790897 @%%@AB@%kbhit%@AE@%%@EH@%%@NL@%
  22245. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22246. %@NL@%
  22247. %@NL@%
  22248. %@3@%%@AB@%Description %@CR:C6A01790898 @%%@CR:C6A01790899 @% %@CR:C6A01790900 @% %@CR:C6A01790901 @%%@AE@%%@EH@%%@NL@%
  22249. %@NL@%
  22250. Checks the console for keyboard input.  %@NL@%
  22251. %@NL@%
  22252. %@AB@%#include <conio.h>%@AE@%                Required only for function declarations
  22253.  
  22254. %@AS@%  int kbhit( void );%@AE@%%@NL@%
  22255. %@NL@%
  22256. %@NL@%
  22257. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22258. %@NL@%
  22259. The %@AB@%kbhit%@AE@% function checks the console for a recent keystroke. If the
  22260. function returns a nonzero value, a keystroke is waiting in the buffer. The
  22261. program can then call %@AB@%getch%@AE@% or %@AB@%getche%@AE@% to get the keystroke.  %@NL@%
  22262. %@NL@%
  22263. %@NL@%
  22264. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22265. %@NL@%
  22266. The %@AB@%kbhit%@AE@% function returns a nonzero value if a key has been pressed.
  22267. Otherwise, it re-turns 0.  %@NL@%
  22268. %@NL@%
  22269. %@NL@%
  22270. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22271. %@NL@%
  22272.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  22273. %@NL@%
  22274. %@NL@%
  22275. %@NL@%
  22276. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22277. %@NL@%
  22278. %@AS@%  /* KBHIT.C: This program loops until the user presses a key.
  22279. %@AS@%   * If kbhit returns nonzero, a keystroke is waiting in the buffer.
  22280. %@AS@%   * The program can call getch or getche to get the keystroke.
  22281. %@AS@%   */
  22282. %@AS@%  
  22283. %@AS@%  #include <conio.h>
  22284. %@AS@%  #include <stdio.h>
  22285. %@AS@%  
  22286. %@AS@%  void main()
  22287. %@AS@%  {
  22288. %@AS@%     /* Display message until key is pressed. */
  22289. %@AS@%     while( !kbhit() )
  22290. %@AS@%        cputs( "Hit me!! " );
  22291. %@AS@%  
  22292. %@AS@%     /* Use getch to throw key away. */
  22293. %@AS@%     printf( "\nKey struck was '%c'\n", getch() );
  22294. %@AS@%     getch();
  22295. %@AS@%  }%@AE@%%@NL@%
  22296. %@NL@%
  22297. %@NL@%
  22298. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22299. %@NL@%
  22300. %@AS@%  
  22301. %@AS@%  
  22302. %@AS@%  Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!!
  22303. %@AS@%  Key struck was 'k'%@AE@%%@NL@%
  22304. %@NL@%
  22305. %@NL@%
  22306. %@NL@%
  22307. %@NL@%
  22308. %@QR:labs@%%@NL@%
  22309. %@2@%%@CR:C6A01800902 @%%@AB@%labs%@AE@%%@EH@%%@NL@%
  22310. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22311. %@NL@%
  22312. %@NL@%
  22313. %@3@%%@AB@%Description%@CR:C6A01800903 @%%@CR:C6A01800904 @%%@AE@%%@EH@%%@NL@%
  22314. %@NL@%
  22315. Calculates the absolute value of a long integer.  %@NL@%
  22316. %@NL@%
  22317. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  22318.  
  22319. %@AB@%#include <math.h>%@AE@%                 
  22320.  
  22321. %@AS@%  long labs( long n );%@AE@%%@NL@%
  22322. %@NL@%
  22323. %@AI@%n%@AE@%                                 Long-integer value
  22324.  
  22325. %@NL@%
  22326. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22327. %@NL@%
  22328. The %@AB@%labs%@AE@% function produces the absolute value of its long-integer argument
  22329. %@AI@%n%@AE@%.  %@NL@%
  22330. %@NL@%
  22331. %@NL@%
  22332. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22333. %@NL@%
  22334. The %@AB@%labs%@AE@% function returns the absolute value of its argument. There is no
  22335. error return.  %@NL@%
  22336. %@NL@%
  22337. %@NL@%
  22338. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22339. %@NL@%
  22340. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  22341. %@NL@%
  22342. %@NL@%
  22343. %@NL@%
  22344. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22345. %@NL@%
  22346. %@AB@%abs%@AE@%, %@AB@%cabs%@AE@%, %@AB@%fabs%@AE@%  %@NL@%
  22347. %@NL@%
  22348. %@NL@%
  22349. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22350. %@NL@%
  22351. %@AS@%  /* ABS.C: This program computes and displays the absolute values of
  22352. %@AS@%   * several numbers.
  22353. %@AS@%   */
  22354. %@AS@%  
  22355. %@AS@%  #include <stdio.h>
  22356. %@AS@%  #include <math.h>
  22357. %@AS@%  #include <stdlib.h>
  22358. %@AS@%  
  22359. %@AS@%  void main()
  22360. %@AS@%  {
  22361. %@AS@%     int    ix = -4, iy;
  22362. %@AS@%     long   lx = -41567L, ly;
  22363. %@AS@%     double dx = -3.141593, dy;
  22364. %@AS@%  
  22365. %@AS@%     iy = abs( ix );
  22366. %@AS@%     printf( "The absolute value of %d is %d\n", ix, iy);
  22367. %@AS@%  
  22368. %@AS@%     ly = labs( lx );
  22369. %@AS@%     printf( "The absolute value of %ld is %ld\n", lx, ly);
  22370. %@AS@%  
  22371. %@AS@%     dy = fabs( dx );
  22372. %@AS@%     printf( "The absolute value of %f is %f\n", dx, dy );
  22373. %@AS@%  }%@AE@%%@NL@%
  22374. %@NL@%
  22375. %@NL@%
  22376. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22377. %@NL@%
  22378. %@AS@%  
  22379. %@AS@%  
  22380. %@AS@%  The absolute value of -4 is 4
  22381. %@AS@%  The absolute value of -41567 is 41567
  22382. %@AS@%  The absolute value of -3.141593 is 3.141593%@AE@%%@NL@%
  22383. %@NL@%
  22384. %@NL@%
  22385. %@NL@%
  22386. %@NL@%
  22387. %@QR:ldexp@%%@QR:ldexpl@%%@NL@%
  22388. %@2@%%@CR:C6A01810905 @%%@AB@%ldexp, ldexpl%@AE@%%@EH@%%@NL@%
  22389. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22390. %@NL@%
  22391. %@NL@%
  22392. %@3@%%@AB@%Description%@CR:C6A01810906 @%%@CR:C6A01810907 @%%@CR:C6A01810908 @% %@CR:C6A01810909 @%%@AE@%%@EH@%%@NL@%
  22393. %@NL@%
  22394. Compute a real number from the mantissa and exponent.  %@NL@%
  22395. %@NL@%
  22396. %@AS@%  #include <math.h>%@AE@%%@NL@%
  22397. %@NL@%
  22398. %@AS@%  double ldexp( double x, int exp );%@AE@%%@NL@%
  22399. %@NL@%
  22400. %@AS@%  long double ldexpl( long double x, int exp );%@AE@%%@NL@%
  22401. %@NL@%
  22402. %@AI@%x%@AE@%                                 Floating-point value
  22403.  
  22404. %@AI@%exp%@AE@%                               Integer exponent
  22405.  
  22406. %@NL@%
  22407. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22408. %@NL@%
  22409. The %@AB@%ldexp%@AE@% and %@AB@%ldexpl%@AE@% functions calculate the value of %@AI@%x%@AE@% * 2exp.  %@NL@%
  22410. %@NL@%
  22411. %@NL@%
  22412. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22413. %@NL@%
  22414. The %@AB@%ldexp%@AE@% and %@AB@%ldexpl%@AE@% functions return %@AI@%x *%@AE@% 2exp. If an overflow results, the
  22415. functions return ± HUGE_VAL (depending on the sign of %@AI@%x%@AE@%) and set%@AB@% errno%@AE@% to
  22416. %@AB@%ERANGE%@AE@%.  %@NL@%
  22417. %@NL@%
  22418. The %@AB@%ldexpl %@AE@%function uses the 80-bit, 10-byte coprocessor form of arguments
  22419. and return values. See the reference page on the long double functions for
  22420. more details on this data type. %@AB@%  %@AE@%%@NL@%
  22421. %@NL@%
  22422. %@NL@%
  22423. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22424. %@NL@%
  22425. %@AB@%ldexp%@AE@%  %@NL@%
  22426. %@NL@%
  22427. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  22428. %@NL@%
  22429. %@NL@%
  22430. %@AB@%ldexpl%@AE@%  %@NL@%
  22431. %@NL@%
  22432.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  22433. %@NL@%
  22434. %@NL@%
  22435. %@NL@%
  22436. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22437. %@NL@%
  22438. %@AB@%frexp%@AE@%, %@AB@%modf%@AE@%  %@NL@%
  22439. %@NL@%
  22440. %@NL@%
  22441. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22442. %@NL@%
  22443. %@AS@%  /* LDEXP.C */
  22444. %@AS@%  #include <math.h>
  22445. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  22446. %@NL@%
  22447. %@AS@%  void main()
  22448. %@AS@%  {
  22449. %@AS@%     double x = 4.0, y;
  22450. %@AS@%     int p = 3;
  22451. %@AS@%  
  22452. %@AS@%     y = ldexp( x, p );
  22453. %@AS@%     printf( "%2.1f times two to the power of %d is %2.1f\n", x, p, y );
  22454. %@AS@%  }%@AE@%%@NL@%
  22455. %@NL@%
  22456. %@NL@%
  22457. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22458. %@NL@%
  22459. %@AS@%  
  22460. %@AS@%  
  22461. %@AS@%  4.0 times two to the power of 3 is 32.0 %@AE@%%@NL@%
  22462. %@NL@%
  22463. %@NL@%
  22464. %@NL@%
  22465. %@NL@%
  22466. %@QR:ldiv@%%@NL@%
  22467. %@2@%%@CR:C6A01820910 @%%@AB@%ldiv%@AE@%%@EH@%%@NL@%
  22468. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22469. %@NL@%
  22470. %@NL@%
  22471. %@3@%%@AB@%Description%@CR:C6A01820911 @%%@CR:C6A01820912 @%%@AE@%%@EH@%%@NL@%
  22472. %@NL@%
  22473. Computes the quotient and remainder of a long integer.  %@NL@%
  22474. %@NL@%
  22475. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  22476. %@NL@%
  22477. %@AS@%  ldiv_t ldiv ( long int numer, long int denom );%@AE@%%@NL@%
  22478. %@NL@%
  22479. %@AI@%numer%@AE@%                             Numerator
  22480.  
  22481. %@AI@%denom%@AE@%                             Denominator
  22482.  
  22483. %@NL@%
  22484. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22485. %@NL@%
  22486. The %@AB@%ldiv%@AE@% function divides %@AI@%numer%@AE@% by %@AI@%denom%@AE@%, computing the quotient and the
  22487. remainder. The sign of the quotient is the same as that of the mathematical
  22488. quotient. Its absolute value is the largest integer that is less than the
  22489. absolute value of the mathematical quotient. If the denominator is 0, the
  22490. program will terminate with an error message.  %@NL@%
  22491. %@NL@%
  22492. The %@AB@%ldiv%@AE@% function is similar to the %@AB@%div%@AE@% function, with the difference being
  22493. that the arguments and the members of the returned structure are all of type
  22494. %@AB@%long int%@AE@%.  %@NL@%
  22495. %@NL@%
  22496. The %@AB@%ldiv_t%@AE@% structure, defined in STDLIB.H, contains the following elements:
  22497. %@NL@%
  22498. %@NL@%
  22499. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  22500. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22501. %@AB@%long int quot%@AE@%                     Quotient
  22502.  
  22503. %@AB@%long int rem%@AE@%                      Remainder
  22504.  
  22505. %@NL@%
  22506. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22507. %@NL@%
  22508. The %@AB@%ldiv%@AE@% function returns a structure of type %@AB@%ldiv_t%@AE@%, comprising both the
  22509. quotient and the remainder.  %@NL@%
  22510. %@NL@%
  22511. %@NL@%
  22512. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22513. %@NL@%
  22514. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  22515. %@NL@%
  22516. %@NL@%
  22517. %@NL@%
  22518. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22519. %@NL@%
  22520. %@AB@%div%@AE@%  %@NL@%
  22521. %@NL@%
  22522. %@NL@%
  22523. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22524. %@NL@%
  22525. %@AS@%  /* LDIV.C: This program takes two long integers as command-line
  22526. %@AS@%   * arguments and displays the results of the integer division.
  22527. %@AS@%   */
  22528. %@AS@%  
  22529. %@AS@%  #include <stdlib.h>
  22530. %@AS@%  #include <math.h>
  22531. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  22532. %@NL@%
  22533. %@AS@%  void main()
  22534. %@AS@%  {
  22535. %@AS@%     long x = 5149627, y = 234879;
  22536. %@AS@%     ldiv_t div_result;
  22537. %@AS@%  
  22538. %@AS@%     div_result = ldiv( x, y );
  22539. %@AS@%     printf( "For %ld / %ld, the quotient is %ld, and the remainder is
  22540. %@AS@%%ld\n",
  22541. %@AS@%             x, y, div_result.quot, div_result.rem );
  22542. %@AS@%  }%@AE@%%@NL@%
  22543. %@NL@%
  22544. %@NL@%
  22545. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22546. %@NL@%
  22547. %@AS@%  
  22548. %@AS@%  
  22549. %@AS@%  For 5149627 / 234879, the quotient is 21, and the remainder is 217168%@AE@%%@NL@%
  22550. %@NL@%
  22551. %@NL@%
  22552. %@NL@%
  22553. %@NL@%
  22554. %@QR:lfind@%%@NL@%
  22555. %@2@%%@CR:C6A01830913 @%%@AB@%lfind%@AE@%%@EH@%%@NL@%
  22556. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22557. %@NL@%
  22558. %@NL@%
  22559. %@3@%%@AB@%Description%@CR:C6A01830914 @%%@CR:C6A01830915 @%%@CR:C6A01830916 @%%@AE@%%@EH@%%@NL@%
  22560. %@NL@%
  22561. Performs a linear search for the specified key.  %@NL@%
  22562. %@NL@%
  22563. %@AB@%#include <search.h>%@AE@%               Required only for function declarations
  22564.  
  22565. %@AS@%  char *lfind( const void *key, const void *base, unsigned int *num,
  22566. %@AS@%  unsigned int width, 
  22567. %@AS@%  int ( *compare )( const void *elem1, const void *elem2 ) );%@AE@%%@NL@%
  22568. %@NL@%
  22569. %@AI@%key%@AE@%                               Object to search for
  22570.  
  22571. %@AI@%base%@AE@%                              Pointer to base of search data
  22572.  
  22573. %@AI@%num%@AE@%                               Number of array elements
  22574.  
  22575. %@AI@%width%@AE@%                             Width of array elements
  22576.  
  22577. %@AI@%compare%@AE@%%@AB@%(%@AE@% %@AB@%)%@AE@%                        Pointer to comparison routine
  22578.  
  22579. %@AI@%elem1%@AE@%                             Pointer to the key for the search
  22580.  
  22581. %@AI@%elem2%@AE@%                             Pointer to the array element to be 
  22582.                                   compared with the key
  22583.  
  22584. %@NL@%
  22585. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22586. %@NL@%
  22587. The %@AB@%lfind%@AE@% function performs a linear search for the value %@AI@%key%@AE@% in an array of
  22588. %@AI@%num%@AE@% elements; each element is %@AI@%width%@AE@% bytes in size. (Unlike %@AB@%bsearch%@AE@%, %@AB@%lfind%@AE@%
  22589. does not require the array to be sorted.) The%@AI@% base%@AE@% argument is a pointer to
  22590. the base of the array to be searched.  %@NL@%
  22591. %@NL@%
  22592. The%@AI@% compare %@AE@%argument is a pointer to a user-supplied routine that compares
  22593. two array elements and then returns a value specifying their relationship.
  22594. The %@AB@%lfind%@AE@% function calls the %@AI@%compare%@AE@% routine one or more times during the
  22595. search, passing pointers to two array elements on each call. This routine
  22596. must compare the elements, then return one of the following values:  %@NL@%
  22597. %@NL@%
  22598. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  22599. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22600. Nonzero                           Elements are different
  22601.  
  22602. 0                                 Elements are identical
  22603.  
  22604. %@NL@%
  22605. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22606. %@NL@%
  22607. If the key is found, %@AB@%lfind%@AE@% returns a pointer to the element of the array at
  22608. %@AI@%base%@AE@% that matches %@AI@%key%@AE@%. If the key is not found, %@AB@%lfind%@AE@% returns %@AB@%NULL%@AE@%.  %@NL@%
  22609. %@NL@%
  22610. %@NL@%
  22611. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22612. %@NL@%
  22613.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  22614. %@NL@%
  22615. %@NL@%
  22616. %@NL@%
  22617. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22618. %@NL@%
  22619. %@AB@%bsearch%@AE@%, %@AB@%lsearch%@AE@%, %@AB@%qsort%@AE@%  %@NL@%
  22620. %@NL@%
  22621. %@NL@%
  22622. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22623. %@NL@%
  22624. %@AS@%  /* LFIND.C: This program uses lfind to search for the word "hello"
  22625. %@AS@%   * in the command-line arguments.
  22626. %@AS@%   */
  22627. %@AS@%  
  22628. %@AS@%  #include <search.h>
  22629. %@AS@%  #include <string.h>
  22630. %@AS@%  #include <stdio.h>
  22631. %@AS@%  
  22632. %@AS@%  int compare( char **arg1, char **arg2 );
  22633. %@AS@%  
  22634. %@AS@%  void main( int argc, char **argv )
  22635. %@AS@%  {
  22636. %@AS@%     char **result;
  22637. %@AS@%     char *key = "hello";
  22638. %@AS@%  
  22639. %@AS@%     result = (char **)lfind( (char *)&key, (char *)argv,
  22640. %@AS@%                              &argc, sizeof( char * ), compare );
  22641. %@AS@%     if( result )
  22642. %@AS@%        printf( "%s found\n", *result );
  22643. %@AS@%     else
  22644. %@AS@%        printf( "hello not found!\n" );
  22645. %@AS@%  }
  22646. %@AS@%  
  22647. %@AS@%  int compare(char ** arg1, char **arg2 )
  22648. %@AS@%  {
  22649. %@AS@%     return( strcmpi( *arg1, *arg2 ) );
  22650. %@AS@%  }%@AE@%%@NL@%
  22651. %@NL@%
  22652. %@NL@%
  22653. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  22654. %@NL@%
  22655. %@NL@%
  22656. %@3@%%@AB@%%@AE@%%@EH@%%@NL@%
  22657. %@NL@%
  22658. %@AS@%  
  22659. %@AS@%  
  22660. %@AS@%  [C:\LIBREF] lfind What if I said Hello world
  22661. %@AS@%  Hello found%@AE@%%@NL@%
  22662. %@NL@%
  22663. %@NL@%
  22664. %@NL@%
  22665. %@NL@%
  22666. %@QR:_lineto@%%@NL@%
  22667. %@2@%%@CR:C6A01840917 @%%@AB@%_lineto Functions%@AE@%%@EH@%%@NL@%
  22668. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22669. %@NL@%
  22670. %@NL@%
  22671. %@3@%%@AB@%Description%@CR:C6A01840918 @%%@CR:C6A01840919 @%%@CR:C6A01840920 @% %@CR:C6A01840921 @%%@AE@%%@EH@%%@NL@%
  22672. %@NL@%
  22673. Draw lines to specified points.  %@NL@%
  22674. %@NL@%
  22675. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  22676. %@NL@%
  22677. %@AS@%  short _far _lineto( short x, short y );%@AE@%%@NL@%
  22678. %@NL@%
  22679. %@AS@%  short _far _lineto_w( double wx, double wy );%@AE@%%@NL@%
  22680. %@NL@%
  22681. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              End point
  22682.  
  22683. %@AI@%wx%@AE@%, %@AI@%wy%@AE@%                            End point
  22684.  
  22685. %@NL@%
  22686. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22687. %@NL@%
  22688. The functions in the %@AB@%_lineto%@AE@% family draw a line from the current graphics
  22689. position up to and including the destination point. The destination point
  22690. for the %@AB@%_lineto%@AE@% function is given by the view-coordinate point (%@AI@%x%@AE@%, %@AI@%y%@AE@%). The
  22691. destination point for the %@AB@%_lineto_w%@AE@% function is given by the
  22692. window-coordinate point (%@AI@%wx%@AE@%, %@AI@%wy%@AE@%).  %@NL@%
  22693. %@NL@%
  22694. The line is drawn using the current color, logical write mode, and line
  22695. style. If no error occurs, %@AB@%_lineto%@AE@% sets the current graphics position to the
  22696. view-coordinate point (%@AI@%x%@AE@%, %@AI@%y%@AE@%); %@AB@%_lineto_w%@AE@% sets the current position to the
  22697. window-coordinate point (%@AI@%wx%@AE@%, %@AI@%wy%@AE@%).  %@NL@%
  22698. %@NL@%
  22699. If you use%@AB@% _floodfill%@AE@% to fill in a closed figure drawn with %@AB@%_lineto%@AE@% calls,
  22700. the figure must be%@AI@% %@AE@%drawn with a solid line-style pattern.%@AI@%  %@AE@%%@NL@%
  22701. %@NL@%
  22702. %@NL@%
  22703. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22704. %@NL@%
  22705. The %@AB@%_lineto%@AE@% and %@AB@%_lineto_w%@AE@% routines return a nonzero value if anything is
  22706. drawn; otherwise, they return 0.  %@NL@%
  22707. %@NL@%
  22708. %@NL@%
  22709. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22710. %@NL@%
  22711.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  22712. %@NL@%
  22713. %@NL@%
  22714. %@NL@%
  22715. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22716. %@NL@%
  22717. %@AB@%_getcurrentposition%@AE@% functions,  %@AB@%_moveto%@AE@% functions,  %@AB@%_setlinestyle%@AE@%  %@NL@%
  22718. %@NL@%
  22719. %@NL@%
  22720. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22721. %@NL@%
  22722. %@AS@%  /* MOVETO.C: This program draws line segments of different colors. */
  22723. %@AS@%  
  22724. %@AS@%  #include <graph.h>
  22725. %@AS@%  #include <stdlib.h>
  22726. %@AS@%  #include <conio.h>%@AE@%%@NL@%
  22727. %@NL@%
  22728. %@AS@%  void main()
  22729. %@AS@%  {
  22730. %@AS@%     short x, y, xinc, yinc, color = 1;
  22731. %@AS@%     struct videoconfig v;
  22732. %@AS@%  
  22733. %@AS@%     /* Find a valid graphics mode. */
  22734. %@AS@%     if( !_setvideomode( _MAXCOLORMODE ) )
  22735. %@AS@%        exit( 1 );
  22736. %@AS@%     _getvideoconfig( &v );
  22737. %@AS@%     xinc = v.numxpixels / 50;
  22738. %@AS@%     yinc = v.numypixels / 50;
  22739. %@AS@%  
  22740. %@AS@%     for( x = 0, y = v.numypixels - 1; x < v.numxpixels; x += xinc, y -=
  22741. %@AS@%yinc )
  22742. %@AS@%     {
  22743. %@AS@%        _setcolor( color++ % 16 );
  22744. %@AS@%        _moveto( x, 0 );
  22745. %@AS@%        _lineto( 0, y );
  22746. %@AS@%     }
  22747. %@AS@%     getch();
  22748. %@AS@%  
  22749. %@AS@%     _setvideomode( _DEFAULTMODE );
  22750. %@AS@%  }%@AE@%%@NL@%
  22751. %@NL@%
  22752. %@NL@%
  22753. %@NL@%
  22754. %@NL@%
  22755. %@QR:localeconv@%%@NL@%
  22756. %@2@%%@CR:C6A01850922 @%%@AB@%localeconv%@AE@%%@EH@%%@NL@%
  22757. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22758. %@NL@%
  22759. %@NL@%
  22760. %@3@%%@AB@%Description%@CR:C6A01850923 @%%@CR:C6A01850924 @%%@AE@%%@EH@%%@NL@%
  22761. %@NL@%
  22762. Gets detailed information on locale settings.  %@NL@%
  22763. %@NL@%
  22764. %@AS@%  #include <locale.h>%@AE@%%@NL@%
  22765. %@NL@%
  22766. %@AS@%  struct lconv *localeconv( void );%@AE@%%@NL@%
  22767. %@NL@%
  22768. %@NL@%
  22769. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22770. %@NL@%
  22771. The %@AB@%localeconv%@AE@% function gets detailed information on the locale-specific
  22772. settings for numeric formatting of the program's current locale. This
  22773. information is stored in a structure of type %@AB@%lconv%@AE@%.  %@NL@%
  22774. %@NL@%
  22775. The %@AB@%lconv%@AE@% structure, defined in LOCALE.H, contains the following elements:  %@NL@%
  22776. %@NL@%
  22777. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  22778. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22779. %@AB@%char *decimal_point%@AE@%               Decimal-point character for nonmonetary 
  22780.                                   quantities.
  22781.  
  22782. %@AB@%char *thousands_sep%@AE@%               Character used to separate groups of 
  22783.                                   digits to the left of the decimal point 
  22784.                                   for non-monetary quantities.
  22785.  
  22786. %@AB@%char *grouping%@AE@%                    Size of each group of digits in 
  22787.                                   non-monetary quantities.
  22788.  
  22789. %@AB@%char *int_curr_symbol%@AE@%             International currency symbol for the 
  22790.                                   current locale. The first three 
  22791.                                   characters specify the alphabetic 
  22792.                                   international currency symbol as defined
  22793.                                   in the %@AI@%ISO 4217 Codes for the %@AE@%
  22794.                                   %@AI@%Representation of Currency and Funds%@AE@% 
  22795.                                   standard. The fourth character 
  22796.                                   (immediately preceding the null 
  22797.                                   character) is used to separate the 
  22798.                                   international currency symbol from the 
  22799.                                   monetary quantity.
  22800.  
  22801. %@AB@%char *currency_symbol%@AE@%             Local currency symbol for the current
  22802.                                   locale.
  22803.  
  22804. %@AB@%char *mon_decimal_point%@AE@%           Decimal-point character for monetary 
  22805.                                   quantities.
  22806.  
  22807. %@AB@%char *mon_thousands_sep%@AE@%           Separator for groups of digits to the 
  22808.                                   left of the decimal place in monetary 
  22809.                                   quantities.
  22810.  
  22811. %@AB@%char *mon_grouping%@AE@%                Size of each group of digits in monetary
  22812.                                   quantities.
  22813.  
  22814. %@AB@%char *positive_sign%@AE@%               String denoting sign for nonnegative 
  22815.                                   monetary quantities.
  22816.  
  22817. %@AB@%char *negative_sign%@AE@%               String denoting sign for negative 
  22818.                                   monetary
  22819.                                   quantities.
  22820.  
  22821. %@AB@%char int_frac_digits%@AE@%              Number of digits to the right of the 
  22822.                                   decimal point in internationally 
  22823.                                   formatted
  22824.                                   monetary quantities.
  22825.  
  22826. %@AB@%char frac_digits%@AE@%                  Number of digits to the right of the 
  22827.                                   decimal point in formatted monetary
  22828.                                   quantities.
  22829.  
  22830. %@AB@%char p_cs_precedes%@AE@%                Set to 1 if the currency symbol precedes
  22831.                                   the value for a nonnegative formatted 
  22832.                                   monetary quantity. Set to 0 if the 
  22833.                                   symbol follows the value.
  22834.  
  22835. %@AB@%char p_sep_by_space%@AE@%               Set to 1 if the currency symbol is 
  22836.                                   separated by a space from the value for 
  22837.                                   a non-negative formatted monetary 
  22838.                                   quantity. Set to 0 if there is no space 
  22839.                                   separation.
  22840.  
  22841. %@AB@%char n_cs_precedes%@AE@%                Set to 1 if the currency symbol precedes
  22842.                                   the value for a negative formatted 
  22843.                                   monetary quantity. Set to 0 if the 
  22844.                                   symbol succeeds the value.
  22845.  
  22846. %@AB@%char n_sep_by_space%@AE@%               Set to 1 if the currency symbol is 
  22847.                                   separated by a space from the value for 
  22848.                                   a negative formatted monetary quantity. 
  22849.                                   Set to 0 if there is no space 
  22850.                                   separation.
  22851.  
  22852. %@AB@%char p_sign_posn%@AE@%                  Position of positive sign in nonnegative
  22853.                                   formatted monetary quantities.
  22854.  
  22855. %@AB@%char n_sign_posn%@AE@%                  Position of positive sign in negative 
  22856.                                   formatted monetary quantities.
  22857.  
  22858. The elements of %@AB@%grouping%@AE@% and %@AB@%mon%@AE@%_%@AB@%grouping%@AE@% are interpreted according to the
  22859. following rules:  %@NL@%
  22860. %@NL@%
  22861. %@AB@%Value%@AE@%                             %@AB@%Interpretation%@AE@%
  22862. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22863. %@AB@%CHAR_MAX%@AE@%                          No further grouping is to be performed.
  22864.  
  22865. 0                                 The previous element is to be repeatedly
  22866.                                   used for the remainder of the digits.
  22867.  
  22868. %@AI@%n%@AE@%                                 The integer value %@AI@%n%@AE@% is the number of 
  22869.                                   digits that make up the current group. 
  22870.                                   The next element is examined to 
  22871.                                   determine the size of the next group of 
  22872.                                   digits before the current group.
  22873.  
  22874. The values for %@AB@%p_sign_posn%@AE@% and %@AB@%n_sign_posn%@AE@% are interpreted according to the
  22875. following rules:  %@NL@%
  22876. %@NL@%
  22877. %@AB@%Value%@AE@%                             %@AB@%Interpretation%@AE@%
  22878. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22879. 0                                 Parentheses surround the quantity and 
  22880.                                   currency symbol
  22881.  
  22882. 1                                 Sign string precedes the quantity and 
  22883.                                   currency symbol
  22884.  
  22885. 2                                 Sign string follows the quantity and 
  22886.                                   currency symbol
  22887.  
  22888. 3                                 Sign string immediately precedes the 
  22889.                                   currency symbol
  22890.  
  22891. 4                                 Sign string immediately follows the 
  22892.                                   currency symbol
  22893.  
  22894. %@NL@%
  22895. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22896. %@NL@%
  22897. The %@AB@%localeconv%@AE@% function returns a pointer to a structure of %@AB@%lconv%@AE@% type.
  22898. Calls to the %@AB@%setlocale%@AE@% function with %@AI@%category%@AE@% values of %@AB@%LC_ALL%@AE@%, %@AB@%LC_MONETARY,%@AE@%
  22899. or %@AB@%LC_NUMERIC%@AE@% will overwrite the contents of the structure.  %@NL@%
  22900. %@NL@%
  22901. %@NL@%
  22902. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22903. %@NL@%
  22904. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  22905. %@NL@%
  22906. %@NL@%
  22907. %@NL@%
  22908. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22909. %@NL@%
  22910. %@AB@%setlocale%@AE@%, %@AB@%strcoll%@AE@%, %@AB@%strftime%@AE@%, %@AB@%strxfrm%@AE@%  %@NL@%
  22911. %@NL@%
  22912. %@NL@%
  22913. %@NL@%
  22914. %@NL@%
  22915. %@QR:localtime@%%@NL@%
  22916. %@2@%%@CR:C6A01860925 @%%@AB@%localtime%@AE@%%@EH@%%@NL@%
  22917. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22918. %@NL@%
  22919. %@NL@%
  22920. %@3@%%@AB@%Description%@CR:C6A01860926 @%%@CR:C6A01860927 @% %@CR:C6A01860928 @%%@CR:C6A01860929 @% %@CR:C6A01860930 @%%@AE@%%@EH@%%@NL@%
  22921. %@NL@%
  22922. Converts a time value and corrects for the local time zone.  %@NL@%
  22923. %@NL@%
  22924. %@AS@%  #include <time.h>%@AE@%%@NL@%
  22925. %@NL@%
  22926. %@AS@%  struct tm *localtime( const time_t *timer );%@AE@%%@NL@%
  22927. %@NL@%
  22928. %@AI@%timer%@AE@%                             Pointer to stored time
  22929.  
  22930. %@NL@%
  22931. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  22932. %@NL@%
  22933. The %@AB@%localtime%@AE@% function converts a time stored as a %@AB@%time_t%@AE@% value and stores
  22934. the result in a structure of type %@AB@%tm%@AE@%. The %@AB@%long%@AE@% value %@AI@%timer%@AE@% represents the
  22935. seconds elapsed since 00:00:00, January 1, 1970, Greenwich mean time; this
  22936. value is usually obtained from the %@AB@%time%@AE@% function.  %@NL@%
  22937. %@NL@%
  22938. The fields of the structure type %@AB@%tm%@AE@% store the following values:  %@NL@%
  22939. %@NL@%
  22940. %@AB@%Element%@AE@%                           %@AB@%Value Stored%@AE@%
  22941. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  22942. %@AB@%int tm_sec%@AE@%                        Seconds
  22943.  
  22944. %@AB@%int tm_min%@AE@%                        Minutes
  22945.  
  22946. %@AB@%int tm_hour%@AE@%                       Hours (0 -24)
  22947.  
  22948. %@AB@%int tm_mday%@AE@%                       Day of month (1-31)
  22949.  
  22950. %@AB@%int tm_mon%@AE@%                        Month (0 -11; January = 0)
  22951.  
  22952. %@AB@%int tm_year%@AE@%                       Year (current year minus 1900)
  22953.  
  22954. %@AB@%int tm_wday%@AE@%                       Day of week (0 - 6; Sunday = 0)
  22955.  
  22956. %@AB@%int tm_yday%@AE@%                       Day of year (0 -365; January 1 = 0)
  22957.  
  22958. %@AB@%int tm_isdst%@AE@%                      Nonzero if daylight saving time is in 
  22959.                                   effect, otherwise 0
  22960.  
  22961. Note that the %@AB@%gmtime, mktime, %@AE@%and%@AB@% localtime%@AE@% functions use a single
  22962. statically allocated %@AB@%tm%@AE@% structure for the conversion. Each call to one of
  22963. these routines destroys the result of the previous call.  %@NL@%
  22964. %@NL@%
  22965. The %@AB@%localtime%@AE@% function makes corrections for the local time zone if the user
  22966. first sets the environment variable TZ. When TZ is set, three other
  22967. environment variables (%@AB@%timezone%@AE@%, %@AB@%daylight%@AE@%, and %@AB@%tzname%@AE@%) are automatically set
  22968. as well. See %@AB@%tzset%@AE@% for a description of these variables.%@CR:C6A01860931 @%  %@NL@%
  22969. %@NL@%
  22970. The TZ variable is not part of the ANSI standard definition of %@AB@%localtime%@AE@% but
  22971. is a Microsoft extension.  %@NL@%
  22972. %@NL@%
  22973. %@NL@%
  22974. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  22975. %@NL@%
  22976. The %@AB@%localtime%@AE@% function returns a pointer to the structure result. DOS and
  22977. OS/2 do not accommodate dates prior to 1980. If the value in %@AI@%timer%@AE@%
  22978. represents a date prior to January 1, 1980, the function returns %@AB@%NULL%@AE@%.  %@NL@%
  22979. %@NL@%
  22980. %@NL@%
  22981. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  22982. %@NL@%
  22983. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  22984. %@NL@%
  22985. %@NL@%
  22986. %@NL@%
  22987. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  22988. %@NL@%
  22989. %@AB@%asctime%@AE@%, %@AB@%ctime%@AE@%, %@AB@%ftime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%time%@AE@%, %@AB@%tzset%@AE@%  %@NL@%
  22990. %@NL@%
  22991. %@NL@%
  22992. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  22993. %@NL@%
  22994. %@AS@%  /* LOCALTIM.C: This program uses time to get the current time and
  22995. %@AS@%   * then uses localtime to convert this time to a structure representing 
  22996. %@AS@%   * the local time. The program converts the result from a 24-hour clock
  22997. %@AS@%   * to a 12-hour clock and determines the proper extension (AM or PM).
  22998. %@AS@%   */
  22999. %@AS@%  
  23000. %@AS@%  #include <stdio.h>
  23001. %@AS@%  #include <string.h>
  23002. %@AS@%  #include <time.h>
  23003. %@AS@%  
  23004. %@AS@%  void main()
  23005. %@AS@%  {
  23006. %@AS@%     struct tm *newtime;
  23007. %@AS@%     char  am_pm[] = "AM";
  23008. %@AS@%     time_t long_time;
  23009. %@AS@%  
  23010. %@AS@%     time( &long_time );                 /* Get time as long integer. */
  23011. %@AS@%     newtime = localtime( &long_time );  /* Convert to local time. */
  23012. %@AS@%  
  23013. %@AS@%     if( newtime->tm_hour < 12 )         /* Set up extension. */
  23014. %@AS@%        strcpy( am_pm, "AM" );
  23015. %@AS@%     if( newtime->tm_hour > 12 )         /* Convert from 24-hour */
  23016. %@AS@%        newtime->tm_hour -=12;           /*   to 12-hour clock.  */
  23017. %@AS@%  
  23018. %@AS@%     printf( "%.19s %s\n", asctime( newtime ), am_pm );
  23019. %@AS@%  }%@AE@%%@NL@%
  23020. %@NL@%
  23021. %@NL@%
  23022. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23023. %@NL@%
  23024. %@AS@%  
  23025. %@AS@%  
  23026. %@AS@%  Fri Jun 16 06:27:02 AM %@AE@%%@NL@%
  23027. %@NL@%
  23028. %@NL@%
  23029. %@NL@%
  23030. %@NL@%
  23031. %@QR:locking@%%@NL@%
  23032. %@2@%%@CR:C6A01870932 @%%@AB@%locking%@AE@%%@EH@%%@NL@%
  23033. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23034. %@NL@%
  23035. %@NL@%
  23036. %@3@%%@AB@%Description%@CR:C6A01870933 @%%@CR:C6A01870934 @%%@CR:C6A01870935 @%%@AE@%%@EH@%%@NL@%
  23037. %@NL@%
  23038. Locks or unlocks bytes of a file.  %@NL@%
  23039. %@NL@%
  23040. %@AS@%  #include <sys\locking.h>%@AE@%%@NL@%
  23041. %@NL@%
  23042. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  23043.  
  23044. %@AS@%  int locking( int handle, int mode, long nbytes );%@AE@%%@NL@%
  23045. %@NL@%
  23046. %@AI@%handle%@AE@%                            File handle
  23047.  
  23048. %@AI@%mode%@AE@%                              File-locking mode
  23049.  
  23050. %@AI@%nbytes%@AE@%                            Number of bytes to lock
  23051.  
  23052. %@NL@%
  23053. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23054. %@NL@%
  23055. The%@AB@% locking%@AE@% function locks or unlocks %@AI@%nbytes%@AE@% bytes of the file specified by
  23056. %@AI@%handle%@AE@%. Locking bytes in a file prevents access to those bytes by other
  23057. processes. All locking or unlocking begins at the current position of the
  23058. file pointer and proceeds for the next %@AI@%nbytes%@AE@% bytes. It is possible to lock
  23059. bytes past the end of the file.  %@NL@%
  23060. %@NL@%
  23061. The %@AI@%mode%@AE@% argument specifies the locking action to be performed. It must be
  23062. one of the following manifest constants:  %@NL@%
  23063. %@NL@%
  23064. %@AB@%Constant%@AE@%                          %@AB@%Action%@AE@%
  23065. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23066. %@AB@%LK_LOCK%@AE@%                           Locks the specified bytes. If the bytes 
  23067.                                   cannot be locked, immediately tries 
  23068.                                   again after 1 second. If, after 10 
  23069.                                   attempts, the bytes cannot be locked, 
  23070.                                   returns an error.
  23071.  
  23072. %@AB@%LK_NBLCK%@AE@%                          Locks the specified bytes. If bytes 
  23073.                                   cannot be locked, returns an error.
  23074.  
  23075. %@AB@%LK_NBRLCK%@AE@%                         Same as %@AB@%LK_NBLCK%@AE@%.
  23076.  
  23077. %@AB@%LK_RLCK%@AE@%                           Same as%@AB@% LK_LOCK%@AE@%.
  23078.  
  23079. %@AB@%LK_UNLCK%@AE@%                          Unlocks the specified bytes. (The bytes 
  23080.                                   must have been previously locked.)
  23081.  
  23082. More than one region of a file can be locked, but no overlapping regions are
  23083. allowed.  %@NL@%
  23084. %@NL@%
  23085. When a region of a file is being unlocked, it must correspond to a region
  23086. that was previously locked. The %@AB@%locking%@AE@% function does not merge adjacent
  23087. regions; if two locked regions are adjacent, each region must be unlocked
  23088. separately.  %@NL@%
  23089. %@NL@%
  23090. Regions should be locked only briefly and should be unlocked before closing
  23091. a file or exiting the program.  %@NL@%
  23092. %@NL@%
  23093. The %@AB@%locking%@AE@% function should be used only under OS/2 or under DOS versions
  23094. 3.0 and later; it has no effect under earlier versions of DOS. Also, file
  23095. sharing must be loaded to use the %@AB@%locking %@AE@%function. Note that under DOS
  23096. versions 3.0 and 3.1, the files locked by parent processes may become
  23097. unlocked when child processes exit.  %@NL@%
  23098. %@NL@%
  23099. %@NL@%
  23100. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23101. %@NL@%
  23102. The %@AB@%locking%@AE@% function returns 0 if successful. A return value of -1 indicates
  23103. failure, and %@AB@%errno%@AE@% is set to one of the following values:  %@NL@%
  23104. %@NL@%
  23105. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  23106. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23107. %@AB@%EACCES%@AE@%                            Locking violation (file already locked 
  23108.                                   or unlocked).
  23109.  
  23110. %@AB@%EBADF%@AE@%                             Invalid file handle.
  23111.  
  23112. %@AB@%EDEADLOCK%@AE@%                         Locking violation. This is returned when
  23113.                                   the %@AB@%LK_LOCK%@AE@% or %@AB@%LK_RLCK%@AE@% flag is specified
  23114.                                   and the file cannot be locked after 10 
  23115.                                   attempts.
  23116.  
  23117. %@AB@%EINVAL%@AE@%                            An invalid argument was given to the 
  23118.                                   function.
  23119.  
  23120. %@NL@%
  23121. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23122. %@NL@%
  23123.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  23124. %@NL@%
  23125. %@NL@%
  23126. %@NL@%
  23127. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23128. %@NL@%
  23129. %@AB@%creat%@AE@%, %@AB@%open%@AE@%  %@NL@%
  23130. %@NL@%
  23131. %@NL@%
  23132. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23133. %@NL@%
  23134. %@AS@%  /* LOCKING.C: This program opens a file with sharing. It locks some
  23135. %@AS@%   * bytes before reading them, then unlocks them. Note that the program
  23136. %@AS@%   * works correctly only if the following conditions are met:
  23137. %@AS@%   *     - The file exists
  23138. %@AS@%   *     - The program is run under OS/2, under DOS 3.0 or later
  23139. %@AS@%   *       with file sharing installed (SHARE.COM or SHARE.EXE), or 
  23140. %@AS@%   *       if a Microsoft Networks compatible network is running
  23141. %@AS@%   */
  23142. %@AS@%  
  23143. %@AS@%  #include <io.h>
  23144. %@AS@%  #include <sys\types.h>
  23145. %@AS@%  #include <sys\stat.h>
  23146. %@AS@%  #include <sys\locking.h>
  23147. %@AS@%  #include <share.h>
  23148. %@AS@%  #include <fcntl.h>
  23149. %@AS@%  #include <stdio.h>
  23150. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  23151. %@NL@%
  23152. %@AS@%  void main()
  23153. %@AS@%  {
  23154. %@AS@%     int  fh, numread;
  23155. %@AS@%     long pos, result;
  23156. %@AS@%     char buffer[40];
  23157. %@AS@%  
  23158. %@AS@%     /* Quit if can't open file or DOS version doesn't support sharing. */
  23159. %@AS@%     fh = sopen( "locking.c", O_RDWR, SH_DENYNO, S_IREAD | S_IWRITE );
  23160. %@AS@%     if( (fh == -1) || (_osmajor < 3) )
  23161. %@AS@%        exit( 1 );
  23162. %@AS@%  
  23163. %@AS@%     /* Lock some bytes and read them. Then unlock. */
  23164. %@AS@%     if( locking( fh, LK_NBLCK, 30L ) != -1 )
  23165. %@AS@%     {
  23166. %@AS@%        printf( "No one can change these bytes while I'm reading them\n" );
  23167. %@AS@%        numread = read( fh, buffer, 30 );
  23168. %@AS@%        printf( "%d bytes read: %.30s\n", numread, buffer );
  23169. %@AS@%        locking( fh, LK_UNLCK, 30L );
  23170. %@AS@%        printf( "Now I'm done. Do what you will with them\n" );
  23171. %@AS@%     }
  23172. %@AS@%     else
  23173. %@AS@%        perror( "Locking failed\n" );
  23174. %@AS@%  
  23175. %@AS@%     close( fh );
  23176. %@AS@%  }%@AE@%%@NL@%
  23177. %@NL@%
  23178. %@NL@%
  23179. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23180. %@NL@%
  23181. %@AS@%  
  23182. %@AS@%  
  23183. %@AS@%  No one can change these bytes while I'm reading them
  23184. %@AS@%  30 bytes read: /* LOCKING.C: This program ope
  23185. %@AS@%  Now I'm done. Do what you will with them %@AE@%%@NL@%
  23186. %@NL@%
  23187. %@NL@%
  23188. %@NL@%
  23189. %@NL@%
  23190. %@QR:log@%%@NL@%
  23191. %@2@%%@CR:C6A01880936 @%%@AB@%log Functions%@AE@%%@EH@%%@NL@%
  23192. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23193. %@NL@%
  23194. %@NL@%
  23195. %@3@%%@AB@%Description%@CR:C6A01880937 @%%@CR:C6A01880938 @% %@CR:C6A01880939 @%%@CR:C6A01880940 @% %@CR:C6A01880941 @%%@AE@%%@EH@%%@NL@%
  23196. %@NL@%
  23197. Calculate logarithms.  %@NL@%
  23198. %@NL@%
  23199. %@AS@%  #include <math.h>%@AE@%%@NL@%
  23200. %@NL@%
  23201. %@AS@%  double log( double x );%@AE@%%@NL@%
  23202. %@NL@%
  23203. %@AS@%  double log10( double x );%@AE@%%@NL@%
  23204. %@NL@%
  23205. %@AS@%  long double logl( long double x );%@AE@%%@NL@%
  23206. %@NL@%
  23207. %@AS@%  long double log10l( long double x );%@AE@%%@NL@%
  23208. %@NL@%
  23209. %@AI@%x%@AE@%                                 Value whose logarithm is to be found
  23210.  
  23211. %@NL@%
  23212. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23213. %@NL@%
  23214. The %@AB@%log%@AE@% and %@AB@%log10%@AE@% functions calculate the natural logarithm and the base-10
  23215. logarithm, respectively, of %@AI@%x%@AE@%. The %@AB@%logl%@AE@% and %@AB@%log10l%@AE@% functions are the 80-bit
  23216. counterparts and use the 80-bit, 10-byte coprocessor form of arguments and
  23217. return values. See the reference page on the long double functions for more
  23218. details on this data type.  %@NL@%
  23219. %@NL@%
  23220. %@NL@%
  23221. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23222. %@NL@%
  23223. The%@AB@% log%@AE@% functions return the logarithm of the argument %@AI@%x%@AE@%. If %@AI@%x%@AE@% is negative,
  23224. the functions print a %@AB@%DOMAIN%@AE@% error message to %@AB@%stderr%@AE@%, return the value
  23225. -%@AB@%HUGE_VAL%@AE@%, and set %@AB@%errno%@AE@% to %@AB@%EDOM%@AE@%. If %@AI@%x%@AE@% is 0, the functions print a%@AB@% SING%@AE@%
  23226. error message to %@AB@%stderr%@AE@%, return the value -%@AB@%HUGE_VAL%@AE@%, and set %@AB@%errno%@AE@% to
  23227. %@AB@%ERANGE.%@AE@%  %@NL@%
  23228. %@NL@%
  23229. Error handling can be modified by using the %@AB@%matherr%@AE@% or %@AB@%_matherrl%@AE@% routine.  %@NL@%
  23230. %@NL@%
  23231. %@NL@%
  23232. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23233. %@NL@%
  23234. %@AB@%log%@AE@%, %@AB@%log10%@AE@%  %@NL@%
  23235. %@NL@%
  23236. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  23237. %@NL@%
  23238. %@NL@%
  23239. %@AB@%logl%@AE@%, %@AB@%log10l%@AE@%  %@NL@%
  23240. %@NL@%
  23241.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  23242. %@NL@%
  23243. %@NL@%
  23244. %@NL@%
  23245. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23246. %@NL@%
  23247. %@AB@%exp%@AE@%,%@AB@% matherr%@AE@%,%@AB@% pow%@AE@% functions  %@NL@%
  23248. %@NL@%
  23249. %@NL@%
  23250. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23251. %@NL@%
  23252. %@AS@%  /* LOG.C: This program uses log and log10 to calculate the natural
  23253. %@AS@%   * logarithm and the base-10 logarithm of 9,000.
  23254. %@AS@%   */
  23255. %@AS@%  
  23256. %@AS@%  #include <math.h>
  23257. %@AS@%  #include <stdio.h>
  23258. %@AS@%  
  23259. %@AS@%  void main()
  23260. %@AS@%  {
  23261. %@AS@%     double x = 9000.0;
  23262. %@AS@%     double y;
  23263. %@AS@%  
  23264. %@AS@%     y = log( x );
  23265. %@AS@%     printf( "log( %.2f ) = %f\n", x, y );
  23266. %@AS@%     y = log10( x );
  23267. %@AS@%     printf( "log10( %.2f ) = %f\n", x, y );
  23268. %@AS@%  }%@AE@%%@NL@%
  23269. %@NL@%
  23270. %@NL@%
  23271. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23272. %@NL@%
  23273. %@AS@%  
  23274. %@AS@%  
  23275. %@AS@%  log( 9000.00 ) = 9.104980
  23276. %@AS@%  log10( 9000.00 ) = 3.954243%@AE@%%@NL@%
  23277. %@NL@%
  23278. %@NL@%
  23279. %@NL@%
  23280. %@NL@%
  23281. %@QR:long@%%@QR:double@%%@NL@%
  23282. %@2@%%@CR:C6A01890942 @%%@AB@%long double Functions%@AE@%%@EH@%%@NL@%
  23283. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23284. %@NL@%
  23285. The 8087 family of numeric coprocessor chips supports the 80-bit precision
  23286. floating-point data type. In Microsoft C, version 6.0, the long double
  23287. functions, whose names end with%@AB@% l%@AE@%, map the C %@AB@%long double%@AE@% type into this
  23288. 80-bit, 10-byte form. Unlike the regular floating-point functions (such as
  23289. %@AB@%acos%@AE@%), which return values of type %@AB@%double%@AE@%, these long double functions (such
  23290. as %@AB@%acosl%@AE@%) return values of type %@AB@%long double%@AE@%. The long double functions also
  23291. return their values on the coprocessor stack for all calling conventions.  %@NL@%
  23292. %@NL@%
  23293. The long double type is also supported by the addition of the "L" prefix for
  23294. a floating-point format specification in the %@AB@%printf%@AE@% and %@AB@%scanf%@AE@% family of
  23295. functions.  %@NL@%
  23296. %@NL@%
  23297. The long double versions are described on the reference pages for their
  23298. regular counterparts. These are the regular C run-time math functions with
  23299. corresponding long double equivalents:  %@NL@%
  23300. %@NL@%
  23301. %@AB@%Regular Function%@AE@%                  %@AB@%Long Double Form%@AE@%
  23302. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23303. %@AB@%acos%@AE@%                              %@AB@%acosl%@AE@%
  23304.  
  23305. %@AB@%asin%@AE@%                              %@AB@%asinl%@AE@%
  23306.  
  23307. %@AB@%atan%@AE@%                              %@AB@%atanl%@AE@%
  23308.  
  23309. %@AB@%atan2%@AE@%                             %@AB@%atan2l%@AE@%
  23310.  
  23311. %@AB@%atof%@AE@%                              %@AB@%_atold%@AE@%
  23312.  
  23313. %@AB@%cabs%@AE@%                              %@AB@%cabsl%@AE@%
  23314.  
  23315. %@AB@%ceil%@AE@%                              %@AB@%ceill%@AE@%
  23316.  
  23317. %@AB@%cos%@AE@%                               %@AB@%cosl%@AE@%
  23318.  
  23319. %@AB@%cosh%@AE@%                              %@AB@%coshl%@AE@%
  23320.  
  23321. %@AB@%exp%@AE@%                               %@AB@%expl%@AE@%
  23322.  
  23323. %@AB@%fabs%@AE@%                              %@AB@%fabsl%@AE@%
  23324.  
  23325. %@AB@%floor%@AE@%                             %@AB@%floorl%@AE@%
  23326.  
  23327. %@AB@%fmod%@AE@%                              %@AB@%fmodl%@AE@%
  23328.  
  23329. %@AB@%frexp%@AE@%                             %@AB@%frexpl%@AE@%
  23330.  
  23331. %@AB@%hypot%@AE@%                             %@AB@%hypotl%@AE@%
  23332.  
  23333. %@AB@%ldexp%@AE@%                             %@AB@%ldexpl%@AE@%
  23334.  
  23335. %@AB@%log%@AE@%                               %@AB@%logl%@AE@%
  23336.  
  23337. %@AB@%log10%@AE@%                             %@AB@%log10l%@AE@%
  23338.  
  23339. %@AB@%matherr%@AE@%                           %@AB@%_matherrl%@AE@%
  23340.  
  23341. %@AB@%modf%@AE@%                              %@AB@%modfl%@AE@%
  23342.  
  23343. %@AB@%pow%@AE@%                               %@AB@%powl%@AE@%
  23344.  
  23345. %@AB@%sin%@AE@%                               %@AB@%sinl%@AE@%
  23346.  
  23347. %@AB@%sinh%@AE@%                              %@AB@%sinhl%@AE@%
  23348.  
  23349. %@AB@%sqrt%@AE@%                              %@AB@%sqrtl%@AE@%
  23350.  
  23351. %@AB@%tan%@AE@%                               %@AB@%tanl%@AE@%
  23352.  
  23353. %@AB@%tanh%@AE@%                              %@AB@%tanhl%@AE@%
  23354.  
  23355. %@NL@%
  23356. %@NL@%
  23357. %@NL@%
  23358. %@QR:longjmp@%%@NL@%
  23359. %@2@%%@CR:C6A01900943 @%%@AB@%longjmp%@AE@%%@EH@%%@NL@%
  23360. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23361. %@NL@%
  23362. %@NL@%
  23363. %@3@%%@AB@%Description%@CR:C6A01900944 @%%@CR:C6A01900945 @%%@CR:C6A01900946 @% %@CR:C6A01900947 @%%@AE@%%@EH@%%@NL@%
  23364. %@NL@%
  23365. Restores stack environment and execution locale.  %@NL@%
  23366. %@NL@%
  23367. %@AS@%  #include <setjmp.h>%@AE@%%@NL@%
  23368. %@NL@%
  23369. %@AS@%  void longjmp( jmp_buf env, int value );%@AE@%%@NL@%
  23370. %@NL@%
  23371. %@AI@%env%@AE@%                               Variable in which environment is stored
  23372.  
  23373. %@AI@%value%@AE@%                             Value to be returned to %@AB@%setjmp%@AE@% call
  23374.  
  23375. %@NL@%
  23376. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23377. %@NL@%
  23378. The %@AB@%longjmp%@AE@% function restores a stack environment and execution locale
  23379. previously saved in %@AI@%env%@AE@% by %@AB@%setjmp%@AE@%. The %@AB@%setjmp%@AE@% and %@AB@%longjmp%@AE@% functions provide
  23380. a way to execute a nonlocal %@AB@%goto%@AE@%; they are typically used to pass execution
  23381. control to error handling or recovery code in a previously called routine
  23382. without using the normal call and return conventions.  %@NL@%
  23383. %@NL@%
  23384. A call to %@AB@%setjmp%@AE@% causes the current stack environment to be saved in %@AI@%env.%@AE@% A
  23385. subsequent call to %@AB@%longjmp%@AE@% restores the saved environment and returns
  23386. control to the point immediately following the corresponding %@AB@%setjmp%@AE@% call.
  23387. Execution resumes as if %@AI@%value%@AE@% had just been returned by the %@AB@%setjmp%@AE@% call. The
  23388. values of all variables (except register variables) that are accessible to
  23389. the routine receiving control contain the values they had when %@AB@%longjmp%@AE@% was
  23390. called. The values of register variables are unpredictable.  %@NL@%
  23391. %@NL@%
  23392. The %@AB@%longjmp%@AE@% function must be called before the function that called %@AB@%setjmp%@AE@%
  23393. returns. If %@AB@%longjmp%@AE@% is called after the function calling %@AB@%setjmp%@AE@% returns,
  23394. unpredictable program behavior results.  %@NL@%
  23395. %@NL@%
  23396. The value returned by %@AB@%setjmp%@AE@% must be nonzero. If %@AI@%value%@AE@% is passed as 0, the
  23397. value 1 is substituted in the actual return.  %@NL@%
  23398. %@NL@%
  23399. Observe the following three restrictions when using %@AB@%longjmp%@AE@%:  %@NL@%
  23400. %@NL@%
  23401. %@NL@%
  23402.   1.  Do not assume that the values of the register variables will remain
  23403.       the same. The values of register variables in the routine calling
  23404.       %@AB@%setjmp%@AE@% may not be restored to the proper values after %@AB@%longjmp%@AE@% is
  23405.       executed.%@NL@%
  23406. %@NL@%
  23407.   2.  Do not use %@AB@%longjmp%@AE@% to transfer control from within one overlay to
  23408.       within another. The overlay manager keeps the overlay in memory after
  23409.       a call to %@AB@%longjmp%@AE@%.%@NL@%
  23410. %@NL@%
  23411.   3.  Do not use %@AB@%longjmp%@AE@% to transfer control out of an interrupt-handling
  23412.       routine unless the interrupt is caused by a floating-point exception.
  23413.       In this case, a program may return from an interrupt handler via
  23414.       %@AB@%longjmp%@AE@% if it first reinitializes the floating-point math package by
  23415.       calling %@AB@%_fpreset%@AE@%.%@NL@%
  23416. %@NL@%
  23417. %@NL@%
  23418. %@NL@%
  23419. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23420. %@NL@%
  23421. None.  %@NL@%
  23422. %@NL@%
  23423. %@NL@%
  23424. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23425. %@NL@%
  23426. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  23427. %@NL@%
  23428. %@NL@%
  23429. %@NL@%
  23430. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23431. %@NL@%
  23432. %@AB@%setjmp%@AE@%  %@NL@%
  23433. %@NL@%
  23434. %@NL@%
  23435. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23436. %@NL@%
  23437. See the example for %@AB@%_fpreset%@AE@%.  %@NL@%
  23438. %@NL@%
  23439. %@NL@%
  23440. %@NL@%
  23441. %@NL@%
  23442. %@QR:_lrotl@%%@QR:_lrotr@%%@NL@%
  23443. %@2@%%@CR:C6A01910948 @%%@AB@%_lrotl, _lrotr%@AE@%%@EH@%%@NL@%
  23444. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23445. %@NL@%
  23446. %@NL@%
  23447. %@3@%%@AB@%Description %@CR:C6A01910949 @%%@CR:C6A01910950 @%%@AE@%%@EH@%%@NL@%
  23448. %@NL@%
  23449. Rotate bits to the left (%@AB@%_lrotl%@AE@%) or right (%@AB@%_lrotr%@AE@%).  %@NL@%
  23450. %@NL@%
  23451. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  23452. %@NL@%
  23453. %@AS@%  unsigned long _lrotl( unsigned long value, int shift );%@AE@%%@NL@%
  23454. %@NL@%
  23455. %@AS@%  unsigned long _lrotr( unsigned long value, int shift );%@AE@%%@NL@%
  23456. %@NL@%
  23457. %@AI@%value%@AE@%                             Value to be rotated
  23458.  
  23459. %@AI@%shift%@AE@%                             Number of bits to shift
  23460.  
  23461. %@NL@%
  23462. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23463. %@NL@%
  23464. The %@AB@%_lrotl%@AE@% and %@AB@%_lrotr%@AE@% functions rotate %@AI@%value%@AE@% by %@AI@%shift%@AE@% bits. The %@AB@%_lrotl%@AE@%
  23465. function rotates the value left. The %@AB@%_lrotr%@AE@% function rotates the value
  23466. right. Both functions "wrap" bits rotated off one end of %@AI@%value%@AE@% to the other
  23467. end.  %@NL@%
  23468. %@NL@%
  23469. %@NL@%
  23470. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23471. %@NL@%
  23472. Both functions return the rotated value. There is no error return.  %@NL@%
  23473. %@NL@%
  23474. %@NL@%
  23475. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23476. %@NL@%
  23477.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  23478. %@NL@%
  23479. %@NL@%
  23480. %@NL@%
  23481. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23482. %@NL@%
  23483. %@AB@%_rotl%@AE@%,  %@AB@%_rotr%@AE@%  %@NL@%
  23484. %@NL@%
  23485. %@NL@%
  23486. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23487. %@NL@%
  23488. %@AS@%  /* LROT.C */
  23489. %@AS@%  #include <stdlib.h>
  23490. %@AS@%  #include <stdio.h>
  23491. %@AS@%  
  23492. %@AS@%  void main()
  23493. %@AS@%  {
  23494. %@AS@%     unsigned long val = 0x0fac35791;
  23495. %@AS@%  
  23496. %@AS@%     printf( "0x%8.8lx rotated left eight times is 0x%8.8lx\n",
  23497. %@AS@%             val, _lrotl( val, 8 ) );
  23498. %@AS@%     printf( "0x%8.8lx rotated right four times is 0x%8.8lx\n",
  23499. %@AS@%             val, _lrotr( val, 4 ) );
  23500. %@AS@%  }%@AE@%%@NL@%
  23501. %@NL@%
  23502. %@NL@%
  23503. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23504. %@NL@%
  23505. %@AS@%  
  23506. %@AS@%  
  23507. %@AS@%  0xfac35791 rotated left eight times is 0xc35791fa
  23508. %@AS@%  0xfac35791 rotated right four times is 0x1fac3579 %@AE@%%@NL@%
  23509. %@NL@%
  23510. %@NL@%
  23511. %@NL@%
  23512. %@NL@%
  23513. %@QR:lsearch@%%@NL@%
  23514. %@2@%%@CR:C6A01920951 @%%@AB@%lsearch%@AE@%%@EH@%%@NL@%
  23515. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23516. %@NL@%
  23517. %@NL@%
  23518. %@3@%%@AB@%Description%@CR:C6A01920952 @%%@CR:C6A01920953 @%%@CR:C6A01920954 @%%@AE@%%@EH@%%@NL@%
  23519. %@NL@%
  23520. Performs a linear search for a value; adds to end of list if not found.  %@NL@%
  23521. %@NL@%
  23522. %@AB@%#include <search.h>%@AE@%               Required only for function declarations
  23523.  
  23524. %@AS@%  char *lsearch( const void *key, const void *base, unsigned int *num, 
  23525. %@AS@%  unsigned int width, int ( *compare )( const void *elem1, const void *elem2
  23526. %@AS@%) );%@AE@%%@NL@%
  23527. %@NL@%
  23528. %@AI@%key%@AE@%                               Object to search for
  23529.  
  23530. %@AI@%base%@AE@%                              Pointer to base of search data
  23531.  
  23532. %@AI@%num%@AE@%                               Number of elements
  23533.  
  23534. %@AI@%width%@AE@%                             Width of elements
  23535.  
  23536. %@AI@%compare%@AE@%                           Pointer to comparison routine
  23537.  
  23538. %@AI@%elem1%@AE@%                             Pointer to the key for the search
  23539.  
  23540. %@AI@%elem2%@AE@%                             Pointer to the array element to be 
  23541.                                   compared with the key
  23542.  
  23543. %@NL@%
  23544. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23545. %@NL@%
  23546. The %@AB@%lsearch%@AE@% function performs a linear search for the value %@AI@%key%@AE@% in an array
  23547. of %@AI@%num%@AE@% elements, each of %@AI@%width%@AE@% bytes in size. (Unlike %@AB@%bsearch%@AE@%, %@AB@%lsearch%@AE@% does
  23548. not require the array to be sorted.) The %@AI@%base%@AE@% argument is a pointer to the
  23549. base of the array to be searched.  %@NL@%
  23550. %@NL@%
  23551. If %@AI@%key%@AE@% is not found, %@AB@%lsearch%@AE@% adds it to the end of the array.  %@NL@%
  23552. %@NL@%
  23553. The %@AI@%compare%@AE@% argument is a pointer to a user-supplied routine that compares
  23554. two array elements and returns a value specifying their relationship. The
  23555. %@AB@%lsearch%@AE@% function calls the %@AI@%compare%@AE@% routine one or more times during the
  23556. search, passing pointers to two array elements on each call. This routine
  23557. must compare the elements, then return one of the following values:  %@NL@%
  23558. %@NL@%
  23559. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  23560. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23561. Nonzero                           Elements are different
  23562.  
  23563. 0                                 Elements are identical
  23564.  
  23565. %@NL@%
  23566. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23567. %@NL@%
  23568. If the key is found, %@AB@%lsearch%@AE@% returns a pointer to the element of the array
  23569. at %@AI@%base%@AE@% that matches %@AI@%key%@AE@%. If the key is not found, %@AB@%lsearch%@AE@% returns a pointer
  23570. to the newly added item at the end of the array.  %@NL@%
  23571. %@NL@%
  23572. %@NL@%
  23573. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23574. %@NL@%
  23575.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  23576. %@NL@%
  23577. %@NL@%
  23578. %@NL@%
  23579. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23580. %@NL@%
  23581. %@AB@%bsearch%@AE@%, %@AB@%lfind%@AE@%  %@NL@%
  23582. %@NL@%
  23583. %@NL@%
  23584. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23585. %@NL@%
  23586. See the example for %@AB@%lfind%@AE@%.  %@NL@%
  23587. %@NL@%
  23588. %@NL@%
  23589. %@NL@%
  23590. %@NL@%
  23591. %@QR:lseek@%%@NL@%
  23592. %@2@%%@CR:C6A01930955 @%%@AB@%lseek%@AE@%%@EH@%%@NL@%
  23593. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23594. %@NL@%
  23595. %@NL@%
  23596. %@3@%%@AB@%Description%@CR:C6A01930956 @%%@CR:C6A01930957 @% %@CR:C6A01930958 @%%@CR:C6A01930959 @%%@AE@%%@EH@%%@NL@%
  23597. %@NL@%
  23598. Moves a file pointer to the specified location.  %@NL@%
  23599. %@NL@%
  23600. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  23601.  
  23602. %@AB@%#include <stdio.h>%@AE@%                
  23603.  
  23604. %@AS@%  long lseek( int handle, long offset, int origin );%@AE@%%@NL@%
  23605. %@NL@%
  23606. %@AI@%handle%@AE@%                            Handle referring to open file
  23607.  
  23608. %@AI@%offset%@AE@%                            Number of bytes from %@AI@%origin%@AE@%
  23609.  
  23610. %@AI@%origin%@AE@%                            Initial position
  23611.  
  23612. %@NL@%
  23613. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23614. %@NL@%
  23615. The %@AB@%lseek%@AE@% function moves the file pointer associated with %@AI@%handle%@AE@% to a new
  23616. location that is %@AI@%offset%@AE@% bytes from %@AI@%origin%@AE@%. The next operation on the file
  23617. occurs at the new location. The %@AI@%origin%@AE@% argument must be one of the following
  23618. constants, which are defined in STDIO.H:  %@NL@%
  23619. %@NL@%
  23620. %@AB@%Origin%@AE@%                            %@AB@%Definition%@AE@%
  23621. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23622. %@AB@%SEEK_SET%@AE@%                          Beginning of file
  23623.  
  23624. %@AB@%SEEK_CUR%@AE@%                          Current position of file pointer
  23625.  
  23626. %@AB@%SEEK_END%@AE@%                          End of file
  23627.  
  23628. The %@AB@%lseek%@AE@% function can be used to reposition the pointer anywhere in a file.
  23629. The pointer can also be positioned beyond the end of the file. However, an
  23630. attempt to position the pointer before the beginning of the file causes an
  23631. error.  %@NL@%
  23632. %@NL@%
  23633. %@NL@%
  23634. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23635. %@NL@%
  23636. The %@AB@%lseek%@AE@% function returns the offset, in bytes, of the new position from
  23637. the beginning of the file. The function returns -1L to indicate an error and
  23638. sets %@AB@%errno%@AE@% to one of the following values:  %@NL@%
  23639. %@NL@%
  23640. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  23641. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23642. %@AB@%EBADF%@AE@%                             Invalid file handle
  23643.  
  23644. %@AB@%EINVAL%@AE@%                            Invalid value for %@AI@%origin%@AE@%, or position 
  23645.                                   specified by %@AI@%offset%@AE@% is before the 
  23646.                                   beginning of the file
  23647.  
  23648. On devices incapable of seeking (such as terminals and printers), the return
  23649. value is undefined.  %@NL@%
  23650. %@NL@%
  23651. %@NL@%
  23652. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23653. %@NL@%
  23654.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  23655. %@NL@%
  23656. %@NL@%
  23657. %@NL@%
  23658. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23659. %@NL@%
  23660. %@AB@%fseek, tell%@AE@%  %@NL@%
  23661. %@NL@%
  23662. %@NL@%
  23663. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23664. %@NL@%
  23665. %@AS@%  /* LSEEK.C: This program first opens a file named LSEEK.C.
  23666. %@AS@%   * It then uses lseek to find the beginning of the file,
  23667. %@AS@%   * to find the current position in the file, and to find
  23668. %@AS@%   * the end of the file.
  23669. %@AS@%   */
  23670. %@AS@%  
  23671. %@AS@%  #include <io.h>
  23672. %@AS@%  #include <fcntl.h>
  23673. %@AS@%  #include <stdlib.h>
  23674. %@AS@%  #include <stdio.h>
  23675. %@AS@%  
  23676. %@AS@%  
  23677. %@AS@%  void main()
  23678. %@AS@%  {
  23679. %@AS@%     int fh;
  23680. %@AS@%     long pos;               /* Position of file pointer */
  23681. %@AS@%     char buffer[10];
  23682. %@AS@%  
  23683. %@AS@%     fh = open( "lseek.c", O_RDONLY );
  23684. %@AS@%  
  23685. %@AS@%     /* Seek the beginning of the file: */
  23686. %@AS@%     pos = lseek( fh, 0L, SEEK_SET );
  23687. %@AS@%     if( pos == -1L )
  23688. %@AS@%        perror( "lseek to beginning failed" );
  23689. %@AS@%     else
  23690. %@AS@%        printf( "Position for beginning of file seek = %ld\n", pos );
  23691. %@AS@%  
  23692. %@AS@%     /* Move file pointer a little */
  23693. %@AS@%     read( fh, buffer, 10 );
  23694. %@AS@%  
  23695. %@AS@%     /* Find current position: */
  23696. %@AS@%     pos = lseek( fh, 0L, SEEK_CUR );
  23697. %@AS@%     if( pos == -1L )
  23698. %@AS@%        perror( "lseek to current position failed" );
  23699. %@AS@%     else
  23700. %@AS@%        printf( "Position for current position seek = %ld\n", pos );
  23701. %@AS@%  %@AE@%%@NL@%
  23702. %@NL@%
  23703. %@AS@%  /* Set the end of the file: */
  23704. %@AS@%     pos = lseek( fh, 0L, SEEK_END );
  23705. %@AS@%     if( pos == -1L )
  23706. %@AS@%        perror( "lseek to end failed" );
  23707. %@AS@%     else
  23708. %@AS@%        printf( "Position for end of file seek = %ld\n", pos );
  23709. %@AS@%  
  23710. %@AS@%     close( fh );
  23711. %@AS@%  }%@AE@%%@NL@%
  23712. %@NL@%
  23713. %@NL@%
  23714. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23715. %@NL@%
  23716. %@AS@%  
  23717. %@AS@%  
  23718. %@AS@%  Position for beginning of file seek = 0
  23719. %@AS@%  Position for current position seek = 10
  23720. %@AS@%  Position for end of file seek = 1183%@AE@%%@NL@%
  23721. %@NL@%
  23722. %@NL@%
  23723. %@NL@%
  23724. %@NL@%
  23725. %@QR:ltoa@%%@NL@%
  23726. %@2@%%@CR:C6A01940960 @%%@AB@%ltoa%@AE@%%@EH@%%@NL@%
  23727. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23728. %@NL@%
  23729. %@NL@%
  23730. %@3@%%@AB@%Description%@CR:C6A01940961 @%%@CR:C6A01940962 @% %@CR:C6A01940963 @%%@CR:C6A01940964 @% %@CR:C6A01940965 @%%@AE@%%@EH@%%@NL@%
  23731. %@NL@%
  23732. Converts a long integer to a string.  %@NL@%
  23733. %@NL@%
  23734. %@AB@%#include <stdlib.h>%@AE@%               Required only for function declarations
  23735.  
  23736. %@AS@%  char *ltoa( long value, char *string, int radix );%@AE@%%@NL@%
  23737. %@NL@%
  23738. %@AI@%value%@AE@%                             Number to be converted
  23739.  
  23740. %@AI@%string%@AE@%                            String result
  23741.  
  23742. %@AI@%radix%@AE@%                             Base of %@AI@%value%@AE@%
  23743.  
  23744. %@NL@%
  23745. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23746. %@NL@%
  23747. The %@AB@%ltoa%@AE@% function converts the digits of %@AI@%value%@AE@% to a null-terminated
  23748. character string and stores the result (up to 33 bytes) in %@AI@%string%@AE@%. The %@AI@%radix%@AE@%
  23749. argument specifies the base of %@AI@%value%@AE@%, which must be in the range 2-36. If
  23750. %@AI@%radix%@AE@% equals 10 and %@AI@%value%@AE@% is negative, the first character of the stored
  23751. string is the minus sign (-).  %@NL@%
  23752. %@NL@%
  23753. %@NL@%
  23754. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23755. %@NL@%
  23756. The %@AB@%ltoa%@AE@% function returns a pointer to %@AI@%string%@AE@%. There is no error return.  %@NL@%
  23757. %@NL@%
  23758. %@NL@%
  23759. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23760. %@NL@%
  23761.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  23762. %@NL@%
  23763. %@NL@%
  23764. %@NL@%
  23765. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23766. %@NL@%
  23767. %@AB@%itoa%@AE@%,%@AB@% ultoa%@AE@%  %@NL@%
  23768. %@NL@%
  23769. %@NL@%
  23770. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23771. %@NL@%
  23772. %@AS@%  /* ITOA.C: This program converts integers of various sizes to strings
  23773. %@AS@%   * in various radixes.
  23774. %@AS@%   */
  23775. %@AS@%  
  23776. %@AS@%  #include <stdlib.h>
  23777. %@AS@%  #include <stdio.h>
  23778. %@AS@%  
  23779. %@AS@%  void main()
  23780. %@AS@%  {
  23781. %@AS@%     char buffer[20];
  23782. %@AS@%     int  i = 3445;
  23783. %@AS@%     long l = -344115L;
  23784. %@AS@%     unsigned long ul = 1234567890UL;
  23785. %@AS@%  %@AE@%%@NL@%
  23786. %@NL@%
  23787. %@AS@%  itoa( i, buffer, 10 );
  23788. %@AS@%     printf( "String of integer %d (radix 10): %s\n", i, buffer );
  23789. %@AS@%     itoa( i, buffer, 16 );
  23790. %@AS@%     printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
  23791. %@AS@%     itoa( i, buffer, 2  );
  23792. %@AS@%     printf( "String of integer %d (radix 2): %s\n", i, buffer );
  23793. %@AS@%  
  23794. %@AS@%     ltoa( l, buffer, 16 );
  23795. %@AS@%     printf( "String of long int %ld (radix 16): 0x%s\n", l, buffer );
  23796. %@AS@%  
  23797. %@AS@%     ultoa( ul, buffer, 16 );
  23798. %@AS@%     printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul, buffer );
  23799. %@AS@%  }%@AE@%%@NL@%
  23800. %@NL@%
  23801. %@NL@%
  23802. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23803. %@NL@%
  23804. %@AS@%  
  23805. %@AS@%  
  23806. %@AS@%  String of integer 3445 (radix 10): 3445
  23807. %@AS@%  String of integer 3445 (radix 16): 0xd75
  23808. %@AS@%  String of integer 3445 (radix 2): 110101110101
  23809. %@AS@%  String of long int -344115 (radix 16): 0xfffabfcd
  23810. %@AS@%  String of unsigned long 1234567890 (radix 16): 0x499602d2 %@AE@%%@NL@%
  23811. %@NL@%
  23812. %@NL@%
  23813. %@NL@%
  23814. %@NL@%
  23815. %@QR:_makepath@%%@NL@%
  23816. %@2@%%@CR:C6A01950966 @%%@AB@%_makepath%@AE@%%@EH@%%@NL@%
  23817. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23818. %@NL@%
  23819. %@NL@%
  23820. %@3@%%@AB@%Description%@CR:C6A01950967 @%%@AE@%%@EH@%%@NL@%
  23821. %@NL@%
  23822. Creates a single path name.  %@NL@%
  23823. %@NL@%
  23824. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  23825. %@NL@%
  23826. %@AS@%  void _makepath( char *path, char *drive, char *dir, char *fname, char *ext
  23827. %@AS@%  );%@AE@%%@NL@%
  23828. %@NL@%
  23829. %@AI@%path%@AE@%                              Full path-name buffer
  23830.  
  23831. %@AI@%drive%@AE@%                             Drive letter
  23832.  
  23833. %@AI@%dir%@AE@%                               Directory path
  23834.  
  23835. %@AI@%fname%@AE@%                             File name
  23836.  
  23837. %@AI@%ext%@AE@%                               File extension
  23838.  
  23839. %@NL@%
  23840. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23841. %@NL@%
  23842. The %@AB@%_makepath%@AE@% routine creates a single path name, composed of a drive
  23843. letter, directory path, file name, and file-name extension. The %@AI@%path%@AE@%
  23844. argument should point to an empty buffer large enough to hold the complete
  23845. path name. The constant %@AB@%_MAX_PATH%@AE@%, defined in STDLIB.H, specifies the
  23846. maximum size %@AI@%path%@AE@% that the %@AB@%_makepath%@AE@% function can handle. The other
  23847. arguments point to buffers containing the path-name elements:  %@NL@%
  23848. %@NL@%
  23849. %@AB@%Buffer%@AE@%                            %@AB@%Description%@AE@%
  23850. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23851. %@AI@%drive%@AE@%                             The %@AI@%drive%@AE@% argument contains a letter (A,
  23852.                                   B, etc.) corresponding to the desired 
  23853.                                   drive and an optional trailing colon. 
  23854.                                   The %@AB@%_makepath%@AE@% routine will insert the 
  23855.                                   colon automatically in the composite 
  23856.                                   path name if it is missing. If %@AI@%drive%@AE@% is 
  23857.                                   a null character or an empty string, no 
  23858.                                   drive letter and colon will appear in 
  23859.                                   the composite %@AI@%path%@AE@% string.
  23860.  
  23861. %@AI@%dir%@AE@%                               The %@AI@%dir%@AE@% argument contains the path of 
  23862.                                   directories, not including the drive 
  23863.                                   designator or the actual file name. The 
  23864.                                   trailing slash is optional, and either 
  23865.                                   forward slashes ( %@AB@%/%@AE@% ) or backslashes ( \
  23866.                                   ) or both may be used in a single %@AI@%dir%@AE@% 
  23867.                                   argument. If a trailing slash ( %@AB@%/%@AE@% or \ )
  23868.                                   is not specified, it will be inserted 
  23869.                                   automatically. If %@AI@%dir%@AE@% is a null 
  23870.                                   character or an empty string, no slash 
  23871.                                   is inserted in the composite %@AI@%path%@AE@% 
  23872.                                   string.
  23873.  
  23874. %@AI@%fname%@AE@%                             The %@AI@%fname%@AE@% argument contains the base 
  23875.                                   file name without any extensions. If %@AI@%%@AE@%
  23876.                                   %@AI@%fname%@AE@% is %@AB@%NULL%@AE@% or points to an empty 
  23877.                                   string, no file name is inserted in the 
  23878.                                   composite %@AI@%path%@AE@% string.
  23879.  
  23880. %@AI@%ext%@AE@%                               The %@AI@%ext%@AE@% argument contains the actual 
  23881.                                   file-name extension, with or without a 
  23882.                                   leading period (%@AB@%.%@AE@%). The %@AB@%_makepath%@AE@% 
  23883.                                   routine will insert the period 
  23884.                                   automatically if it does not appear in %@AI@%%@AE@%
  23885.                                   %@AI@%ext%@AE@%. If %@AI@%ext%@AE@% is a null character or an 
  23886.                                   empty string, no period is inserted in 
  23887.                                   the composite %@AI@%path%@AE@% string.
  23888.  
  23889. There are no size limits on any of the above four fields. However, the
  23890. composite path must be no larger than the %@AB@%_MAX_PATH%@AE@% constant. The %@AB@%_MAX_PATH%@AE@%
  23891. limit permits a path name much larger than any of the current versions of
  23892. DOS or OS/2 will handle.  %@NL@%
  23893. %@NL@%
  23894. %@NL@%
  23895. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  23896. %@NL@%
  23897. None.  %@NL@%
  23898. %@NL@%
  23899. %@NL@%
  23900. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  23901. %@NL@%
  23902.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  23903. %@NL@%
  23904. %@NL@%
  23905. %@NL@%
  23906. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  23907. %@NL@%
  23908. %@AB@%_fullpath%@AE@%,  %@AB@%_splitpath%@AE@%  %@NL@%
  23909. %@NL@%
  23910. %@NL@%
  23911. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  23912. %@NL@%
  23913. %@AS@%  /* MAKEPATH.C */
  23914. %@AS@%  #include <stdlib.h>
  23915. %@AS@%  #include <stdio.h>
  23916. %@AS@%  
  23917. %@AS@%  void main()
  23918. %@AS@%  {
  23919. %@AS@%     char path_buffer[_MAX_PATH];
  23920. %@AS@%     char drive[_MAX_DRIVE];
  23921. %@AS@%     char dir[_MAX_DIR];
  23922. %@AS@%     char fname[_MAX_FNAME];
  23923. %@AS@%     char ext[_MAX_EXT];
  23924. %@AS@%  
  23925. %@AS@%     _makepath( path_buffer, "c", "\\c60\\clibref\\", "makepath", "c" );
  23926. %@AS@%     printf( "Path created with _makepath: %s\n\n", path_buffer );
  23927. %@AS@%     _splitpath( path_buffer, drive, dir, fname, ext );
  23928. %@AS@%     printf( "Path extracted with _splitpath:\n" );
  23929. %@AS@%     printf( "  Drive: %s\n", drive );
  23930. %@AS@%     printf( "  Dir: %s\n", dir );
  23931. %@AS@%     printf( "  Filename: %s\n", fname );
  23932. %@AS@%     printf( "  Ext: %s\n", ext );
  23933. %@AS@%  }%@AE@%%@NL@%
  23934. %@NL@%
  23935. %@NL@%
  23936. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  23937. %@NL@%
  23938. %@AS@%  
  23939. %@AS@%  
  23940. %@AS@%  Path created with _makepath: c:\c60\clibref\makepath.c
  23941. %@AS@%  
  23942. %@AS@%  Path extracted with _splitpath:
  23943. %@AS@%    Drive: c:
  23944. %@AS@%    Dir: \c60\clibref\
  23945. %@AS@%    Filename: makepath
  23946. %@AS@%    Ext: .c %@AE@%%@NL@%
  23947. %@NL@%
  23948.  %@NL@%
  23949. %@NL@%
  23950. %@NL@%
  23951. %@QR:malloc@%%@NL@%
  23952. %@2@%%@CR:C6A01960968 @%%@AB@%malloc Functions%@AE@%%@EH@%%@NL@%
  23953. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  23954. %@NL@%
  23955. %@NL@%
  23956. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  23957. %@NL@%
  23958. Allocate memory blocks.  %@NL@%
  23959. %@NL@%
  23960. %@CR:C6A01960969 @%%@CR:C6A01960970 @%%@CR:C6A01960971 @%%@CR:C6A01960972 @%%@CR:C6A01960973 @%%@CR:C6A01960974 @%%@CR:C6A01960975 @%%@CR:C6A01960976 @%  %@NL@%
  23961. %@NL@%
  23962. %@AB@%#include <stdlib.h>%@AE@%               For ANSI compatibility (%@AB@%malloc%@AE@% only)
  23963.  
  23964. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  23965.  
  23966. %@AS@%  void *malloc( size_t size );%@AE@%%@NL@%
  23967. %@NL@%
  23968. %@AS@%  void _based(void) *_bmalloc( _segment seg, size_t size );%@AE@%%@NL@%
  23969. %@NL@%
  23970. %@AS@%  void _far *_fmalloc( size_t size );%@AE@%%@NL@%
  23971. %@NL@%
  23972. %@AS@%  void _near *_nmalloc( size_t size );%@AE@%%@NL@%
  23973. %@NL@%
  23974. %@AI@%size%@AE@%                              Bytes to allocate
  23975.  
  23976. %@AI@%seg%@AE@%                               Based heap segment selector
  23977.  
  23978. %@NL@%
  23979. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  23980. %@NL@%
  23981. Functions in the %@AB@%malloc%@AE@% family allocate a memory block of at least %@AI@%size%@AE@%
  23982. bytes. The block may be larger than %@AI@%size%@AE@% bytes because of space required for
  23983. alignment and maintenance information. If %@AI@%size%@AE@% is 0, each of these functions
  23984. allocates a zero-length item in the heap and returns a valid pointer to that
  23985. item.  %@NL@%
  23986. %@NL@%
  23987. The storage space pointed to by the return value is guaranteed to be
  23988. suitably aligned for storage of any type of object. To get a pointer to a
  23989. type other than %@AB@%void%@AE@%, use a type cast on the return value.  %@NL@%
  23990. %@NL@%
  23991. In large data models (compact-, large-, and huge-model programs), %@AB@%malloc%@AE@%
  23992. maps to %@AB@%_fmalloc%@AE@%. In small data models (tiny-, small-, and medium-model
  23993. programs), %@AB@%malloc%@AE@% maps to %@AB@%_nmalloc%@AE@%.  %@NL@%
  23994. %@NL@%
  23995. The %@AB@%_fmalloc%@AE@% function allocates a memory block of at least %@AI@%size%@AE@% bytes in the
  23996. far heap, which is outside the default data segment. The return value is a
  23997. far pointer to %@AB@%void%@AE@%.  %@NL@%
  23998. %@NL@%
  23999. The %@AB@%_bmalloc%@AE@% function allocates a memory block of at least %@AI@%size%@AE@% bytes in the
  24000. based heap segment specified by the segment selector %@AI@%seg%@AE@%.  %@NL@%
  24001. %@NL@%
  24002. The %@AB@%malloc%@AE@% functions allocate memory in the heap segment specified below.  %@NL@%
  24003. %@NL@%
  24004. %@AB@%Function%@AE@%                          %@AB@%Heap Segment%@AE@%
  24005. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24006. %@AB@%malloc%@AE@%                            Depends on data model of program
  24007.  
  24008. %@AB@%_bmalloc%@AE@%                          Based heap segment specified by %@AI@%seg%@AE@% 
  24009.                                   value
  24010.  
  24011. %@AB@%_fmalloc%@AE@%                          Far heap (outside default data segment)
  24012.  
  24013. %@AB@%_nmalloc%@AE@%                          Near heap (within default data segment)
  24014.  
  24015. If you are creating programs to run in both real mode and protected mode,
  24016. you should probably bind with APILMR.OBJ as well as API.LIB and OS2.LIB.
  24017. This is necessary if a program will use the %@AB@%_nmalloc%@AE@% function.  %@NL@%
  24018. %@NL@%
  24019. The functions listed below call the %@AB@%malloc%@AE@% family of routines. In addition,
  24020. the C start-up code uses %@AB@%malloc%@AE@% to allocate storage for the%@AB@% environ%@AE@%/%@AB@%envp%@AE@% and
  24021. %@AB@%argv%@AE@% strings and arrays.  %@NL@%
  24022. %@NL@%
  24023. The following routines call %@AB@%malloc%@AE@%:  %@NL@%
  24024. %@NL@%
  24025. %@TH:  37  1242 01 10 10 56 @%
  24026. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24027. %@AB@%calloc%@AE@%    fseek     %@AB@%_searchenv%@AE@%
  24028.  
  24029. %@AB@%execv%@AE@%     %@AB@%fsetpos%@AE@%   %@AB@%spawnv%@AE@%
  24030.  
  24031. %@AB@%execve%@AE@%    %@AB@%fullpath%@AE@%  %@AB@%spawnve%@AE@%
  24032.  
  24033. %@AB@%execvp%@AE@%    %@AB@%fwrite%@AE@%    %@AB@%spawnvp%@AE@%
  24034.  
  24035. %@AB@%execvpe%@AE@%   %@AB@%getc%@AE@%      %@AB@%spawnvpe%@AE@%
  24036.  
  24037. %@AB@%execl%@AE@%     %@AB@%getchar%@AE@%   %@AB@%spawnl%@AE@%
  24038.  
  24039. %@AB@%execle%@AE@%    %@AB@%getcwd%@AE@%    %@AB@%spawnle%@AE@%
  24040.  
  24041. %@AB@%execlp%@AE@%    %@AB@%_getcwd%@AE@%   %@AB@%spawnlp%@AE@%
  24042.  
  24043. %@AB@%execlpe%@AE@%   %@AB@%gets%@AE@%      %@AB@%spawnlpe%@AE@%
  24044.  
  24045. %@AB@%fgetc%@AE@%     %@AB@%getw%@AE@%      %@AB@%strdup%@AE@%
  24046.  
  24047. %@AB@%fgetchar%@AE@%  %@AB@%_popen%@AE@%    %@AB@%system%@AE@%
  24048.  
  24049. %@AB@%fgets%@AE@%     %@AB@%printf%@AE@%    %@AB@%scanf%@AE@%
  24050.  
  24051. %@AB@%fprint%@AE@%    %@AB@%putc%@AE@%      %@AB@%setvbuf%@AE@%
  24052.  
  24053. %@AB@%fputc%@AE@%     %@AB@%putchar%@AE@%   %@AB@%tempnam%@AE@%
  24054.  
  24055. %@AB@%fputchar%@AE@%  %@AB@%putenv%@AE@%    %@AB@%ungetc%@AE@%
  24056.  
  24057. %@AB@%fputs%@AE@%     %@AB@%puts%@AE@%      %@AB@%vfprintf%@AE@%
  24058.  
  24059. %@AB@%fread%@AE@%     %@AB@%putw%@AE@%      %@AB@%vprintf%@AE@%
  24060.  
  24061. %@AB@%fscanf%@AE@%    
  24062.  
  24063. %@TE:  37  1242 01 10 10 56 @%
  24064.  
  24065. The following routines call %@AB@%malloc %@AE@%only in the multithread run-time
  24066. libraries (LLIBCMT, LLIBCDLL, CDLLOBJS), not in the regular run-time
  24067. libraries:  %@NL@%
  24068. %@NL@%
  24069. %@TH:   9   365 01 14 11 51 @%
  24070. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24071. %@AB@%asctime%@AE@%       %@AB@%localtime%@AE@%  %@AB@%_strerrpr%@AE@%
  24072.  
  24073. %@AB@%_beginthread%@AE@%  %@AB@%mktime%@AE@%     %@AB@%tmpfile%@AE@%
  24074.  
  24075. %@AB@%ctime%@AE@%         %@AB@%sterror%@AE@%    %@AB@%tmpnam%@AE@%
  24076.  
  24077. %@AB@%gmtime%@AE@%        
  24078.  
  24079. %@TE:   9   365 01 14 11 51 @%
  24080.  
  24081. The following routines call %@AB@%_nmalloc%@AE@%:  %@NL@%
  24082. %@NL@%
  24083. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24084. %@AB@%_nrealloc%@AE@%
  24085.  
  24086. %@AB@%_ncalloc%@AE@%
  24087.  
  24088. %@AB@%_nstrdup%@AE@%
  24089.  
  24090. %@AB@%realloc%@AE@% (in small data models)
  24091.  
  24092.  
  24093. The following routines call %@AB@%_fmalloc%@AE@%:  %@NL@%
  24094. %@NL@%
  24095. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24096. %@AB@%_frealloc%@AE@%
  24097.  
  24098. %@AB@%_fcalloc%@AE@%
  24099.  
  24100. %@AB@%_fstrdup%@AE@%
  24101.  
  24102. %@AB@%realloc%@AE@% (in large data models)
  24103.  
  24104.  
  24105. ────────────────────────────────────────────────────────────────────────────%@NL@%
  24106. %@AB@%C5.1 Differences%@AE@%%@AI@%%@AE@%%@AI@%%@AB@%
  24107. %@AB@%%@AI@%In Microsoft C version 5%@AI@%.1, the %@AE@%%@AI@%_fmalloc%@AE@%%@AI@% function would retry all%@AE@%%@AI@%ocating
  24108. %@AI@%within the default data segment (i.e., in the near heap) if sufficient
  24109. %@AI@%memory was not available outside the default data segment. Version 6.0
  24110. %@AI@%ret%@AE@%%@AI@%urns %@AE@%%@AI@%NULL%@AE@%%@AI@% under t%@AE@%%@AI@%hese conditions.%@AE@%%@AE@%%@NL@%
  24111. %@AI@%In version 5.1, the s%@AI@%tart-up code used %@AE@%%@AI@%malloc%@AE@%%@AI@% only if wild-card expansion
  24112. %@AI@%was used.%@AE@%%@AI@%%@AE@%%@AE@%%@NL@%
  24113.  
  24114. %@AI@%%@AI@%The %@AE@%%@AI@%_freect%@AE@%%@AI@%, %@AE@%%@AI@%_memavl%@AE@%%@AI@%, and%@AE@%%@AI@% _memmax%@AE@%%@AI@% functions called %@AE@%%@AI@%malloc%@AE@%%@AI@% in version 5.1 b%@AE@%%@AI@%ut
  24115. %@AI@%do not do so in version 6.0.%@AE@%%@AE@%%@NL@%
  24116. %@AE@%%@AE@%────────────────────────────────────────────────────────────────────────────%@NL@%%@NL@%
  24117. %@NL@%
  24118. %@NL@%
  24119. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24120. %@NL@%
  24121. The %@AB@%malloc%@AE@% function returns a %@AB@%void%@AE@% pointer to the allocated space. The
  24122. %@AB@%_nmalloc%@AE@% function returns a %@AB@%( void _near * )%@AE@% and %@AB@%_fmalloc%@AE@% returns a %@AB@%( void
  24123. %@AB@%_far * )%@AE@%. The %@AB@%_bmalloc%@AE@% function returns a %@AB@%( void _based( void ) * )%@AE@%.  %@NL@%
  24124. %@NL@%
  24125. The %@AB@%_malloc%@AE@%, %@AB@%_fmalloc%@AE@% and %@AB@%_nmalloc%@AE@% functions return %@AB@%NULL%@AE@% if there is
  24126. insufficient memory available. The %@AB@%_bmalloc%@AE@% function returns %@AB@%_NULLOFF%@AE@% if
  24127. there is insufficient memory available.  %@NL@%
  24128. %@NL@%
  24129. Always check the return from the %@AB@%malloc%@AE@% function, even if the amount of
  24130. memory requested is small.  %@NL@%
  24131. %@NL@%
  24132. %@NL@%
  24133. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24134. %@NL@%
  24135. %@AB@%malloc%@AE@%  %@NL@%
  24136. %@NL@%
  24137. %@AB@%%@AE@% ANSI  %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX%@NL@%
  24138. %@NL@%
  24139. %@NL@%
  24140. %@AB@%_bmalloc, _fmalloc, _nmalloc%@AE@%  %@NL@%
  24141. %@NL@%
  24142.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24143. %@NL@%
  24144. %@NL@%
  24145. %@NL@%
  24146. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24147. %@NL@%
  24148. %@AB@%calloc%@AE@% functions, %@AB@%free%@AE@% functions, %@AB@%realloc%@AE@% functions   %@NL@%
  24149. %@NL@%
  24150. %@NL@%
  24151. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24152. %@NL@%
  24153. %@AS@%  /* MALLOC.C: This program allocates memory with malloc, then frees
  24154. %@AS@%   * the memory with free.
  24155. %@AS@%   */
  24156. %@AS@%  
  24157. %@AS@%  #include <stdlib.h>         /* Definition of _MAX_PATH */
  24158. %@AS@%  #include <stdio.h>
  24159. %@AS@%  #include <malloc.h>
  24160. %@AS@%  
  24161. %@AS@%  void main()
  24162. %@AS@%  {
  24163. %@AS@%     char *string;
  24164. %@AS@%  
  24165. %@AS@%     /* Allocate space for a path name */
  24166. %@AS@%     string = malloc( _MAX_PATH );
  24167. %@AS@%     if( string == NULL )
  24168. %@AS@%        printf( "Insufficient memory available\n" );
  24169. %@AS@%     else
  24170. %@AS@%        printf( "Memory space allocated for pathname\n" );
  24171. %@AS@%     free( string );
  24172. %@AS@%     printf( "Memory freed\n" );
  24173. %@AS@%  }%@AE@%%@NL@%
  24174. %@NL@%
  24175. %@NL@%
  24176. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24177. %@NL@%
  24178. %@AS@%  
  24179. %@AS@%  
  24180. %@AS@%  Memory space allocated for pathname
  24181. %@AS@%  Memory freed %@AE@%%@NL@%
  24182. %@NL@%
  24183. %@NL@%
  24184. %@NL@%
  24185. %@NL@%
  24186. %@QR:matherr@%%@QR:_matherrl@%%@NL@%
  24187. %@2@%%@CR:C6A01970977 @%%@AB@%matherr, _matherrl%@AE@%%@EH@%%@NL@%
  24188. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24189. %@NL@%
  24190. %@NL@%
  24191. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  24192. %@NL@%
  24193. Handle math errors.  %@NL@%
  24194. %@NL@%
  24195. %@CR:C6A01970978 @%%@CR:C6A01970979 @%%@AS@%  #include <math.h>%@AE@%%@NL@%
  24196. %@NL@%
  24197. %@AS@%  int matherr( struct exception *except );%@AE@%%@NL@%
  24198. %@NL@%
  24199. %@AS@%  int _matherrl( struct _exceptionl *except );%@AE@%%@NL@%
  24200. %@NL@%
  24201. %@AI@%except%@AE@%                            Pointer to structure containing error 
  24202.                                   information
  24203.  
  24204. %@NL@%
  24205. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24206. %@NL@%
  24207. The %@AB@%matherr%@AE@% functions process errors generated by the functions of the math
  24208. library. The math functions call the appropriate %@AB@%matherr%@AE@% routine whenever an
  24209. error is detected. The %@AB@%_matherrl%@AE@% function uses the 80-bit, 10-byte
  24210. coprocessor form of arguments and return values. See the reference page on
  24211. the long double functions for more details on this data type.  %@NL@%
  24212. %@NL@%
  24213. The user can provide a different definition of the %@AB@%matherr%@AE@% or %@AB@%_matherrl%@AE@%
  24214. function to carry out special error handling.  %@NL@%
  24215. %@NL@%
  24216. When an error occurs in a math routine, %@AB@%matherr%@AE@% is called with a pointer to
  24217. an %@AB@%exception%@AE@% type structure (defined in%@AB@% %@AE@%MATH.H) as an argument.%@CR:C6A01970980 @%%@CR:C6A01970981 @%  %@NL@%
  24218. %@NL@%
  24219. The %@AB@%exception%@AE@% structure contains the following elements:  %@NL@%
  24220. %@NL@%
  24221. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  24222. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24223. %@AB@%int type%@AE@%                          Exception type
  24224.  
  24225. %@AB@%char *name%@AE@%                        Name of function where error occurred
  24226.  
  24227. %@AB@%double arg1%@AE@%, %@AB@%arg2%@AE@%                 First and second (if any) argument to 
  24228.                                   function
  24229.  
  24230. %@AB@%double%@AE@%%@AI@% %@AE@%%@AB@%retval%@AE@%                     Value to be returned by function
  24231.  
  24232. The%@AB@% type%@AE@% specifies the type of math error. It is one of the following
  24233. values, defined in MATH.H:  %@NL@%
  24234. %@NL@%
  24235. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  24236. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24237. %@AB@%DOMAIN%@AE@%                            Argument domain error %@CR:C6A01970982 @%
  24238.  
  24239. %@AB@%SING%@AE@%                              Argument singularity %@CR:C6A01970983 @%%@CR:C6A01970984 @%
  24240.  
  24241. %@AB@%OVERFLOW%@AE@%                          Overflow range error %@CR:C6A01970985 @%
  24242.  
  24243. %@AB@%PLOSS%@AE@%                             Partial loss of significance %@CR:C6A01970986 @%
  24244.  
  24245. %@AB@%TLOSS%@AE@%                             Total loss of significance %@CR:C6A01970987 @%
  24246.  
  24247. %@AB@%UNDERFLOW%@AE@%                         Underflow range error %@CR:C6A01970988 @%
  24248.  
  24249. The structure member%@AB@% name%@AE@% is a pointer to a null-terminated string
  24250. containing the name of the function that caused the error. The structure
  24251. members %@AB@%arg1%@AE@% and %@AB@%arg2%@AE@% specify the values that caused the error. (If only one
  24252. argument is given, it is stored in %@AB@%arg1%@AE@%.)  %@NL@%
  24253. %@NL@%
  24254. The default return value for the given error is %@AB@%retval%@AE@%. If you change the
  24255. return value, remember that the return value must specify whether an error
  24256. actually occurred. If the %@AB@%matherr%@AE@% function returns 0, an error message is
  24257. displayed and %@AB@%errno%@AE@% is set to an appropriate error value. If %@AB@%matherr%@AE@% returns
  24258. a nonzero value, no error message is displayed, and %@AB@%errno%@AE@% remains unchanged.
  24259. %@NL@%
  24260. %@NL@%
  24261. %@NL@%
  24262. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24263. %@NL@%
  24264. The %@AB@%matherr%@AE@% functions should return 0 to indicate an error, and a nonzero
  24265. value to indicate successful corrective action.  %@NL@%
  24266. %@NL@%
  24267. %@NL@%
  24268. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24269. %@NL@%
  24270. %@AB@%matherr%@AE@%  %@NL@%
  24271. %@NL@%
  24272.  ANSI  %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX%@NL@%
  24273. %@NL@%
  24274. %@NL@%
  24275. %@AB@%_matherrl%@AE@%  %@NL@%
  24276. %@NL@%
  24277.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24278. %@NL@%
  24279. %@NL@%
  24280. %@NL@%
  24281. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24282. %@NL@%
  24283. %@AB@%acos%@AE@% functions, %@AB@%asin%@AE@% functions, %@AB@%atan%@AE@% functions, %@AB@%bessel%@AE@% functions, %@AB@%cabs%@AE@%, %@AB@%cos%@AE@%
  24284. functions, %@AB@%exp%@AE@%, %@AB@%hypot%@AE@%, %@AB@%log%@AE@% functions, %@AB@%pow%@AE@%, %@AB@%sin%@AE@% functions, %@AB@%sqrt%@AE@%, %@AB@%tan%@AE@%
  24285. functions  %@NL@%
  24286. %@NL@%
  24287. %@NL@%
  24288. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24289. %@NL@%
  24290. %@AS@%  /* MATHERR.C: To use matherr, you must turn off the Extended Dictionary
  24291. %@AS@%   * flag within the Microsoft Programmer's WorkBench environment, or use
  24292. %@AS@%the 
  24293. %@AS@%   * /NOE linker option outside the environment. For example:
  24294. %@AS@%   *      CL matherr.c /link /NOE
  24295. %@AS@%   */
  24296. %@AS@%  
  24297. %@AS@%  #include <math.h>
  24298. %@AS@%  #include <string.h>
  24299. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  24300. %@NL@%
  24301. %@AS@%  void main()
  24302. %@AS@%  {
  24303. %@AS@%     /* Do several math operations that cause errors. The matherr
  24304. %@AS@%      * routine handles DOMAIN errors, but lets the system handle
  24305. %@AS@%      * other errors normally.
  24306. %@AS@%      */
  24307. %@AS@%     printf( "log( -2.0 ) = %e\n", log( -2.0 ) );
  24308. %@AS@%     printf( "log10( -5.0 ) = %e\n", log10( -5.0 ) );
  24309. %@AS@%     printf( "log( 0.0 ) = %e\n", log( 0.0 ) );
  24310. %@AS@%  }
  24311. %@AS@%  
  24312. %@AS@%  /* Handle several math errors caused by passing a negative argument
  24313. %@AS@%   * to log or log10 (DOMAIN errors). When this happens, matherr returns
  24314. %@AS@%   * the natural or base-10 logarithm of the absolute value of the
  24315. %@AS@%   * argument and suppresses the usual error message.
  24316. %@AS@%   */
  24317. %@AS@%  int matherr( struct exception *except )
  24318. %@AS@%  {
  24319. %@AS@%      /* Handle DOMAIN errors for log or log10. */
  24320. %@AS@%      if( except->type == DOMAIN )
  24321. %@AS@%      {
  24322. %@AS@%          if( strcmp( except->name, "log" ) == 0 )
  24323. %@AS@%          {
  24324. %@AS@%              except->retval = log( -(except->arg1) );
  24325. %@AS@%              printf( "Special: using absolute value: %s: DOMAIN error\n",
  24326. %@AS@%                      except->name );
  24327. %@AS@%              return 1;
  24328. %@AS@%          }
  24329. %@AS@%          else if( strcmp( except->name, "log10" ) == 0 )
  24330. %@AS@%          {
  24331. %@AS@%              except->retval = log10( -(except->arg1) );
  24332. %@AS@%              printf( "Special: using absolute value: %s: DOMAIN error\n",
  24333. %@AS@%                      except->name );
  24334. %@AS@%              return 1;
  24335. %@AS@%          }
  24336. %@AS@%      }
  24337. %@AS@%      else
  24338. %@AS@%      {
  24339. %@AS@%          printf( "Normal: " );
  24340. %@AS@%          return 0;    /* Else use the default actions */
  24341. %@AS@%      }
  24342. %@AS@%  }%@AE@%%@NL@%
  24343. %@NL@%
  24344. %@NL@%
  24345. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24346. %@NL@%
  24347. %@AS@%  
  24348. %@AS@%  
  24349. %@AS@%  Special: using absolute value: log: DOMAIN error
  24350. %@AS@%  log( -2.0 ) = 6.931472e-001
  24351. %@AS@%  Special: using absolute value: log10: DOMAIN error
  24352. %@AS@%  log10( -5.0 ) = 6.989700e-001
  24353. %@AS@%  Normal: log: SING error
  24354. %@AS@%  log( 0.0 ) = -1.797693e+308 %@AE@%%@NL@%
  24355. %@NL@%
  24356. %@NL@%
  24357. %@NL@%
  24358. %@NL@%
  24359. %@QR:max@%%@NL@%
  24360. %@2@%%@CR:C6A01980989 @%%@AB@%max%@AE@%%@EH@%%@NL@%
  24361. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24362. %@NL@%
  24363. %@NL@%
  24364. %@3@%%@AB@%Description%@CR:C6A01980990 @%%@CR:C6A01980991 @%%@AE@%%@EH@%%@NL@%
  24365. %@NL@%
  24366. Returns the larger of two values.  %@NL@%
  24367. %@NL@%
  24368. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  24369. %@NL@%
  24370. %@AS@%  type max( type a, type b );%@AE@%%@NL@%
  24371. %@NL@%
  24372. %@AI@%type%@AE@%                              Any numeric data type
  24373.  
  24374. %@AI@%a%@AE@%,%@AI@% b%@AE@%                              Values of any numeric type to be 
  24375.                                   compared
  24376.  
  24377. %@NL@%
  24378. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24379. %@NL@%
  24380. The %@AB@%max%@AE@% macro compares two values and returns the value of the larger one.
  24381. The arguments can be of any numeric data type, signed or unsigned. Both
  24382. arguments and the return value must be of the same data type.  %@NL@%
  24383. %@NL@%
  24384. %@NL@%
  24385. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24386. %@NL@%
  24387. The macro returns the larger of the two arguments.  %@NL@%
  24388. %@NL@%
  24389. %@NL@%
  24390. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24391. %@NL@%
  24392.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24393. %@NL@%
  24394. %@NL@%
  24395. %@NL@%
  24396. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24397. %@NL@%
  24398. %@AB@%min%@AE@%  %@NL@%
  24399. %@NL@%
  24400. %@NL@%
  24401. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24402. %@NL@%
  24403. %@AS@%  /* MINMAX.C */
  24404. %@AS@%  #include <stdlib.h>
  24405. %@AS@%  #include <stdio.h>
  24406. %@AS@%  
  24407. %@AS@%  void main()
  24408. %@AS@%  {
  24409. %@AS@%     int a = 10;
  24410. %@AS@%     int b = 21;
  24411. %@AS@%  
  24412. %@AS@%     printf( "The larger of %d and %d is %d\n",  a, b, max( a, b ) );
  24413. %@AS@%     printf( "The smaller of %d and %d is %d\n", a, b, min( a, b ) );
  24414. %@AS@%  }%@AE@%%@NL@%
  24415. %@NL@%
  24416. %@NL@%
  24417. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24418. %@NL@%
  24419. %@AS@%  
  24420. %@AS@%  
  24421. %@AS@%  The larger of 10 and 21 is 21
  24422. %@AS@%  The smaller of 10 and 21 is 10%@AE@%%@NL@%
  24423. %@NL@%
  24424. %@NL@%
  24425. %@NL@%
  24426. %@NL@%
  24427. %@QR:_memavl@%%@NL@%
  24428. %@2@%%@CR:C6A01990992 @%%@AB@%_memavl%@AE@%%@EH@%%@NL@%
  24429. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24430. %@NL@%
  24431. %@NL@%
  24432. %@3@%%@AB@%Description%@CR:C6A01990993 @%%@CR:C6A01990994 @%%@AE@%%@EH@%%@NL@%
  24433. %@NL@%
  24434. Returns the size of memory available.  %@NL@%
  24435. %@NL@%
  24436. %@AS@%  #include <malloc.h> Required only for function declarations%@AE@%%@NL@%
  24437. %@NL@%
  24438. %@AS@%  size_t _memavl( void );%@AE@%%@NL@%
  24439. %@NL@%
  24440. %@NL@%
  24441. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24442. %@NL@%
  24443. The %@AB@%_memavl%@AE@% function returns the approximate size, in bytes, of the memory
  24444. available for dynamic memory allocation in the near heap (default data
  24445. segment). The %@AB@%_memavl%@AE@% function can be used with %@AB@%calloc%@AE@%, %@AB@%malloc%@AE@%, or %@AB@%realloc%@AE@%
  24446. in tiny, small, and medium memory models and with %@AB@%_ncalloc%@AE@%, %@AB@%_nmalloc%@AE@% or
  24447. %@AB@%_nrealloc%@AE@% in any memory model.  %@NL@%
  24448. %@NL@%
  24449. The number returned by the %@AB@%_memavl%@AE@% function may not be the number of
  24450. contiguous bytes. Consequently, a call to %@AB@%malloc%@AE@% requesting allocation of
  24451. the size returned by %@AB@%_memavl%@AE@% may not succeed. Use the %@AB@%_memmax%@AE@% function to
  24452. find the size of the largest available contiguous block of memory.  %@NL@%
  24453. %@NL@%
  24454. %@NL@%
  24455. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24456. %@NL@%
  24457. The %@AB@%_memavl%@AE@% function returns the size in bytes as an unsigned integer.  %@NL@%
  24458. %@NL@%
  24459. %@NL@%
  24460. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24461. %@NL@%
  24462.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24463. %@NL@%
  24464. %@NL@%
  24465. %@NL@%
  24466. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24467. %@NL@%
  24468. %@AB@%calloc%@AE@% functions,  %@AB@%_freect%@AE@%, %@AB@%malloc%@AE@% functions,  %@AB@%_memmax%@AE@%, %@AB@%realloc%@AE@% functions  %@NL@%
  24469. %@NL@%
  24470. %@NL@%
  24471. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24472. %@NL@%
  24473. %@AS@%  /* MEMAVL.C: This program uses _memavl to determine the amount of
  24474. %@AS@%   * memory available for dynamic allocation. It then uses malloc to
  24475. %@AS@%   * allocate space for 5,000 long integers and uses _memavl again to
  24476. %@AS@%   * determine the new amount of available memory.
  24477. %@AS@%   */
  24478. %@AS@%  
  24479. %@AS@%  #include <malloc.h>
  24480. %@AS@%  #include <stdio.h>
  24481. %@AS@%  
  24482. %@AS@%  void main()
  24483. %@AS@%  {
  24484. %@AS@%     long *longptr;
  24485. %@AS@%  
  24486. %@AS@%     printf( "Memory available before _nmalloc = %u\n", _memavl() );
  24487. %@AS@%     if( (longptr = _nmalloc( 5000 * sizeof( long ) )) != NULL )
  24488. %@AS@%     {
  24489. %@AS@%        printf( "Memory available after _nmalloc = %u\n", _memavl() );
  24490. %@AS@%        _nfree( longptr );
  24491. %@AS@%     }
  24492. %@AS@%  }%@AE@%%@NL@%
  24493. %@NL@%
  24494. %@NL@%
  24495. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24496. %@NL@%
  24497. %@AS@%  
  24498. %@AS@%  
  24499. %@AS@%  Memory available before _nmalloc = 60906
  24500. %@AS@%  Memory available after _nmalloc = 40390%@AE@%%@NL@%
  24501. %@NL@%
  24502. %@NL@%
  24503. %@NL@%
  24504. %@NL@%
  24505. %@QR:memccpy@%%@QR:_fmemccpy@%%@NL@%
  24506. %@2@%%@CR:C6A02000995 @%%@AB@%memccpy, _fmemccpy%@AE@%%@EH@%%@NL@%
  24507. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24508. %@NL@%
  24509. %@NL@%
  24510. %@3@%%@AB@%Description%@CR:C6A02000996 @%%@CR:C6A02000997 @% %@CR:C6A02000998 @%%@CR:C6A02000999 @%%@AE@%%@EH@%%@NL@%
  24511. %@NL@%
  24512. Copy characters from a buffer.  %@NL@%
  24513. %@NL@%
  24514. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations
  24515.  
  24516. %@AB@%#include <string.h>%@AE@%               Use either STRING.H or MEMORY.H
  24517.  
  24518. %@AS@%  void *memccpy( void *dest, void *src, int c, unsigned int count );%@AE@%%@NL@%
  24519. %@NL@%
  24520. %@AS@%  void _far * _far _fmemccpy( void _far *dest, void _far *src, int c,
  24521. %@AS@%  unsigned int count );%@AE@%%@NL@%
  24522. %@NL@%
  24523. %@AI@%dest%@AE@%                              Pointer to destination
  24524.  
  24525. %@AI@%src%@AE@%                               Pointer to source
  24526.  
  24527. %@AI@%c%@AE@%                                 Last character to copy
  24528.  
  24529. %@AI@%count%@AE@%                             Number of characters
  24530.  
  24531. %@NL@%
  24532. %@3@%%@AB@%Remarks%@CR:C6A02001000 @%%@AE@%%@EH@%%@NL@%
  24533. %@NL@%
  24534. The %@AB@%memccpy%@AE@% and %@AB@%_fmemccpy %@AE@%functions copy 0 or more bytes of%@AB@% %@AE@%%@AI@%src%@AE@% to %@AI@%dest%@AE@%,
  24535. halting when the character %@AI@%c%@AE@% has been copied or when %@AI@%count%@AE@% bytes have been
  24536. copied, whichever comes first.  %@NL@%
  24537. %@NL@%
  24538. The %@AB@%_fmemccpy%@AE@% function is a model-independent (large-model) form of the
  24539. %@AB@%memccpy%@AE@% function. It can be called from any point in any program.  %@NL@%
  24540. %@NL@%
  24541. %@NL@%
  24542. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24543. %@NL@%
  24544. If the character %@AI@%c%@AE@% is copied, %@AB@%memccpy%@AE@% or %@AB@%_fmemccpy%@AE@% returns a pointer (or far
  24545. pointer) to the byte in %@AI@%dest%@AE@% that immediately follows the character. If %@AI@%c%@AE@% is
  24546. not copied, %@AB@%memccpy%@AE@% returns %@AB@%NULL%@AE@%.  %@NL@%
  24547. %@NL@%
  24548. %@NL@%
  24549. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24550. %@NL@%
  24551. %@AB@%memccpy%@AE@%  %@NL@%
  24552. %@NL@%
  24553.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   UNIX    XENIX %@NL@%
  24554. %@NL@%
  24555. %@NL@%
  24556. %@AB@%_fmemccpy%@AE@%  %@NL@%
  24557. %@NL@%
  24558.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24559. %@NL@%
  24560. %@NL@%
  24561. %@NL@%
  24562. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24563. %@NL@%
  24564. %@AB@%memchr%@AE@%,%@AB@% memcmp%@AE@%,%@AB@% memcpy%@AE@%,%@AB@% memset%@AE@%  %@NL@%
  24565. %@NL@%
  24566. %@NL@%
  24567. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24568. %@NL@%
  24569. %@AS@%  /* MEMCCPY.C */
  24570. %@AS@%  #include <memory.h>
  24571. %@AS@%  #include <stdio.h>
  24572. %@AS@%  #include <string.h>
  24573. %@AS@%  
  24574. %@AS@%  char string1[60] = "The quick brown dog jumps over the lazy fox";
  24575. %@AS@%  
  24576. %@AS@%  void main()
  24577. %@AS@%  {
  24578. %@AS@%     char buffer[61];
  24579. %@AS@%     char *pdest;
  24580. %@AS@%  
  24581. %@AS@%     printf( "Function:\tmemccpy 60 characters or to character 's'\n" );
  24582. %@AS@%     printf( "Source:\t\t%s\n", string1 );
  24583. %@AS@%     pdest = memccpy( buffer, string1, 's', 60 );
  24584. %@AS@%     *pdest = '\0';
  24585. %@AS@%     printf( "Result:\t\t%s\n", buffer );
  24586. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( buffer ) );
  24587. %@AS@%  }%@AE@%%@NL@%
  24588. %@NL@%
  24589. %@NL@%
  24590. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24591. %@NL@%
  24592. %@AS@%  
  24593. %@AS@%  
  24594. %@AS@%  Function:       memccpy 60 characters or to character 's'
  24595. %@AS@%  Source:         The quick brown dog jumps over the lazy fox
  24596. %@AS@%  Result:         The quick brown dog jumps
  24597. %@AS@%  Length:         25 characters %@AE@%%@NL@%
  24598. %@NL@%
  24599. %@NL@%
  24600. %@NL@%
  24601. %@NL@%
  24602. %@QR:memchr@%%@QR:_fmemchr@%%@NL@%
  24603. %@2@%%@CR:C6A02011001 @%%@AB@%memchr, _fmemchr%@AE@%%@EH@%%@NL@%
  24604. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24605. %@NL@%
  24606. %@NL@%
  24607. %@3@%%@AB@%Description%@CR:C6A02011002 @%%@CR:C6A02011003 @% %@CR:C6A02011004 @%%@CR:C6A02011005 @%%@AE@%%@EH@%%@NL@%
  24608. %@NL@%
  24609. Find characters in a buffer.  %@NL@%
  24610. %@NL@%
  24611. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations
  24612.  
  24613. %@AB@%#include <string.h>%@AE@%               Use either STRING.H (for ANSI 
  24614.                                   compatibility) or MEMORY.H
  24615.  
  24616. %@AS@%  void *memchr( const void *buf, int c, size_t count );%@AE@%%@NL@%
  24617. %@NL@%
  24618. %@AS@%  void _far * _far _fmemchr( const void _far *buf, int c, size_t count );%@AE@%%@NL@%
  24619. %@NL@%
  24620. %@AI@%buf%@AE@%                               Pointer to buffer
  24621.  
  24622. %@AI@%c%@AE@%                                 Character to look for
  24623.  
  24624. %@AI@%count%@AE@%                             Number of characters
  24625.  
  24626. %@NL@%
  24627. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24628. %@NL@%
  24629. The %@AB@%memchr%@AE@% and %@AB@%_fmemchr%@AE@% functions look for the first occurrence of %@AI@%c%@AE@% in the
  24630. first %@AI@%count%@AE@% bytes of %@AI@%buf%@AE@%. They stop when they find %@AI@%c%@AE@% or when they have
  24631. checked the first %@AI@%count%@AE@% bytes. %@CR:C6A02011006 @%  %@NL@%
  24632. %@NL@%
  24633. The %@AB@%_fmemchr%@AE@% function is a model-independent (large-model) form of the
  24634. %@AB@%memchr%@AE@% function. It can be called from any point in any program.  %@NL@%
  24635. %@NL@%
  24636. %@NL@%
  24637. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24638. %@NL@%
  24639. If successful, %@AB@%memchr%@AE@% or %@AB@%_fmemchr%@AE@% returns a pointer (or a far pointer) to
  24640. the first location of %@AI@%c%@AE@% in %@AI@%buf%@AE@%. Otherwise, they return %@AB@%NULL%@AE@%.  %@NL@%
  24641. %@NL@%
  24642. %@NL@%
  24643. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24644. %@NL@%
  24645. %@AB@%memchr%@AE@%  %@NL@%
  24646. %@NL@%
  24647. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  24648. %@NL@%
  24649. %@NL@%
  24650. %@AB@%_fmemchr%@AE@%  %@NL@%
  24651. %@NL@%
  24652.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24653. %@NL@%
  24654. %@NL@%
  24655. %@NL@%
  24656. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24657. %@NL@%
  24658. %@AB@%memccpy%@AE@%,%@AB@% memcmp%@AE@%,%@AB@% memcpy%@AE@%,%@AB@% memset%@AE@%,%@AB@% strchr%@AE@%  %@NL@%
  24659. %@NL@%
  24660. %@NL@%
  24661. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24662. %@NL@%
  24663. %@AS@%  /* MEMCHR.C */
  24664. %@AS@%  #include <memory.h>
  24665. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  24666. %@NL@%
  24667. %@AS@%  int  ch = 'r';
  24668. %@AS@%  char str[] =    "lazy";
  24669. %@AS@%  char string[] = "The quick brown dog jumps over the lazy fox";
  24670. %@AS@%  char fmt1[] =   "         1         2         3         4         5";
  24671. %@AS@%  char fmt2[] =   "12345678901234567890123456789012345678901234567890";
  24672. %@AS@%  
  24673. %@AS@%  void main()
  24674. %@AS@%  {
  24675. %@AS@%     char *pdest;
  24676. %@AS@%     int result;
  24677. %@AS@%  
  24678. %@AS@%     printf( "String to be searched:\n\t\t%s\n", string );
  24679. %@AS@%     printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
  24680. %@AS@%  
  24681. %@AS@%     printf( "Search char:\t%c\n", ch );
  24682. %@AS@%     pdest = memchr( string, ch, sizeof( string ) );
  24683. %@AS@%     result = pdest - string + 1;
  24684. %@AS@%     if( pdest != NULL )
  24685. %@AS@%        printf( "Result:\t\t%c found at position %d\n\n", ch, result );
  24686. %@AS@%     else
  24687. %@AS@%        printf( "Result:\t\t%c not found\n" );
  24688. %@AS@%  }%@AE@%%@NL@%
  24689. %@NL@%
  24690. %@NL@%
  24691. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24692. %@NL@%
  24693. %@AS@%  
  24694. %@AS@%  
  24695. %@AS@%  String to be searched:
  24696. %@AS@%                  The quick brown dog jumps over the lazy fox
  24697. %@AS@%                           1         2         3         4         5
  24698. %@AS@%                  12345678901234567890123456789012345678901234567890
  24699. %@AS@%  
  24700. %@AS@%  Search char:    r
  24701. %@AS@%  Result:         r found at position 12 %@AE@%%@NL@%
  24702. %@NL@%
  24703. %@NL@%
  24704. %@NL@%
  24705. %@NL@%
  24706. %@QR:memcmp@%%@QR:_fmemcmp@%%@NL@%
  24707. %@2@%%@CR:C6A02021007 @%%@AB@%memcmp, _fmemcmp%@AE@%%@EH@%%@NL@%
  24708. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24709. %@NL@%
  24710. %@NL@%
  24711. %@3@%%@AB@%Description%@CR:C6A02021008 @%%@CR:C6A02021009 @% %@CR:C6A02021010 @%%@CR:C6A02021011 @%%@AE@%%@EH@%%@NL@%
  24712. %@NL@%
  24713. Compare characters in two buffers.  %@NL@%
  24714. %@NL@%
  24715. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations
  24716.  
  24717. %@AB@%#include <string.h>%@AE@%               Use either STRING.H (for ANSI 
  24718.                                   compatibility) or MEMORY.H
  24719.  
  24720. %@AS@%  int memcmp( const void *buf1, const void *buf2, size_t count );%@AE@%%@NL@%
  24721. %@NL@%
  24722. %@AS@%  int _far _fmemcmp( const void _far *buf1, const void _far *buf2, size_t
  24723. %@AS@%  count );%@AE@%%@NL@%
  24724. %@NL@%
  24725. %@AI@%buf1%@AE@%                              First buffer
  24726.  
  24727. %@AI@%buf2%@AE@%                              Second buffer
  24728.  
  24729. %@AI@%count%@AE@%                             Number of characters
  24730.  
  24731. %@NL@%
  24732. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24733. %@NL@%
  24734. The %@AB@%memcmp%@AE@% and %@AB@%_fmemcmp%@AE@% functions compare the first %@AI@%count%@AE@% bytes of %@AI@%buf1%@AE@% and
  24735. %@AI@%buf2%@AE@% and return a value indicating their relationship, as follows: %@CR:C6A02021012 @%  %@NL@%
  24736. %@NL@%
  24737. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  24738. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24739. < 0                               %@AI@%buf1%@AE@% less than %@AI@%buf2%@AE@%
  24740.  
  24741. = 0                               %@AI@%buf1%@AE@% identical to %@AI@%buf2%@AE@%
  24742.  
  24743. > 0                               %@AI@%buf1%@AE@% greater than %@AI@%buf2%@AE@%
  24744.  
  24745. The %@AB@%_fmemcmp%@AE@% function is a model-independent (large-model) form of the
  24746. %@AB@%memcmp%@AE@% function. It can be called from any point in program.  %@NL@%
  24747. %@NL@%
  24748. There is a semantic difference between the function version of %@AB@%memcmp %@AE@%and
  24749. its intrinsic version. The function version supports huge pointers in
  24750. compact-, large-, and huge-model programs, but the intrinsic version does
  24751. not.  %@NL@%
  24752. %@NL@%
  24753. %@NL@%
  24754. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24755. %@NL@%
  24756. The %@AB@%memcmp%@AE@% function returns an integer value, as described above.  %@NL@%
  24757. %@NL@%
  24758. %@NL@%
  24759. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24760. %@NL@%
  24761. %@AB@%memcmp%@AE@%  %@NL@%
  24762. %@NL@%
  24763. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  24764. %@NL@%
  24765. %@NL@%
  24766. %@AB@%_fmemcmp%@AE@%  %@NL@%
  24767. %@NL@%
  24768.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24769. %@NL@%
  24770. %@NL@%
  24771. %@NL@%
  24772. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24773. %@NL@%
  24774. %@AB@%memccpy%@AE@%, %@AB@%memchr%@AE@%, %@AB@%memcpy%@AE@%, %@AB@%memset%@AE@%, %@AB@%strcmp%@AE@%, %@AB@%strncmp%@AE@%  %@NL@%
  24775. %@NL@%
  24776. %@NL@%
  24777. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24778. %@NL@%
  24779. %@AS@%  /* MEMCMP.C: This program uses memcmp to compare the strings named
  24780. %@AS@%   * first and second. If the first 19 bytes of the strings are
  24781. %@AS@%   * equal, the program considers the strings to be equal.
  24782. %@AS@%   */
  24783. %@AS@%  
  24784. %@AS@%  #include <string.h>
  24785. %@AS@%  #include <stdio.h>
  24786. %@AS@%  
  24787. %@AS@%  void main()
  24788. %@AS@%  {
  24789. %@AS@%     char first[]  = "12345678901234567890";
  24790. %@AS@%     char second[] = "12345678901234567891";
  24791. %@AS@%     int result;
  24792. %@AS@%  
  24793. %@AS@%     printf( "Compare '%.19s' to '%.19s':\n", first, second );
  24794. %@AS@%     result = memcmp( first, second, 19 );
  24795. %@AS@%     if( result < 0 )
  24796. %@AS@%        printf( "First is less than second.\n" );
  24797. %@AS@%     else if( result == 0 )
  24798. %@AS@%        printf( "First is equal to second.\n" );
  24799. %@AS@%     else if( result > 0 )
  24800. %@AS@%        printf( "First is greater than second.\n" );
  24801. %@AS@%     printf( "Compare '%.20s' to '%.20s':\n", first, second );
  24802. %@AS@%     result = memcmp( first, second, 20 );
  24803. %@AS@%     if( result < 0 )
  24804. %@AS@%        printf( "First is less than second.\n" );
  24805. %@AS@%     else if( result == 0 )
  24806. %@AS@%        printf( "First is equal to second.\n" );
  24807. %@AS@%     else if( result > 0 )
  24808. %@AS@%        printf( "First is greater than second.\n" );
  24809. %@AS@%  }%@AE@%%@NL@%
  24810. %@NL@%
  24811. %@NL@%
  24812. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24813. %@NL@%
  24814. %@AS@%  
  24815. %@AS@%  
  24816. %@AS@%  Compare '1234567890123456789' to '1234567890123456789':
  24817. %@AS@%  First is equal to second.
  24818. %@AS@%  Compare '12345678901234567890' to '12345678901234567891':
  24819. %@AS@%  First is less than second. %@AE@%%@NL@%
  24820. %@NL@%
  24821. %@NL@%
  24822. %@NL@%
  24823. %@NL@%
  24824. %@QR:memcpy@%%@QR:_fmemcpy@%%@NL@%
  24825. %@2@%%@CR:C6A02031013 @%%@AB@%memcpy, _fmemcpy%@AE@%%@EH@%%@NL@%
  24826. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24827. %@NL@%
  24828. %@NL@%
  24829. %@3@%%@AB@%Description%@CR:C6A02031014 @%%@CR:C6A02031015 @% %@CR:C6A02031016 @%%@CR:C6A02031017 @%%@AE@%%@EH@%%@NL@%
  24830. %@NL@%
  24831. Copy characters between buffers.  %@NL@%
  24832. %@NL@%
  24833. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations%@AB@%%@AE@%
  24834.  
  24835. %@AB@%#include <string.h>%@AE@%               Use either STRING.H (for ANSI 
  24836.                                   compatibility) or MEMORY.H
  24837.  
  24838. %@AS@%  void *memcpy( void *dest, const void *src, size_t count );%@AE@%%@NL@%
  24839. %@NL@%
  24840. %@AS@%  void _far  * _far _fmemcpy( void _far *dest, const void _far *src, size_t
  24841. %@AS@%  count );%@AE@%%@NL@%
  24842. %@NL@%
  24843. %@AI@%dest%@AE@%                              New buffer
  24844.  
  24845. %@AI@%src%@AE@%                               Buffer to copy from
  24846.  
  24847. %@AI@%count%@AE@%                             Number of characters to copy
  24848.  
  24849. %@NL@%
  24850. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24851. %@NL@%
  24852. The %@AB@%memcpy%@AE@% and %@AB@%_fmemcpy%@AE@% functions copy %@AI@%count%@AE@% bytes of %@AI@%src%@AE@% to %@AI@%dest%@AE@%. If the
  24853. source and destination overlap, these functions do not ensure that the
  24854. original source bytes in the overlapping region are copied before being
  24855. overwritten. Use %@AB@%memmove%@AE@% to handle overlapping regions. %@CR:C6A02031018 @%%@CR:C6A02031019 @%  %@NL@%
  24856. %@NL@%
  24857. The %@AB@%_fmemcpy%@AE@% function is a model-independent (large-model) form of the
  24858. %@AB@%memcpy%@AE@% function. It can be called from any point in any program.  %@NL@%
  24859. %@NL@%
  24860. There is a semantic difference between the function version of %@AB@%memcpy%@AE@% and
  24861. its intrinsic version. The function version supports huge pointers in
  24862. compact-, large-, and huge-model programs, but the intrinsic version does
  24863. not.  %@NL@%
  24864. %@NL@%
  24865. %@NL@%
  24866. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  24867. %@NL@%
  24868. The %@AB@%memcpy%@AE@% and %@AB@%_fmemcpy%@AE@% functions return a pointer to %@AI@%dest%@AE@%.  %@NL@%
  24869. %@NL@%
  24870. %@NL@%
  24871. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  24872. %@NL@%
  24873. %@AB@%memcpy%@AE@%  %@NL@%
  24874. %@NL@%
  24875. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  24876. %@NL@%
  24877. %@NL@%
  24878. %@AB@%_fmemcpy%@AE@%  %@NL@%
  24879. %@NL@%
  24880.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  24881. %@NL@%
  24882. %@NL@%
  24883. %@NL@%
  24884. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  24885. %@NL@%
  24886. %@AB@%memccpy%@AE@%, %@AB@%memchr%@AE@%, %@AB@%memcmp%@AE@%, %@AB@%memmove%@AE@%, %@AB@%memset%@AE@%, %@AB@%strcpy%@AE@%, %@AB@%strncpy%@AE@%  %@NL@%
  24887. %@NL@%
  24888. %@NL@%
  24889. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  24890. %@NL@%
  24891. %@AS@%  /* MEMCPY.C. Illustrate overlapping copy: memmove handles it
  24892. %@AS@%   * correctly; memcpy does not.
  24893. %@AS@%   */
  24894. %@AS@%  #include <memory.h>
  24895. %@AS@%  #include <string.h>
  24896. %@AS@%  #include <stdio.h>
  24897. %@AS@%  
  24898. %@AS@%  char string1[60] = "The quick brown dog jumps over the lazy fox";
  24899. %@AS@%  char string2[60] = "The quick brown fox jumps over the lazy dog";
  24900. %@AS@%  /*                           1         2         3         4         5 
  24901. %@AS@%   *                  12345678901234567890123456789012345678901234567890 
  24902. %@AS@%   */
  24903. %@AS@%  void main()
  24904. %@AS@%  {
  24905. %@AS@%     printf( "Function:\tmemcpy without overlap\n" );
  24906. %@AS@%     printf( "Source:\t\t%s\n", string1 + 40 );
  24907. %@AS@%     printf( "Destination:\t%s\n", string1 + 16 );
  24908. %@AS@%     memcpy( string1 + 16, string1 + 40, 3 );
  24909. %@AS@%     printf( "Result:\t\t%s\n", string1 );
  24910. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );
  24911. %@AS@%  
  24912. %@AS@%     /* Restore string1 to original contents */
  24913. %@AS@%     memcpy( string1 + 16, string2 + 40, 3 );
  24914. %@AS@%  
  24915. %@AS@%     printf( "Function:\tmemmove with overlap\n" );
  24916. %@AS@%     printf( "Source:\t\t%s\n", string2 + 4 );
  24917. %@AS@%     printf( "Destination:\t%s\n", string2 + 10 );
  24918. %@AS@%     memmove( string2 + 10, string2 + 4, 40 );
  24919. %@AS@%     printf( "Result:\t\t%s\n", string2 );
  24920. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( string2 ) );
  24921. %@AS@%  
  24922. %@AS@%     printf( "Function:\tmemcpy with overlap\n" );
  24923. %@AS@%     printf( "Source:\t\t%s\n", string1 + 4 );
  24924. %@AS@%     printf( "Destination:\t%s\n", string1 + 10 );
  24925. %@AS@%     memcpy( string1 + 10, string1 + 4, 40 );
  24926. %@AS@%     printf( "Result:\t\t%s\n", string1 );
  24927. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );
  24928. %@AS@%  
  24929. %@AS@%  }%@AE@%%@NL@%
  24930. %@NL@%
  24931. %@NL@%
  24932. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  24933. %@NL@%
  24934. %@AS@%  
  24935. %@AS@%  
  24936. %@AS@%  Function:       memcpy without overlap
  24937. %@AS@%  Source:         fox
  24938. %@AS@%  Destination:    dog jumps over the lazy fox
  24939. %@AS@%  Result:         The quick brown fox jumps over the lazy fox
  24940. %@AS@%  Length:         43 characters
  24941. %@AS@%  
  24942. %@AS@%  Function:       memmove with overlap
  24943. %@AS@%  Source:         quick brown fox jumps over the lazy dog
  24944. %@AS@%  Destination:    brown fox jumps over the lazy dog
  24945. %@AS@%  Result:         The quick quick brown fox jumps over the lazy dog
  24946. %@AS@%  Length:         49 characters
  24947. %@AS@%  
  24948. %@AS@%  Function:       memcpy with overlap
  24949. %@AS@%  Source:         quick brown dog jumps over the lazy fox
  24950. %@AS@%  Destination:    brown dog jumps over the lazy fox
  24951. %@AS@%  Result:         The quick quick quick quick quick quick quick quic
  24952. %@AS@%  Length:         50 characters %@AE@%%@NL@%
  24953. %@NL@%
  24954. %@NL@%
  24955. %@NL@%
  24956. %@NL@%
  24957. %@QR:memicmp@%%@QR:_fmemicmp@%%@NL@%
  24958. %@2@%%@CR:C6A02041020 @%%@AB@%memicmp, _fmemicmp%@AE@%%@EH@%%@NL@%
  24959. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24960. %@NL@%
  24961. %@NL@%
  24962. %@3@%%@AB@%Description%@CR:C6A02041021 @%%@CR:C6A02041022 @% %@CR:C6A02041023 @%%@CR:C6A02041024 @%%@AE@%%@EH@%%@NL@%
  24963. %@NL@%
  24964. Compare characters in two buffers (case-insensitive).  %@NL@%
  24965. %@NL@%
  24966. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations
  24967.  
  24968. %@AB@%#include <string.h>%@AE@%               Use either STRING.H or MEMORY.H
  24969.  
  24970. %@AS@%  int memicmp( void *buf1, void *buf2, unsigned int count );%@AE@%%@NL@%
  24971. %@NL@%
  24972. %@AS@%  int _far _fmemicmp( void _far *buf1, void _far *buf2, unsigned int count
  24973. %@AS@%  );%@AE@%%@NL@%
  24974. %@NL@%
  24975. %@AI@%buf1%@AE@%                              First buffer
  24976.  
  24977. %@AI@%buf2%@AE@%                              Second buffer
  24978.  
  24979. %@AI@%count%@AE@%                             Number of characters
  24980.  
  24981. %@NL@%
  24982. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  24983. %@NL@%
  24984. The %@AB@%memicmp%@AE@% and %@AB@%_fmemicmp%@AE@% functions compare the first %@AI@%count%@AE@% characters of
  24985. the two buffers %@AI@%buf1%@AE@% and %@AI@%buf2%@AE@% byte-by-byte. The comparison is made without
  24986. regard to the case of letters in the two buffers; that is, uppercase and
  24987. lowercase letters are considered equivalent. The %@AB@%memicmp%@AE@% and %@AB@%_fmemicmp%@AE@%
  24988. functions return a value indicating the relationship of the two buffers, as
  24989. follows: %@CR:C6A02041025 @%  %@NL@%
  24990. %@NL@%
  24991. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  24992. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  24993. < 0                               %@AI@%buf1%@AE@% less than %@AI@%buf2%@AE@%
  24994.  
  24995. = 0                               %@AI@%buf1%@AE@% identical to %@AI@%buf2%@AE@%
  24996.  
  24997. > 0                               %@AI@%buf1%@AE@% greater than %@AI@%buf2%@AE@%
  24998.  
  24999. The %@AB@%_fmemicmp%@AE@% function is a model-independent (large-model) form of the
  25000. %@AB@%memicmp%@AE@% function. It can be called from any point in any program.  %@NL@%
  25001. %@NL@%
  25002. %@NL@%
  25003. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25004. %@NL@%
  25005. The %@AB@%memicmp%@AE@% and %@AB@%_fmemicmp%@AE@% functions return an integer value, as described
  25006. above.  %@NL@%
  25007. %@NL@%
  25008. %@NL@%
  25009. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25010. %@NL@%
  25011. %@AB@%memicmp%@AE@%  %@NL@%
  25012. %@NL@%
  25013.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  25014. %@NL@%
  25015. %@NL@%
  25016. %@AB@%_fmemicmp%@AE@%  %@NL@%
  25017. %@NL@%
  25018.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25019. %@NL@%
  25020. %@NL@%
  25021. %@NL@%
  25022. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25023. %@NL@%
  25024. %@AB@%memccpy%@AE@%, %@AB@%memchr%@AE@%, %@AB@%memcmp%@AE@%, %@AB@%memcpy%@AE@%, %@AB@%memset%@AE@%, %@AB@%stricmp%@AE@%, %@AB@%strnicmp%@AE@%  %@NL@%
  25025. %@NL@%
  25026. %@NL@%
  25027. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25028. %@NL@%
  25029. %@AS@%  /* MEMICMP.C: This program uses memicmp to compare the first
  25030. %@AS@%   * 29 letters of the strings named first and second without
  25031. %@AS@%   * regard to the case of the letters.
  25032. %@AS@%   */
  25033. %@AS@%  
  25034. %@AS@%  #include <memory.h>
  25035. %@AS@%  #include <stdio.h>
  25036. %@AS@%  #include <string.h>
  25037. %@AS@%  
  25038. %@AS@%  void main()
  25039. %@AS@%  {
  25040. %@AS@%     int result;
  25041. %@AS@%     char first[]  = "Those Who Will Not Learn from History";
  25042. %@AS@%     char second[] = "THOSE WHO WILL NOT LEARN FROM their mistakes";
  25043. %@AS@%     /* Note that the 29th character is right here ^ */
  25044. %@AS@%  
  25045. %@AS@%     printf( "Compare '%.29s' to '%.29s'\n", first, second );
  25046. %@AS@%     result = memicmp( first, second, 29 );
  25047. %@AS@%     if( result < 0 )
  25048. %@AS@%        printf( "First is less than second.\n" );
  25049. %@AS@%     else if( result == 0 )
  25050. %@AS@%        printf( "First is equal to second.\n" );
  25051. %@AS@%     else if( result > 0 )
  25052. %@AS@%        printf( "First is greater than second.\n" );
  25053. %@AS@%  }%@AE@%%@NL@%
  25054. %@NL@%
  25055. %@NL@%
  25056. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25057. %@NL@%
  25058. %@AS@%  
  25059. %@AS@%  
  25060. %@AS@%  Compare 'Those Who Will Not Learn from' to 'THOSE WHO WILL NOT LEARN FROM'
  25061. %@AS@%  First is equal to second. %@AE@%%@NL@%
  25062. %@NL@%
  25063. %@NL@%
  25064. %@NL@%
  25065. %@NL@%
  25066. %@QR:_memmax@%%@NL@%
  25067. %@2@%%@CR:C6A02051026 @%%@AB@%_memmax%@AE@%%@EH@%%@NL@%
  25068. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25069. %@NL@%
  25070. %@NL@%
  25071. %@3@%%@AB@%Description%@CR:C6A02051027 @%%@CR:C6A02051028 @%%@AE@%%@EH@%%@NL@%
  25072. %@NL@%
  25073. Finds the size of the largest contiguous memory block.  %@NL@%
  25074. %@NL@%
  25075. %@AS@%  #include <malloc.h>%@AE@%%@NL@%
  25076. %@NL@%
  25077. %@AS@%  size_t _memmax( void );%@AE@%%@NL@%
  25078. %@NL@%
  25079. %@NL@%
  25080. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25081. %@NL@%
  25082. The %@AB@%_memmax%@AE@% function returns the size (in bytes) of the largest contiguous
  25083. block of memory that can be allocated from the near heap (i.e., the default
  25084. data segment). Calling %@AB@%_nmalloc%@AE@% with the value returned by the %@AB@%_memmax%@AE@%
  25085. function will succeed as long as %@AB@%_memmax%@AE@% returns a nonzero value.  %@NL@%
  25086. %@NL@%
  25087. %@NL@%
  25088. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25089. %@NL@%
  25090. The function returns the block size, if successful. Otherwise, it returns 0,
  25091. indicating that nothing more can be allocated from the near heap.  %@NL@%
  25092. %@NL@%
  25093. %@NL@%
  25094. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25095. %@NL@%
  25096.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25097. %@NL@%
  25098. %@NL@%
  25099. %@NL@%
  25100. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25101. %@NL@%
  25102. %@AB@%malloc%@AE@% functions, %@AB@%msize%@AE@% functions  %@NL@%
  25103. %@NL@%
  25104. %@NL@%
  25105. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25106. %@NL@%
  25107. %@AS@%  /* MEMMAX.C: This program uses _memmax and _nmalloc to allocate
  25108. %@AS@%   * the largest block of memory available in the near heap.
  25109. %@AS@%   */
  25110. %@AS@%  
  25111. %@AS@%  #include <stddef.h>
  25112. %@AS@%  #include <malloc.h>
  25113. %@AS@%  #include <stdio.h>
  25114. %@AS@%  
  25115. %@AS@%  void main()
  25116. %@AS@%  {
  25117. %@AS@%     size_t contig;
  25118. %@AS@%     char *p;%@AE@%%@NL@%
  25119. %@NL@%
  25120. %@AS@%  /* Determine contiguous memory size */
  25121. %@AS@%     contig = _memmax();
  25122. %@AS@%     printf( "Largest block of available memory is %u bytes long\n", contig
  25123. %@AS@%);
  25124. %@AS@%     if( contig )
  25125. %@AS@%     {
  25126. %@AS@%        p = _nmalloc( contig * sizeof( int ) );
  25127. %@AS@%        if( p == NULL )
  25128. %@AS@%           printf( "Error with malloc (should never occur)\n" );
  25129. %@AS@%        else
  25130. %@AS@%        {
  25131. %@AS@%           printf( "Maximum allocation succeeded\n" );
  25132. %@AS@%           free( p );
  25133. %@AS@%        }
  25134. %@AS@%     }
  25135. %@AS@%     else
  25136. %@AS@%        printf( "Near heap is already full\n" );
  25137. %@AS@%  }%@AE@%%@NL@%
  25138. %@NL@%
  25139. %@NL@%
  25140. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25141. %@NL@%
  25142. %@AS@%  
  25143. %@AS@%  
  25144. %@AS@%  Largest block of available memory is 60844 bytes long
  25145. %@AS@%  Maximum allocation succeeded%@AE@%%@NL@%
  25146. %@NL@%
  25147. %@NL@%
  25148. %@NL@%
  25149. %@NL@%
  25150. %@QR:memmove@%%@QR:_fmemmove@%%@NL@%
  25151. %@2@%%@CR:C6A02061029 @%%@AB@%memmove, _fmemmove%@AE@%%@EH@%%@NL@%
  25152. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25153. %@NL@%
  25154. %@NL@%
  25155. %@3@%%@AB@%Description%@CR:C6A02061030 @%%@CR:C6A02061031 @% %@CR:C6A02061032 @%%@CR:C6A02061033 @%%@AE@%%@EH@%%@NL@%
  25156. %@NL@%
  25157. Move one buffer to another.  %@NL@%
  25158. %@NL@%
  25159. %@AS@%  #include <string.h>%@AE@%%@NL@%
  25160. %@NL@%
  25161. %@AS@%  void *memmove( void *dest, const void *src, size_t count );%@AE@%%@NL@%
  25162. %@NL@%
  25163. %@AS@%  void _far * _far _fmemmove( void _far *dest, const void _far *src, size_t
  25164. %@AS@%  count );%@AE@%%@NL@%
  25165. %@NL@%
  25166. %@AI@%dest%@AE@%                              Destination object
  25167.  
  25168. %@AI@%src%@AE@%                               Source object
  25169.  
  25170. %@AI@%count%@AE@%                             Number of characters to copy
  25171.  
  25172. %@NL@%
  25173. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25174. %@NL@%
  25175. The %@AB@%memmove%@AE@% and %@AB@%_fmemmove%@AE@% functions copy %@AI@%count%@AE@% characters from the source
  25176. (%@AI@%src%@AE@%) to the destination (%@AI@%dest%@AE@%). If some regions of the source area and the
  25177. destination overlap, the %@AB@%memmove%@AE@% and %@AB@%_fmemmove%@AE@% functions ensure that the
  25178. original source bytes in the overlapping region are copied before being
  25179. overwritten.  %@NL@%
  25180. %@NL@%
  25181. The %@AB@%_fmemmove%@AE@% function is a model-independent (large-model) form of the
  25182. %@AB@%memmove%@AE@% function. It can be called from any point in any program.  %@NL@%
  25183. %@NL@%
  25184. %@NL@%
  25185. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25186. %@NL@%
  25187. The %@AB@%memmove%@AE@% and %@AB@%_fmemmove%@AE@% functions return the value of %@AI@%dest%@AE@%.  %@NL@%
  25188. %@NL@%
  25189. %@NL@%
  25190. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25191. %@NL@%
  25192. %@AB@%memmove%@AE@%  %@NL@%
  25193. %@NL@%
  25194. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25195. %@NL@%
  25196. %@NL@%
  25197. %@AB@%_fmemmove%@AE@%  %@NL@%
  25198. %@NL@%
  25199.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25200. %@NL@%
  25201. %@NL@%
  25202. %@NL@%
  25203. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25204. %@NL@%
  25205. %@AB@%memccpy%@AE@%, %@AB@%memcpy%@AE@%, %@AB@%strccpy%@AE@%, %@AB@%strncpy%@AE@%  %@NL@%
  25206. %@NL@%
  25207. %@NL@%
  25208. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25209. %@NL@%
  25210. %@AS@%  /* MEMCPY.C. Illustrate overlapping copy: memmove handles it
  25211. %@AS@%   * correctly; memcpy does not.
  25212. %@AS@%   */
  25213. %@AS@%  #include <memory.h>
  25214. %@AS@%  #include <string.h>
  25215. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  25216. %@NL@%
  25217. %@AS@%  char string1[60] = "The quick brown dog jumps over the lazy fox";
  25218. %@AS@%  char string2[60] = "The quick brown fox jumps over the lazy dog";
  25219. %@AS@%  /*                           1         2         3         4         5 
  25220. %@AS@%   *                  12345678901234567890123456789012345678901234567890 
  25221. %@AS@%   */
  25222. %@AS@%  void main()
  25223. %@AS@%  {
  25224. %@AS@%     printf( "Function:\tmemcpy without overlap\n" );
  25225. %@AS@%     printf( "Source:\t\t%s\n", string1 + 40 );
  25226. %@AS@%     printf( "Destination:\t%s\n", string1 + 16 );
  25227. %@AS@%     memcpy( string1 + 16, string1 + 40, 3 );
  25228. %@AS@%     printf( "Result:\t\t%s\n", string1 );
  25229. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );
  25230. %@AS@%  
  25231. %@AS@%     /* Restore string1 to original contents */
  25232. %@AS@%     memcpy( string1 + 16, string2 + 40, 3 );
  25233. %@AS@%  
  25234. %@AS@%     printf( "Function:\tmemmove with overlap\n" );
  25235. %@AS@%     printf( "Source:\t\t%s\n", string2 + 4 );
  25236. %@AS@%     printf( "Destination:\t%s\n", string2 + 10 );
  25237. %@AS@%     memmove( string2 + 10, string2 + 4, 40 );
  25238. %@AS@%     printf( "Result:\t\t%s\n", string2 );
  25239. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( string2 ) );
  25240. %@AS@%  
  25241. %@AS@%     printf( "Function:\tmemcpy with overlap\n" );
  25242. %@AS@%     printf( "Source:\t\t%s\n", string1 + 4 );
  25243. %@AS@%     printf( "Destination:\t%s\n", string1 + 10 );
  25244. %@AS@%     memcpy( string1 + 10, string1 + 4, 40 );
  25245. %@AS@%     printf( "Result:\t\t%s\n", string1 );
  25246. %@AS@%     printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );
  25247. %@AS@%  
  25248. %@AS@%  }%@AE@%%@NL@%
  25249. %@NL@%
  25250. %@NL@%
  25251. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25252. %@NL@%
  25253. %@AS@%  
  25254. %@AS@%  
  25255. %@AS@%  Function:       memcpy without overlap
  25256. %@AS@%  Source:         fox
  25257. %@AS@%  Destination:    dog jumps over the lazy fox
  25258. %@AS@%  Result:         The quick brown fox jumps over the lazy fox
  25259. %@AS@%  Length:         43 characters
  25260. %@AS@%  
  25261. %@AS@%  Function:       memmove with overlap
  25262. %@AS@%  Source:         quick brown fox jumps over the lazy dog
  25263. %@AS@%  Destination:    brown fox jumps over the lazy dog
  25264. %@AS@%  Result:         The quick quick brown fox jumps over the lazy dog
  25265. %@AS@%  Length:         49 characters%@AE@%%@NL@%
  25266. %@NL@%
  25267. %@AS@%  Function:       memcpy with overlap
  25268. %@AS@%  Source:         quick brown dog jumps over the lazy fox
  25269. %@AS@%  Destination:    brown dog jumps over the lazy fox
  25270. %@AS@%  Result:         The quick quick quick quick quick quick quick quic
  25271. %@AS@%  Length:         50 characters %@AE@%%@NL@%
  25272. %@NL@%
  25273. %@NL@%
  25274. %@NL@%
  25275. %@NL@%
  25276. %@QR:memset@%%@QR:_fmemset@%%@NL@%
  25277. %@2@%%@CR:C6A02071034 @%%@AB@%memset, _fmemset%@AE@%%@EH@%%@NL@%
  25278. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25279. %@NL@%
  25280. %@NL@%
  25281. %@3@%%@AB@%Description%@CR:C6A02071035 @%%@CR:C6A02071036 @% %@CR:C6A02071037 @%%@CR:C6A02071038 @%%@AE@%%@EH@%%@NL@%
  25282. %@NL@%
  25283. Set buffers to a specified character.  %@NL@%
  25284. %@NL@%
  25285. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations
  25286.  
  25287. %@AB@%#include <string.h>%@AE@%               Use either STRING.H (for ANSI 
  25288.                                   compatibility) or MEMORY.H
  25289.  
  25290. %@AS@%  void *memset( void *dest, int c, size_t count );%@AE@%%@NL@%
  25291. %@NL@%
  25292. %@AS@%  void _far * _far _fmemset( void _far *dest, int c, size_t count );%@AE@%%@NL@%
  25293. %@NL@%
  25294. %@AI@%dest%@AE@%                              Pointer to destination
  25295.  
  25296. %@AI@%c%@AE@%                                 Character to set
  25297.  
  25298. %@AI@%count%@AE@%                             Number of characters
  25299.  
  25300. %@NL@%
  25301. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25302. %@NL@%
  25303. The %@AB@%memset%@AE@% and %@AB@%_fmemset%@AE@% functions set the first %@AI@%count%@AE@% bytes of %@AI@%dest%@AE@% to the
  25304. character %@AI@%c%@AE@%.%@CR:C6A02071039 @%  %@NL@%
  25305. %@NL@%
  25306. The %@AB@%_fmemset%@AE@% function is a model-independent (large-model) form of the
  25307. %@AB@%memset%@AE@% function. It can be called from any point in any program.  %@NL@%
  25308. %@NL@%
  25309. There is a semantic difference between the function version of %@AB@%memset%@AE@% and
  25310. its intrinsic version. The function version supports huge pointers in
  25311. compact-, large-, and huge-model programs, but the intrinsic version does
  25312. not.  %@NL@%
  25313. %@NL@%
  25314. %@NL@%
  25315. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25316. %@NL@%
  25317. The %@AB@%memset%@AE@% and %@AB@%_fmemset%@AE@% functions return a pointer to %@AI@%dest%@AE@%.  %@NL@%
  25318. %@NL@%
  25319. %@NL@%
  25320. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25321. %@NL@%
  25322. %@AB@%memset%@AE@%  %@NL@%
  25323. %@NL@%
  25324. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  25325. %@NL@%
  25326. %@NL@%
  25327. %@AB@%_fmemset%@AE@%  %@NL@%
  25328. %@NL@%
  25329.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   UNIX    XENIX %@NL@%
  25330. %@NL@%
  25331. %@NL@%
  25332. %@NL@%
  25333. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25334. %@NL@%
  25335. %@AB@%memccpy%@AE@%, %@AB@%memchr%@AE@%, %@AB@%memcmp%@AE@%, %@AB@%memcpy%@AE@%, %@AB@%strnset%@AE@%  %@NL@%
  25336. %@NL@%
  25337. %@NL@%
  25338. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25339. %@NL@%
  25340. %@AS@%  /* MEMSET.C: This program uses memset to set the first four bytes
  25341. %@AS@%   * of buffer to "*".
  25342. %@AS@%   */%@AE@%%@NL@%
  25343. %@NL@%
  25344. %@AS@%  #include <memory.h>
  25345. %@AS@%  #include <stdio.h>
  25346. %@AS@%  
  25347. %@AS@%  void main()
  25348. %@AS@%  {
  25349. %@AS@%     char buffer[] = "This is a test of the memset function";
  25350. %@AS@%  
  25351. %@AS@%     printf( "Before: %s\n", buffer );
  25352. %@AS@%     memset( buffer, '*', 4 );
  25353. %@AS@%     printf( "After:  %s\n", buffer );
  25354. %@AS@%  }%@AE@%%@NL@%
  25355. %@NL@%
  25356. %@NL@%
  25357. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25358. %@NL@%
  25359. %@AS@%  
  25360. %@AS@%  
  25361. %@AS@%  Before: This is a test of the memset function
  25362. %@AS@%  After:  **** is a test of the memset function %@AE@%%@NL@%
  25363. %@NL@%
  25364. %@NL@%
  25365. %@NL@%
  25366. %@NL@%
  25367. %@QR:min@%%@NL@%
  25368. %@2@%%@CR:C6A02081040 @%%@AB@%min%@AE@%%@EH@%%@NL@%
  25369. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25370. %@NL@%
  25371. %@NL@%
  25372. %@3@%%@AB@%Description%@CR:C6A02081041 @%%@CR:C6A02081042 @%%@AE@%%@EH@%%@NL@%
  25373. %@NL@%
  25374. Returns the smaller of two values.  %@NL@%
  25375. %@NL@%
  25376. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  25377. %@NL@%
  25378. %@AS@%  type min( type a, type b );%@AE@%%@NL@%
  25379. %@NL@%
  25380. %@AI@%type%@AE@%                              Any numeric data type
  25381.  
  25382. %@AI@%a%@AE@%,%@AI@% b%@AE@%                              Values of any numeric type to be 
  25383.                                   compared
  25384.  
  25385. %@NL@%
  25386. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25387. %@NL@%
  25388. The %@AB@%min%@AE@% macro compares two values and returns the value of the smaller one.
  25389. The arguments can be of any numeric data type, signed or unsigned. Both
  25390. arguments and the return value must be of the same data type.  %@NL@%
  25391. %@NL@%
  25392. %@NL@%
  25393. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25394. %@NL@%
  25395. The macro returns the smaller of the two arguments.  %@NL@%
  25396. %@NL@%
  25397. %@NL@%
  25398. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25399. %@NL@%
  25400.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25401. %@NL@%
  25402. %@NL@%
  25403. %@NL@%
  25404. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25405. %@NL@%
  25406. %@AB@%max%@AE@%  %@NL@%
  25407. %@NL@%
  25408. %@NL@%
  25409. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25410. %@NL@%
  25411. %@AS@%  /* MINMAX.C */
  25412. %@AS@%  #include <stdlib.h>
  25413. %@AS@%  #include <stdio.h>
  25414. %@AS@%  
  25415. %@AS@%  void main()
  25416. %@AS@%  {
  25417. %@AS@%     int a = 10;
  25418. %@AS@%     int b = 21;
  25419. %@AS@%  
  25420. %@AS@%     printf( "The larger of %d and %d is %d\n",  a, b, max( a, b ) );
  25421. %@AS@%     printf( "The smaller of %d and %d is %d\n", a, b, min( a, b ) );
  25422. %@AS@%  }%@AE@%%@NL@%
  25423. %@NL@%
  25424. %@NL@%
  25425. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25426. %@NL@%
  25427. %@AS@%  
  25428. %@AS@%  
  25429. %@AS@%  The larger of 10 and 21 is 21
  25430. %@AS@%  The smaller of 10 and 21 is 10%@AE@%%@NL@%
  25431. %@NL@%
  25432. %@NL@%
  25433. %@NL@%
  25434. %@NL@%
  25435. %@QR:mkdir@%%@NL@%
  25436. %@2@%%@CR:C6A02091043 @%%@AB@%mkdir%@AE@%%@EH@%%@NL@%
  25437. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25438. %@NL@%
  25439. %@NL@%
  25440. %@3@%%@AB@%Description%@CR:C6A02091044 @%%@CR:C6A02091045 @%%@CR:C6A02091046 @%%@AE@%%@EH@%%@NL@%
  25441. %@NL@%
  25442. Creates a new directory.  %@NL@%
  25443. %@NL@%
  25444. %@AB@%#include <direct.h>%@AE@%               Required only for function declarations
  25445.  
  25446. %@AS@%  int mkdir( char *dirname );%@AE@%%@NL@%
  25447. %@NL@%
  25448. %@AI@%dirname%@AE@%                           Path name for new directory
  25449.  
  25450. %@NL@%
  25451. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25452. %@NL@%
  25453. The %@AB@%mkdir%@AE@% function creates a new directory with the specified %@AI@%dirname%@AE@%. Only
  25454. one directory can be created at a time, so only the last component of
  25455. %@AI@%dirname%@AE@% can name a new directory.  %@NL@%
  25456. %@NL@%
  25457. The %@AB@%mkdir%@AE@% function does not do any translation of path-name delimiters. Both
  25458. DOS and OS/ 2 accept either " \" or "/ "  internally as valid delimiters
  25459. within path names.  %@NL@%
  25460. %@NL@%
  25461. %@NL@%
  25462. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25463. %@NL@%
  25464. The %@AB@%mkdir%@AE@% function returns the value 0 if the new directory was created. A
  25465. return value of -1 indicates an error, and %@AB@%errno%@AE@% is set to one of the
  25466. following values:  %@NL@%
  25467. %@NL@%
  25468. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  25469. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25470. %@AB@%EACCES%@AE@%                            Directory not created. The given name is
  25471.                                   the name of an
  25472.                                   existing file, directory, or device.
  25473.  
  25474. %@AB@%ENOENT%@AE@%                            Path name not found.
  25475.  
  25476. %@NL@%
  25477. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25478. %@NL@%
  25479.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25480. %@NL@%
  25481. %@NL@%
  25482. %@NL@%
  25483. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25484. %@NL@%
  25485. %@AB@%chdir%@AE@%, %@AB@%rmdir%@AE@%  %@NL@%
  25486. %@NL@%
  25487. %@NL@%
  25488. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25489. %@NL@%
  25490. %@AS@%  /* MAKEDIR.C */
  25491. %@AS@%  #include <direct.h>
  25492. %@AS@%  #include <stdlib.h>
  25493. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  25494. %@NL@%
  25495. %@AS@%  void main()
  25496. %@AS@%  {
  25497. %@AS@%     int result;
  25498. %@AS@%  
  25499. %@AS@%     if( mkdir( "\\testtmp" ) == 0 )
  25500. %@AS@%     {
  25501. %@AS@%        printf( "Directory '\\testtmp' was successfully created\n" );
  25502. %@AS@%        system( "dir \\testtmp" );
  25503. %@AS@%        if( rmdir( "\\testtmp" ) == 0 )
  25504. %@AS@%           printf( "Directory '\\testtmp' was successfully removed\n"  );
  25505. %@AS@%        else
  25506. %@AS@%           printf( "Problem removing directory '\\testtmp'\n" );
  25507. %@AS@%     }
  25508. %@AS@%     else
  25509. %@AS@%        printf( "Problem creating directory '\\testtmp'\n" );
  25510. %@AS@%  }%@AE@%%@NL@%
  25511. %@NL@%
  25512. %@NL@%
  25513. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25514. %@NL@%
  25515. %@AS@%  
  25516. %@AS@%  
  25517. %@AS@%  Directory '\testtmp' was successfully created
  25518. %@AS@%  
  25519. %@AS@%   The volume label in drive C is OS2.
  25520. %@AS@%   Directory of C:\TESTTMP
  25521. %@AS@%  
  25522. %@AS@%  .            <DIR>      6-19-89  11:20a
  25523. %@AS@%  ..           <DIR>      6-19-89  11:20a
  25524. %@AS@%       2 File(s)   12730368 bytes free
  25525. %@AS@%  Directory '\testtmp' was successfully removed %@AE@%%@NL@%
  25526. %@NL@%
  25527. %@NL@%
  25528. %@NL@%
  25529. %@NL@%
  25530. %@QR:mktemp@%%@NL@%
  25531. %@2@%%@CR:C6A02101047 @%%@AB@%mktemp%@AE@%%@EH@%%@NL@%
  25532. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25533. %@NL@%
  25534. %@NL@%
  25535. %@3@%%@AB@%Description%@CR:C6A02101048 @%%@CR:C6A02101049 @%%@CR:C6A02101050 @%%@AE@%%@EH@%%@NL@%
  25536. %@NL@%
  25537. Creates a unique file name.  %@NL@%
  25538. %@NL@%
  25539. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  25540.  
  25541. %@AS@%  char *mktemp( char *template );%@AE@%%@NL@%
  25542. %@NL@%
  25543. %@AI@%template%@AE@%                          File-name pattern
  25544.  
  25545. %@NL@%
  25546. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25547. %@NL@%
  25548. The %@AB@%mktemp%@AE@% function creates a unique file name by modifying the given
  25549. %@AI@%template%@AE@% argument. The %@AI@%template%@AE@% argument has the form:  %@NL@%
  25550. %@NL@%
  25551. %@AI@%base%@AE@%%@AB@%XXXXXX%@AE@%  %@NL@%
  25552. %@NL@%
  25553. where %@AI@%base%@AE@% is the part of the new file name that you supply, and the %@AB@%X%@AE@%'s are
  25554. placeholders for the part supplied by %@AB@%mktemp%@AE@%; %@AB@%mktemp%@AE@% preserves %@AI@%base%@AE@% and
  25555. replaces the six trailing%@AB@% X%@AE@%'s with an alphanumeric character followed by a
  25556. five-digit value. The five-digit value is a unique number identifying the
  25557. calling process. The alphanumeric character is 0 ('%@AB@%0%@AE@%') the first time %@AB@%mktemp%@AE@%
  25558. is called with a given template.  %@NL@%
  25559. %@NL@%
  25560. In subsequent calls from the same process with copies of the same template,
  25561. %@AB@%mktemp%@AE@% checks to see if previously returned names have been used to create
  25562. files. If no file exists for a given name, %@AB@%mktemp%@AE@% returns that name. If
  25563. files exist for all previously returned names, %@AB@%mktemp%@AE@% creates a new name by
  25564. replacing the alphanumeric character in the name with the next available
  25565. lowercase letter. For example, if the first name returned is %@AS@% t012345 %@AE@% and
  25566. this name is used to create a file, the next name returned will be %@AS@% ta12345%@AE@%.
  25567. When creating new names, %@AB@%mktemp%@AE@% uses, in order, '0' and then the lowercase
  25568. letters 'a' through 'z'.  %@NL@%
  25569. %@NL@%
  25570. Note that the original template is modified by the first call to %@AB@%mktemp%@AE@%. If
  25571. you then call the %@AB@%mktemp%@AE@% function again with the same template (i.e., the
  25572. original one), you will get an error.  %@NL@%
  25573. %@NL@%
  25574. The %@AB@%mktemp%@AE@% function generates unique file names but does not create or open
  25575. files.  %@NL@%
  25576. %@NL@%
  25577. %@NL@%
  25578. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25579. %@NL@%
  25580. The %@AB@%mktemp%@AE@% function returns a pointer to the modified template. The return
  25581. value is %@AB@%NULL%@AE@% if the %@AI@%template%@AE@% argument is badly formed or no more unique
  25582. names can be created from the given template.  %@NL@%
  25583. %@NL@%
  25584. %@NL@%
  25585. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25586. %@NL@%
  25587.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  25588. %@NL@%
  25589. %@NL@%
  25590. %@NL@%
  25591. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25592. %@NL@%
  25593. %@AB@%fopen%@AE@%, %@AB@%getpid%@AE@%, %@AB@%open%@AE@%, %@AB@%tempnam%@AE@%, %@AB@%tmpfile%@AE@%  %@NL@%
  25594. %@NL@%
  25595. %@NL@%
  25596. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25597. %@NL@%
  25598. %@AS@%  /* MKTEMP.C: The program uses mktemp to create five unique file names.
  25599. %@AS@%   * It opens each file name to ensure that the next name is unique.
  25600. %@AS@%   */
  25601. %@AS@%  
  25602. %@AS@%  #include <io.h>
  25603. %@AS@%  #include <string.h>
  25604. %@AS@%  #include <stdio.h>
  25605. %@AS@%  
  25606. %@AS@%  char *template = "fnXXXXXX";
  25607. %@AS@%  char *result;
  25608. %@AS@%  char names[5][9];
  25609. %@AS@%  
  25610. %@AS@%  void main()
  25611. %@AS@%  {
  25612. %@AS@%     int i;
  25613. %@AS@%     FILE *fp;
  25614. %@AS@%  
  25615. %@AS@%     for( i = 0; i < 5; i++ )
  25616. %@AS@%     {
  25617. %@AS@%        strcpy( names[i], template );
  25618. %@AS@%  
  25619. %@AS@%        /* Attempt to find a unique file name: */
  25620. %@AS@%        result = mktemp( names[i] );
  25621. %@AS@%        if( result == NULL )
  25622. %@AS@%           printf( "Problem creating the template" );
  25623. %@AS@%        else
  25624. %@AS@%        {
  25625. %@AS@%           if( (fp = fopen( result, "w" )) != NULL )
  25626. %@AS@%               printf( "Unique file name is %s\n", result );
  25627. %@AS@%           else
  25628. %@AS@%               printf( "Cannot open %s\n", result );
  25629. %@AS@%           fclose( fp );
  25630. %@AS@%        }
  25631. %@AS@%     }
  25632. %@AS@%  }%@AE@%%@NL@%
  25633. %@NL@%
  25634. %@NL@%
  25635. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25636. %@NL@%
  25637. %@AS@%  
  25638. %@AS@%  
  25639. %@AS@%  Unique file name is fn000686
  25640. %@AS@%  Unique file name is fna00686
  25641. %@AS@%  Unique file name is fnb00686
  25642. %@AS@%  Unique file name is fnc00686
  25643. %@AS@%  Unique file name is fnd00686%@AE@%%@NL@%
  25644. %@NL@%
  25645. %@NL@%
  25646. %@NL@%
  25647. %@NL@%
  25648. %@QR:mktime@%%@NL@%
  25649. %@2@%%@CR:C6A02111051 @%%@AB@%mktime%@AE@%%@EH@%%@NL@%
  25650. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25651. %@NL@%
  25652. %@NL@%
  25653. %@3@%%@AB@%Description%@CR:C6A02111052 @%%@CR:C6A02111053 @%%@AE@%%@EH@%%@NL@%
  25654. %@NL@%
  25655. Converts the local time to a calendar value.  %@NL@%
  25656. %@NL@%
  25657. %@AS@%  #include <time.h>%@AE@%%@NL@%
  25658. %@NL@%
  25659. %@AS@%  time_t mktime( struct tm *timeptr );%@AE@%%@NL@%
  25660. %@NL@%
  25661. %@AI@%timeptr%@AE@%                           Pointer to time structure
  25662.  
  25663. %@NL@%
  25664. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25665. %@NL@%
  25666. The %@AB@%mktime%@AE@% function converts the supplied time structure (possibly
  25667. incomplete) pointed to by %@AI@%timeptr%@AE@% into a fully defined structure with
  25668. "normalized" values and then converts it to a %@AB@%time_t%@AE@% calendar time value.
  25669. The structure for the %@AB@%tm%@AE@% is described in the reference page for %@AB@%asctime%@AE@%.  %@NL@%
  25670. %@NL@%
  25671. The converted time has the same encoding as the values returned by the %@AB@%time%@AE@%
  25672. function. The original values of the %@AB@%tm_wday%@AE@% and %@AB@%tm_yday%@AE@% components of the
  25673. %@AI@%timeptr%@AE@% structure are ignored, and the original values of the other
  25674. components are not restricted to their normal ranges.  %@NL@%
  25675. %@NL@%
  25676. If successful, %@AB@%mktime%@AE@% sets the values of %@AB@%tm_wday%@AE@% and %@AB@%tm_yday%@AE@% appropriately,
  25677. and sets the other components to represent the specified calendar time, but
  25678. with their values forced to the normal ranges; the final value of %@AB@%tm_mday%@AE@% is
  25679. not set until %@AB@%tm_mon%@AE@% and %@AB@%tm_year%@AE@% are determined.  %@NL@%
  25680. %@NL@%
  25681. DOS and OS/2 do not accommodate dates prior to 1980. If %@AI@%timeptr%@AE@% references a
  25682. date before January 1, 1980, %@AB@%mktime%@AE@% returns -1.  %@NL@%
  25683. %@NL@%
  25684. Note that the %@AB@%gmtime%@AE@% and %@AB@%localtime%@AE@% functions use a single statically
  25685. allocated buffer for the conversion. If you supply this buffer to %@AB@%mktime%@AE@%,
  25686. the previous contents will be destroyed.  %@NL@%
  25687. %@NL@%
  25688. %@NL@%
  25689. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25690. %@NL@%
  25691. The %@AB@%mktime%@AE@% function returns the specified calendar time encoded as a value
  25692. of type %@AB@%time_t%@AE@%. If the calendar time cannot be represented, the function
  25693. returns the value -1 cast as type %@AB@%time_t%@AE@%.  %@NL@%
  25694. %@NL@%
  25695. %@NL@%
  25696. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25697. %@NL@%
  25698. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25699. %@NL@%
  25700. %@NL@%
  25701. %@NL@%
  25702. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25703. %@NL@%
  25704. %@AB@%asctime%@AE@%, %@AB@%gmtime%@AE@%, %@AB@%localtime%@AE@%, %@AB@%time%@AE@%  %@NL@%
  25705. %@NL@%
  25706. %@NL@%
  25707. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25708. %@NL@%
  25709. %@AS@%  /* MKTIME.C: The example takes a number of days as input and returns
  25710. %@AS@%   * the time, the current date, and the specified number of days.
  25711. %@AS@%   */%@AE@%%@NL@%
  25712. %@NL@%
  25713. %@AS@%  #include <time.h>
  25714. %@AS@%  #include <stdio.h>
  25715. %@AS@%  
  25716. %@AS@%  void main()
  25717. %@AS@%  {
  25718. %@AS@%     struct tm when;
  25719. %@AS@%     time_t now, result;
  25720. %@AS@%     int    days;
  25721. %@AS@%  
  25722. %@AS@%     time( &now );
  25723. %@AS@%     when = *localtime( &now );
  25724. %@AS@%     printf( "Current time is %s\n", asctime( &when ) );
  25725. %@AS@%     printf( "How many days to look ahead: " );
  25726. %@AS@%     scanf( "%d", &days );
  25727. %@AS@%  
  25728. %@AS@%     when.tm_mday = when.tm_mday + days;
  25729. %@AS@%     if( (result = mktime( &when )) != (time_t)-1 )
  25730. %@AS@%        printf( "In %d days the time will be %s\n",
  25731. %@AS@%                days, asctime( &when ) );
  25732. %@AS@%     else
  25733. %@AS@%        perror( "mktime failed" );
  25734. %@AS@%  }%@AE@%%@NL@%
  25735. %@NL@%
  25736. %@NL@%
  25737. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25738. %@NL@%
  25739. %@AS@%  
  25740. %@AS@%  
  25741. %@AS@%  Current time is Mon Jun 19 11:45:20 1989
  25742. %@AS@%  
  25743. %@AS@%  How many days to look ahead: 23
  25744. %@AS@%  In 23 days the time will be Wed Jul 12 11:45:20 1989 %@AE@%%@NL@%
  25745. %@NL@%
  25746. %@NL@%
  25747. %@NL@%
  25748. %@NL@%
  25749. %@QR:modf@%%@QR:modfl@%%@NL@%
  25750. %@2@%%@CR:C6A02121054 @%%@AB@%modf, modfl%@AE@%%@EH@%%@NL@%
  25751. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25752. %@NL@%
  25753. %@NL@%
  25754. %@3@%%@AB@%Description%@CR:C6A02121055 @% %@CR:C6A02121056 @%%@CR:C6A02121057 @%%@AE@%%@EH@%%@NL@%
  25755. %@NL@%
  25756. Split a floating-point value into a mantissa and an exponent.  %@NL@%
  25757. %@NL@%
  25758. %@AS@%  #include <math.h>%@AE@%%@NL@%
  25759. %@NL@%
  25760. %@AS@%  double modf( double x, double *intptr );%@AE@%%@NL@%
  25761. %@NL@%
  25762. %@AS@%  long double modfl( long double x, long double *intptr );%@AE@%%@NL@%
  25763. %@NL@%
  25764. %@AI@%x%@AE@%                                 Floating-point value
  25765.  
  25766. %@AI@%intptr%@AE@%                            Pointer to stored integer portion
  25767.  
  25768. %@NL@%
  25769. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25770. %@NL@%
  25771. The %@AB@%modf%@AE@% functions break down the floating-point value %@AI@%x%@AE@% into fractional and
  25772. integer parts, each of which has the same sign as %@AI@%x%@AE@%. The signed fractional
  25773. portion of %@AI@%x%@AE@% is returned. The integer portion is stored as a floating-point
  25774. value at  %@AI@%intptr%@AE@%.  %@NL@%
  25775. %@NL@%
  25776. The %@AB@%modfl%@AE@% function uses the 80-bit, 10-byte coprocessor form of arguments
  25777. and return values. See the reference page on the long double functions for
  25778. more details on this data type.  %@NL@%
  25779. %@NL@%
  25780. %@NL@%
  25781. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25782. %@NL@%
  25783. The %@AB@%modf%@AE@% and %@AB@%modfl%@AE@% functions return the signed fractional portion of %@AI@%x%@AE@%.
  25784. There is no error return.  %@NL@%
  25785. %@NL@%
  25786. %@NL@%
  25787. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25788. %@NL@%
  25789. %@AB@%modf%@AE@%  %@NL@%
  25790. %@NL@%
  25791. %@AB@%%@AE@% ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2   %@AB@%%@AE@% UNIX   %@AB@%%@AE@% XENIX %@NL@%
  25792. %@NL@%
  25793. %@NL@%
  25794. %@AB@%modfl%@AE@%  %@NL@%
  25795. %@NL@%
  25796.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25797. %@NL@%
  25798. %@NL@%
  25799. %@NL@%
  25800. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25801. %@NL@%
  25802. %@AB@%frexp%@AE@%, %@AB@%ldexp%@AE@%  %@NL@%
  25803. %@NL@%
  25804. %@NL@%
  25805. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25806. %@NL@%
  25807. %@AS@%  /* MODF.C */
  25808. %@AS@%  #include <math.h>
  25809. %@AS@%  #include <stdio.h>%@AE@%%@NL@%
  25810. %@NL@%
  25811. %@AS@%  void main()
  25812. %@AS@%  {
  25813. %@AS@%     double x, y, n;
  25814. %@AS@%  
  25815. %@AS@%     x = -14.87654321;       /* Divide x into its fractional */
  25816. %@AS@%     y = modf( x, &n );      /* and integer parts            */
  25817. %@AS@%  
  25818. %@AS@%     printf( "For %f, the fraction is %f and the integer is %.f\n", x, y, n
  25819. %@AS@%);
  25820. %@AS@%  }%@AE@%%@NL@%
  25821. %@NL@%
  25822. %@NL@%
  25823. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25824. %@NL@%
  25825. %@AS@%  
  25826. %@AS@%  
  25827. %@AS@%  For -14.876543, the fraction is -0.876543 and the integer is -14 %@AE@%%@NL@%
  25828. %@NL@%
  25829. %@NL@%
  25830. %@NL@%
  25831. %@NL@%
  25832. %@QR:movedata@%%@NL@%
  25833. %@2@%%@CR:C6A02131058 @%%@AB@%movedata%@AE@%%@EH@%%@NL@%
  25834. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25835. %@NL@%
  25836. %@NL@%
  25837. %@3@%%@AB@%Description%@CR:C6A02131059 @%%@CR:C6A02131060 @%%@AE@%%@EH@%%@NL@%
  25838. %@NL@%
  25839. Moves characters to another segment.  %@NL@%
  25840. %@NL@%
  25841. %@AB@%#include <memory.h>%@AE@%               Required only for function declarations%@AB@%%@AE@%
  25842.  
  25843. %@AB@%#include <string.h>%@AE@%               Use either STRING.H (for ANSI 
  25844.                                   compatibility) or MEMORY.H
  25845.  
  25846. %@AS@%  void movedata( unsigned int srcseg, unsigned int srcoff, unsigned int
  25847. %@AS@%  destseg, 
  25848. %@AS@%  unsigned int destoff, unsigned int count );%@AE@%%@NL@%
  25849. %@NL@%
  25850. %@AI@%srcseg%@AE@%                            Segment address of source
  25851.  
  25852. %@AI@%srcoff%@AE@%                            Segment offset of source
  25853.  
  25854. %@AI@%destseg%@AE@%                           Segment address of destination
  25855.  
  25856. %@AI@%destoff%@AE@%                           Segment offset of destination
  25857.  
  25858. %@AI@%count%@AE@%                             Number of bytes
  25859.  
  25860. %@NL@%
  25861. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25862. %@NL@%
  25863. The %@AB@%movedata%@AE@% function copies %@AI@%count%@AE@% bytes from the source address specified
  25864. by %@AI@%srcseg%@AE@%:%@AI@%srcoff%@AE@% to the destination address specified by %@AI@%destseg%@AE@%:%@AI@%destoff%@AE@%.%@CR:C6A02131061 @%  %@NL@%
  25865. %@NL@%
  25866. The %@AB@%movedata%@AE@% function was intended to move far data in small-data-model
  25867. programs. The newer model-independent %@AB@%_fmemcpy%@AE@% and %@AB@%_fmemmove%@AE@% functions
  25868. should be used instead of the %@AB@%movedata%@AE@% function. In large-data-model
  25869. programs, the %@AB@%memcpy%@AE@% and %@AB@%memmove%@AE@% functions can also be used.  %@NL@%
  25870. %@NL@%
  25871. Segment values for the %@AI@%srcseg%@AE@% and %@AI@%destseg%@AE@% arguments can be obtained by using
  25872. either the %@AB@%segread%@AE@% function or the %@AB@%FP_SEG%@AE@% macro.  %@NL@%
  25873. %@NL@%
  25874. The %@AB@%movedata%@AE@% function does not handle all cases of overlapping moves
  25875. correctly. These occur when part of the destination is the same memory area
  25876. as part of the source. The %@AB@%memmove%@AE@% function correctly handles overlapping
  25877. moves.  %@NL@%
  25878. %@NL@%
  25879. %@NL@%
  25880. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25881. %@NL@%
  25882. None.  %@NL@%
  25883. %@NL@%
  25884. %@NL@%
  25885. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25886. %@NL@%
  25887.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  25888. %@NL@%
  25889. %@NL@%
  25890. %@NL@%
  25891. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25892. %@NL@%
  25893. %@AB@%%@AE@%FP_OFF, FP_SEG, %@AB@%memcpy%@AE@%, %@AB@%memmove%@AE@%, %@AB@%segread%@AE@%  %@NL@%
  25894. %@NL@%
  25895. %@NL@%
  25896. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25897. %@NL@%
  25898. %@AS@%  /* MOVEDATA.C */
  25899. %@AS@%  #include <memory.h>
  25900. %@AS@%  #include <stdio.h>
  25901. %@AS@%  #include <string.h>
  25902. %@AS@%  #include <dos.h>
  25903. %@AS@%  #include <malloc.h>
  25904. %@AS@%  
  25905. %@AS@%  char _far *src = "This is a test.";
  25906. %@AS@%  
  25907. %@AS@%  void main()
  25908. %@AS@%  {
  25909. %@AS@%     char _far *dest;
  25910. %@AS@%  
  25911. %@AS@%     if( (dest = _fmalloc( 80 )) != NULL )
  25912. %@AS@%     {
  25913. %@AS@%        movedata( FP_SEG( src ),  FP_OFF( src ),
  25914. %@AS@%                  FP_SEG( dest ), FP_OFF( dest ), _fstrlen( src ) + 1 );
  25915. %@AS@%        printf( "The source data at %Fp is '%Fs'\n", src, src );
  25916. %@AS@%        printf( "The destination data at %Fp is '%Fs'\n", dest, dest );
  25917. %@AS@%        _ffree( dest );
  25918. %@AS@%     }
  25919. %@AS@%  }%@AE@%%@NL@%
  25920. %@NL@%
  25921. %@NL@%
  25922. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  25923. %@NL@%
  25924. %@AS@%  
  25925. %@AS@%  
  25926. %@AS@%  The source data at 2D0A:02B8 is 'This is a test.'
  25927. %@AS@%  The destination data at 3D0B:0016 is 'This is a test.'%@AE@%%@NL@%
  25928. %@NL@%
  25929. %@NL@%
  25930. %@NL@%
  25931. %@NL@%
  25932. %@QR:_moveto@%%@NL@%
  25933. %@2@%%@CR:C6A02141062 @%%@AB@%_moveto Functions%@AE@%%@EH@%%@NL@%
  25934. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25935. %@NL@%
  25936. %@NL@%
  25937. %@3@%%@AB@%Description%@AE@%%@EH@%%@NL@%
  25938. %@NL@%
  25939. Move current graphics positions.  %@NL@%
  25940. %@NL@%
  25941. %@CR:C6A02141063 @%%@CR:C6A02141064 @%%@CR:C6A02141065 @%%@AS@%  #include <graph.h>%@AE@%%@NL@%
  25942. %@NL@%
  25943. %@AS@%  struct xycoord _far _moveto( short x, short y );%@AE@%%@NL@%
  25944. %@NL@%
  25945. %@AS@%  struct _wxycoord _far _moveto_w( double wx, double wy );%@AE@%%@NL@%
  25946. %@NL@%
  25947. %@AI@%x%@AE@%, %@AI@%y%@AE@%                              View-coordinate point
  25948.  
  25949. %@AI@%wx%@AE@%, %@AI@%wy%@AE@%                            Window-coordinate point
  25950.  
  25951. %@NL@%
  25952. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  25953. %@NL@%
  25954. The %@AB@%_moveto%@AE@% functions move the current position to the specified point. The
  25955. %@AB@%_moveto%@AE@% function uses the view-coordinate point (%@AI@%x%@AE@%, %@AI@%y%@AE@%) as the current
  25956. position. The %@AB@%_moveto_w%@AE@% function uses the window-coordinate point (%@AI@%wx%@AE@%, %@AI@%wy%@AE@%)
  25957. as the current position. No drawing takes place.  %@NL@%
  25958. %@NL@%
  25959. %@NL@%
  25960. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  25961. %@NL@%
  25962. The function returns the coordinates of the previous position. The %@AB@%_moveto%@AE@%
  25963. function returns the coordinates in an %@AB@%xycoord%@AE@% structure. The %@AB@%xycoord%@AE@%
  25964. structure, defined in GRAPH.H, contains the following elements:  %@NL@%
  25965. %@NL@%
  25966. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  25967. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25968. %@AB@%short xcoord%@AE@%                      %@AI@%x%@AE@% coordinate
  25969.  
  25970. %@AB@%short ycoord%@AE@%                      %@AI@%y%@AE@% coordinate
  25971.  
  25972. The %@AB@%_moveto_w%@AE@% function returns the coordinates in an %@AB@%_wxycoord%@AE@% structure,
  25973. defined in GRAPH.H. The %@AB@%_wxycoord%@AE@% structure contains the following elements:
  25974. %@NL@%
  25975. %@NL@%
  25976. %@AB@%Element%@AE@%                           %@AB@%Description%@AE@%
  25977. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  25978. %@AB@%double wx%@AE@%                         %@AI@%x%@AE@% window coordinate
  25979.  
  25980. %@AB@%double wy%@AE@%                         %@AI@%y%@AE@% window coordinate
  25981.  
  25982. %@NL@%
  25983. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  25984. %@NL@%
  25985.  ANSI   %@AB@%%@AE@% DOS    OS/2    UNIX    XENIX %@NL@%
  25986. %@NL@%
  25987. %@NL@%
  25988. %@NL@%
  25989. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  25990. %@NL@%
  25991. %@AB@%_lineto%@AE@% functions  %@NL@%
  25992. %@NL@%
  25993. %@NL@%
  25994. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  25995. %@NL@%
  25996. %@AS@%  /* MOVETO.C: This program draws line segments of different colors. */
  25997. %@AS@%  
  25998. %@AS@%  #include <graph.h>
  25999. %@AS@%  #include <stdlib.h>
  26000. %@AS@%  #include <conio.h>
  26001. %@AS@%  
  26002. %@AS@%  void main()
  26003. %@AS@%  {
  26004. %@AS@%     short x, y, xinc, yinc, color = 1;
  26005. %@AS@%     struct videoconfig v;
  26006. %@AS@%  
  26007. %@AS@%     /* Find a valid graphics mode. */
  26008. %@AS@%     if( !_setvideomode( _MAXCOLORMODE ) )
  26009. %@AS@%        exit( 1 );
  26010. %@AS@%     _getvideoconfig( &v );
  26011. %@AS@%     xinc = v.numxpixels / 50;
  26012. %@AS@%     yinc = v.numypixels / 50;
  26013. %@AS@%  
  26014. %@AS@%     for( x = 0, y = v.numypixels - 1; x < v.numxpixels; x += xinc, y -=
  26015. %@AS@%yinc )
  26016. %@AS@%     {
  26017. %@AS@%        _setcolor( color++ % 16 );
  26018. %@AS@%        _moveto( x, 0 );
  26019. %@AS@%        _lineto( 0, y );
  26020. %@AS@%     }
  26021. %@AS@%     getch();
  26022. %@AS@%  
  26023. %@AS@%     _setvideomode( _DEFAULTMODE );
  26024. %@AS@%  }
  26025. %@AS@%  %@AE@%%@NL@%
  26026. %@NL@%
  26027. %@NL@%
  26028. %@NL@%
  26029. %@NL@%
  26030. %@QR:_msize@%%@NL@%
  26031. %@2@%%@CR:C6A02151066 @%%@AB@%_msize Functions%@AE@%%@EH@%%@NL@%
  26032. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26033. %@NL@%
  26034. %@NL@%
  26035. %@3@%%@AB@%Description%@CR:C6A02151067 @%%@CR:C6A02151068 @%%@CR:C6A02151069 @% %@CR:C6A02151070 @%%@CR:C6A02151071 @% %@CR:C6A02151072 @%%@CR:C6A02151073 @% %@CR:C6A02151074 @%%@AE@%%@EH@%%@NL@%
  26036. %@NL@%
  26037. Return the size of a memory block allocated in the heap.  %@NL@%
  26038. %@NL@%
  26039. %@AB@%#include <malloc.h>%@AE@%               Required only for function declarations
  26040.  
  26041. %@AS@%  size_t  _msize( void *memblock );%@AE@%%@NL@%
  26042. %@NL@%
  26043. %@AS@%  size_t _bmsize( _segment seg, void _based( void ) *memblock );%@AE@%%@NL@%
  26044. %@NL@%
  26045. %@AS@%  size_t _fmsize( void _far *memblock );%@AE@%%@NL@%
  26046. %@NL@%
  26047. %@AS@%  size_t _nmsize( void _near *memblock );%@AE@%%@NL@%
  26048. %@NL@%
  26049. %@AI@%memblock%@AE@%                          Pointer to memory block 
  26050.  
  26051. %@AI@%seg%@AE@%                               Based-heap segment selector
  26052.  
  26053. %@NL@%
  26054. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  26055. %@NL@%
  26056. The %@AB@%_msize%@AE@% family of functions returns the size, in bytes, of the memory
  26057. block allocated by a call to the appropriate version of the %@AB@%calloc%@AE@%, %@AB@%malloc%@AE@%,
  26058. or %@AB@%realloc%@AE@% functions.  %@NL@%
  26059. %@NL@%
  26060. In large data models (compact-, large-, and huge-model programs), %@AB@%_msize%@AE@%
  26061. maps to %@AB@%_fmsize%@AE@%. In small data models (tiny-, small-, and medium-model
  26062. programs), %@AB@%_msize%@AE@% maps to %@AB@%_nmsize%@AE@%.  %@NL@%
  26063. %@NL@%
  26064. The %@AB@%_nmsize%@AE@% function returns the size (in bytes) of the memory block
  26065. allocated by a call to %@AB@%_nmalloc%@AE@%, and the %@AB@%_fmsize%@AE@% function returns the size
  26066. (in bytes) of the memory block allocated by a call to %@AB@%_fmalloc%@AE@% or %@AB@%_frealloc%@AE@%.
  26067. The %@AB@%_bmsize%@AE@% function returns the size of a block allocated in segment %@AI@%seg%@AE@% by
  26068. a call to %@AB@%_bmalloc%@AE@%, %@AB@%_bcalloc%@AE@%, or %@AB@%_brealloc%@AE@%.  %@NL@%
  26069. %@NL@%
  26070. The location of the memory block is indicated below:  %@NL@%
  26071. %@NL@%
  26072. %@AB@%Function%@AE@%                          %@AB@%Data Segment%@AE@%
  26073. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26074. %@AB@%_msize%@AE@%                            Depends on data model of program
  26075.  
  26076. %@AB@%_bmsize%@AE@%                           Based heap segment specified by %@AI@%seg%@AE@% 
  26077.                                   value
  26078.  
  26079. %@AB@%_fmsize%@AE@%                           Far heap segment (outside default data 
  26080.                                   segment)
  26081.  
  26082. %@AB@%_nmsize%@AE@%                           Default data segment (inside near heap)
  26083.  
  26084. %@NL@%
  26085. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  26086. %@NL@%
  26087. All four functions return the size (in bytes) as an unsigned integer.  %@NL@%
  26088. %@NL@%
  26089. %@NL@%
  26090. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  26091. %@NL@%
  26092.  ANSI   %@AB@%%@AE@% DOS   %@AB@%%@AE@% OS/2    UNIX    XENIX %@NL@%
  26093. %@NL@%
  26094. %@NL@%
  26095. %@NL@%
  26096. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  26097. %@NL@%
  26098. %@AB@%calloc%@AE@% functions,  %@AB@%_expand%@AE@% functions, %@AB@%malloc%@AE@% functions, %@AB@%realloc%@AE@% functions  %@NL@%
  26099. %@NL@%
  26100. %@NL@%
  26101. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  26102. %@NL@%
  26103. %@AS@%  /* REALLOC.C: This program allocates a block of memory for buffer
  26104. %@AS@%   * and then uses _msize to display the size of that block. Next, it
  26105. %@AS@%   * uses realloc to expand the amount of memory used by buffer
  26106. %@AS@%   * and then calls _msize again to display the new amount of
  26107. %@AS@%   * memory allocated to buffer.
  26108. %@AS@%   */
  26109. %@AS@%  
  26110. %@AS@%  #include <stdio.h>
  26111. %@AS@%  #include <malloc.h>
  26112. %@AS@%  #include <stdlib.h>
  26113. %@AS@%  
  26114. %@AS@%  void main()
  26115. %@AS@%  {
  26116. %@AS@%     long *buffer;
  26117. %@AS@%     size_t size;
  26118. %@AS@%  
  26119. %@AS@%     if( (buffer = (long *)malloc( 1000 * sizeof( long ) )) == NULL )
  26120. %@AS@%        exit( 1 );
  26121. %@AS@%  
  26122. %@AS@%     size = _msize( buffer );
  26123. %@AS@%     printf( "Size of block after malloc of 1000 longs: %u\n", size );
  26124. %@AS@%  
  26125. %@AS@%     /* Reallocate and show new size: */
  26126. %@AS@%     if( (buffer = realloc( buffer, size + (1000 * sizeof( long )) )) ==
  26127. %@AS@%NULL )
  26128. %@AS@%        exit( 1 );
  26129. %@AS@%     size = _msize( buffer );
  26130. %@AS@%     printf( "Size of block after realloc of 1000 more longs: %u\n", size );
  26131. %@AS@%  
  26132. %@AS@%     free( buffer );
  26133. %@AS@%  }%@AE@%%@NL@%
  26134. %@NL@%
  26135. %@NL@%
  26136. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  26137. %@NL@%
  26138. %@AS@%  
  26139. %@AS@%  
  26140. %@AS@%  Size of block after malloc of 1000 longs: 4000
  26141. %@AS@%  Size of block after realloc of 1000 more longs: 8000 %@AE@%%@NL@%
  26142. %@NL@%
  26143. %@NL@%
  26144. %@NL@%
  26145. %@NL@%
  26146. %@QR:onexit@%%@NL@%
  26147. %@2@%%@CR:C6A02161075 @%%@AB@%onexit%@AE@%%@EH@%%@NL@%
  26148. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26149. %@NL@%
  26150. %@NL@%
  26151. %@3@%%@AB@%Description%@CR:C6A02161076 @%%@CR:C6A02161077 @%%@AE@%%@EH@%%@NL@%
  26152. %@NL@%
  26153. Registers a routine to be called at exit time.  %@NL@%
  26154. %@NL@%
  26155. %@AS@%  #include <stdlib.h>%@AE@%%@NL@%
  26156. %@NL@%
  26157. %@AS@%  onexit_t onexit( onexit_t func );%@AE@%%@NL@%
  26158. %@NL@%
  26159. %@AI@%func%@AE@%                              Pointer to function to be called at exit
  26160.  
  26161. %@NL@%
  26162. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  26163. %@NL@%
  26164. The %@AB@%onexit%@AE@% function is passed the address of a function (%@AI@%func%@AE@%) to be called
  26165. when the program terminates normally. Successive calls to %@AB@%onexit%@AE@% create a
  26166. register of functions that is executed in LIFO (last-in-first-out) order. No
  26167. more than 32 functions can be registered with %@AB@%onexit%@AE@%; %@AB@%onexit%@AE@% returns the
  26168. value%@AB@% NULL%@AE@% if the number of functions exceeds 32. The functions passed to
  26169. %@AB@%onexit%@AE@% cannot take parameters.  %@NL@%
  26170. %@NL@%
  26171. The %@AB@%onexit%@AE@% function is not part of the ANSI definition, but is instead a
  26172. Microsoft extension. The ANSI-standard %@AB@%atexit %@AE@%function does the same thing
  26173. as%@AB@% onexit%@AE@%, and should be used instead of %@AB@%onexit %@AE@%when ANSI portability is
  26174. desired.  %@NL@%
  26175. %@NL@%
  26176. All routines passed to %@AB@%onexit%@AE@% should have the %@AB@%_loadds%@AE@% attribute if used in
  26177. multithread dynamic-link libraries.  %@NL@%
  26178. %@NL@%
  26179. %@NL@%
  26180. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  26181. %@NL@%
  26182. The %@AB@%onexit%@AE@% function returns a pointer to the function if successful and
  26183. returns %@AB@%NULL%@AE@% if there is no space left to store the function pointer.  %@NL@%
  26184. %@NL@%
  26185. %@NL@%
  26186. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  26187. %@NL@%
  26188.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  26189. %@NL@%
  26190. %@NL@%
  26191. %@NL@%
  26192. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  26193. %@NL@%
  26194. %@AB@%exit%@AE@%  %@NL@%
  26195. %@NL@%
  26196. %@NL@%
  26197. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  26198. %@NL@%
  26199. %@AS@%  /* ONEXIT.C */
  26200. %@AS@%  #include <stdlib.h>
  26201. %@AS@%  #include <stdio.h>
  26202. %@AS@%  
  26203. %@AS@%  /* Prototypes */
  26204. %@AS@%  void fn1( void ), fn2( void ), fn3( void ),  fn4( void );%@AE@%%@NL@%
  26205. %@NL@%
  26206. %@AS@%  void main()
  26207. %@AS@%  {
  26208. %@AS@%     onexit( fn1 );
  26209. %@AS@%     onexit( fn2 );
  26210. %@AS@%     onexit( fn3 );
  26211. %@AS@%     onexit( fn4 );
  26212. %@AS@%     printf( "This is executed first.\n" );
  26213. %@AS@%  }
  26214. %@AS@%  
  26215. %@AS@%  void fn1()
  26216. %@AS@%  {
  26217. %@AS@%     printf( "next.\n" );
  26218. %@AS@%  }
  26219. %@AS@%  
  26220. %@AS@%  void fn2()
  26221. %@AS@%  {
  26222. %@AS@%     printf( "executed " );
  26223. %@AS@%  }
  26224. %@AS@%  
  26225. %@AS@%  void fn3()
  26226. %@AS@%  {
  26227. %@AS@%     printf( "is " );
  26228. %@AS@%  }
  26229. %@AS@%  
  26230. %@AS@%  void fn4()
  26231. %@AS@%  {
  26232. %@AS@%     printf( "This " );
  26233. %@AS@%  }%@AE@%%@NL@%
  26234. %@NL@%
  26235. %@NL@%
  26236. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  26237. %@NL@%
  26238. %@AS@%  
  26239. %@AS@%  
  26240. %@AS@%  This is executed first.
  26241. %@AS@%  This is executed next. %@AE@%%@NL@%
  26242. %@NL@%
  26243. %@NL@%
  26244. %@NL@%
  26245. %@NL@%
  26246. %@QR:open@%%@NL@%
  26247. %@2@%%@CR:C6A02171078 @%%@AB@%open%@AE@%%@EH@%%@NL@%
  26248. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26249. %@NL@%
  26250. %@NL@%
  26251. %@3@%%@AB@%Description%@CR:C6A02171079 @%%@CR:C6A02171080 @%%@CR:C6A02171081 @% %@CR:C6A02171082 @%%@CR:C6A02171083 @%%@AE@%%@EH@%%@NL@%
  26252. %@NL@%
  26253. Opens a file.  %@NL@%
  26254. %@NL@%
  26255. %@AB@%#include <fcntl.h>%@AE@%                
  26256.  
  26257. %@AB@%#include <sys\types.h>%@AE@%            
  26258.  
  26259. %@AB@%#include <sys\stat.h>%@AE@%             
  26260.  
  26261. %@AB@%#include <io.h>%@AE@%                   Required only for function declarations
  26262.  
  26263. %@AS@%  int open( char *filename, int oflag [[, int pmode]] );%@AE@%%@NL@%
  26264. %@NL@%
  26265. %@AI@%filename%@AE@%                          File name
  26266.  
  26267. %@AI@%oflag%@AE@%                             Type of operations allowed
  26268.  
  26269. %@AI@%pmode%@AE@%                             Permission mode
  26270.  
  26271. %@NL@%
  26272. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  26273. %@NL@%
  26274. The %@AB@%open%@AE@% function opens the file specified by %@AI@%filename%@AE@% and prepares the file
  26275. for subsequent reading or writing, as defined by %@AI@%oflag%@AE@%. The %@AI@%oflag%@AE@% argument
  26276. is an integer expression formed from one or more of the manifest constants
  26277. defined in FCNTL.H (listed below). When two or more manifest constants are
  26278. used to form the %@AI@%oflag%@AE@% argument, the constants are combined with the
  26279. bitwise-OR operator ( | ). See Section 2.5, "File Handling," for a
  26280. discussion of binary and text modes.  %@NL@%
  26281. %@NL@%
  26282. The FCNTL.H file defines the following manifest constants:%@CR:C6A02171084 @%%@CR:C6A02171085 @%%@CR:C6A02171086 @%%@CR:C6A02171087 @%%@CR:C6A02171088 @%  %@NL@%
  26283. %@NL@%
  26284. %@AB@%Constant%@AE@%                          %@AB@%Meaning%@AE@%
  26285. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26286. %@AB@%O_APPEND%@AE@%                          Repositions the file pointer to the end 
  26287.                                   of the file before every write 
  26288.                                   operation.
  26289.  
  26290. %@AB@%O_BINARY%@AE@%                          Opens file in binary (untranslated) 
  26291.                                   mode.
  26292.  
  26293. %@AB@%O_CREAT%@AE@%                           Creates and opens a new file for 
  26294.                                   writing; this has no effect if the file 
  26295.                                   specified by %@AI@%filename%@AE@% exists.
  26296.  
  26297. %@AB@%O_EXCL%@AE@%                            Returns an error value if the file 
  26298.                                   specified by %@AI@%filename%@AE@% exists. Only 
  26299.                                   applies when used with %@AB@%O_CREAT%@AE@%.
  26300.  
  26301. %@AB@%O_RDONLY%@AE@%                          Opens file for reading only; if this 
  26302.                                   flag is given, neither %@AB@%O_RDWR%@AE@% nor %@AB@%%@AE@%
  26303.                                   %@AB@%O_WRONLY%@AE@% can be given.
  26304.  
  26305. %@AB@%O_RDWR%@AE@%                            Opens file for both reading and writing;
  26306.                                   if this flag is given, neither %@AB@%O_RDONLY%@AE@% 
  26307.                                   nor%@AB@% O_WRONLY%@AE@% can be given.
  26308.  
  26309. %@AB@%O_TEXT%@AE@%                            Opens file in text (translated) mode.
  26310.  
  26311. %@AB@%O_TRUNC%@AE@%                           Opens and truncates an existing file to 
  26312.                                   zero length; the file must have write 
  26313.                                   permission. The contents of the file are
  26314.                                   destroyed. If this flag is given, you 
  26315.                                   cannot specify %@AB@%O_RDONLY%@AE@%.
  26316.  
  26317. %@AB@%O_WRONLY%@AE@%                          Opens file for writing only; if this 
  26318.                                   flag is given, neither %@AB@%O_RDONLY%@AE@% nor %@AB@%%@AE@%
  26319.                                   %@AB@%O_RDWR%@AE@% can be given.
  26320.  
  26321. ────────────────────────────────────────────────────────────────────────────%@NL@%
  26322. %@AU@%WARNING%@AE@%%@NL@%
  26323. %@NL@%
  26324. %@AI@%Use the O_TRUNC flag with care, as it destroys the complete contents of an
  26325. %@AI@%existing file.%@AE@%%@NL@%
  26326. ────────────────────────────────────────────────────────────────────────────%@NL@%
  26327. %@NL@%
  26328. Either %@AB@%O_RDONLY%@AE@%, %@AB@%O_RDWR%@AE@%, or%@AB@% O_WRONLY%@AE@% must be given to specify the access
  26329. mode. There is no default value for the access mode.  %@NL@%
  26330. %@NL@%
  26331. The %@AI@%pmode%@AE@% argument is required only when %@AB@%O_CREAT%@AE@% is specified. If the file
  26332. exists, %@AI@%pmode%@AE@% is ignored. Otherwise, %@AI@%pmode%@AE@% specifies the file's permission
  26333. settings, which are set when the new file is closed for the first time. The
  26334. %@AI@%pmode%@AE@% is an integer expression containing one or both of the manifest
  26335. constants %@AB@%S_IWRITE%@AE@% and %@AB@%S_IREAD%@AE@%, defined in SYS\STAT.H. When both constants
  26336. are given, they are joined with the bitwise-OR operator ( | ). The meaning
  26337. of the %@AI@%pmode%@AE@% argument is as follows:  %@NL@%
  26338. %@NL@%
  26339. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  26340. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26341. %@AB@%S_IWRITE%@AE@%                          Writing permitted
  26342.  
  26343. %@AB@%S_IREAD%@AE@%                           Reading permitted
  26344.  
  26345. %@AB@%S_IREAD |  S_IWRITE%@AE@%               Reading and writing permitted
  26346.  
  26347. If write permission is not given, the file is read-only. Under DOS and OS/2,
  26348. all files are readable; it is not possible to give write-only permission.
  26349. Thus the modes %@AB@%S_IWRITE%@AE@% and %@AB@%S_IREAD | S_IWRITE%@AE@% are equivalent.  %@NL@%
  26350. %@NL@%
  26351. The %@AB@%open%@AE@% function applies the current file-permission mask to %@AI@%pmode%@AE@% before
  26352. setting the permissions (see %@AB@%umask%@AE@%).  %@NL@%
  26353. %@NL@%
  26354. The %@AI@%filename%@AE@% argument used in the %@AB@%open%@AE@% function is affected by the DOS
  26355. APPEND command.  %@NL@%
  26356. %@NL@%
  26357. Note that under DOS versions 3.0 and later, a problem occurs when %@AB@%SHARE%@AE@% is
  26358. installed and a new file is opened with %@AI@%oflag%@AE@% set to %@AB@%O_CREAT%@AE@% | %@AB@%O_RDONLY%@AE@% or%@AB@%
  26359. %@AB@%O_CREAT%@AE@% | %@AB@%O _WRONLY%@AE@% and %@AI@%pmode%@AE@% set to %@AB@%S_IREAD%@AE@%. Under these conditions, the
  26360. operating system prematurely closes the file during system calls made within
  26361. %@AB@%open%@AE@%. This problem does not occur under OS/2.  %@NL@%
  26362. %@NL@%
  26363. To work around the problem, open the file with the %@AI@%pmode%@AE@% argument set to
  26364. %@AB@%S_IWRITE%@AE@%. Then close the file and use %@AB@%chmod%@AE@% to change the access mode back
  26365. to %@AB@%S_IREAD%@AE@%. Another work-around is to open the file with %@AI@%pmode%@AE@% set to
  26366. %@AB@%S_IREAD%@AE@% and %@AI@%oflag%@AE@% set to %@AB@%O_CREAT%@AE@% | %@AB@%O_RDWR%@AE@%.  %@NL@%
  26367. %@NL@%
  26368. %@NL@%
  26369. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  26370. %@NL@%
  26371. The %@AB@%open%@AE@% function returns a file handle for the opened file. A return value
  26372. of -1 indicates an error, and %@AB@%errno%@AE@% is set to one of the following values:  %@NL@%
  26373. %@NL@%
  26374. %@AB@%Value%@AE@%                             %@AB@%Meaning%@AE@%
  26375. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26376. %@AB@%EACCES%@AE@%                            Given path name is a directory; or an 
  26377.                                   attempt was made to open a read-only 
  26378.                                   file for writing; or a sharing violation
  26379.                                   occurred (the file's sharing mode does 
  26380.                                   not allow the specified operations).
  26381.  
  26382. %@AB@%EEXIST%@AE@%                            The %@AB@%O_CREAT%@AE@% and %@AB@%O_EXCL%@AE@% flags are 
  26383.                                   specified, but the named file already 
  26384.                                   exists.
  26385.  
  26386. %@AB@%EINVAL%@AE@%                            An invalid %@AI@%oflag%@AE@% or %@AI@%pmode%@AE@% argument was 
  26387.                                   given.
  26388.  
  26389. %@AB@%EMFILE%@AE@%                            No more file handles available (too many
  26390.                                   open files).
  26391.  
  26392. %@AB@%ENOENT%@AE@%                            File or path name not found.
  26393.  
  26394. %@NL@%
  26395. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  26396. %@NL@%
  26397.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2  %@AB@%%@AE@% UNIX  %@AB@%%@AE@% XENIX%@NL@%
  26398. %@NL@%
  26399. %@NL@%
  26400. %@NL@%
  26401. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  26402. %@NL@%
  26403. %@AB@%access%@AE@%, %@AB@%chmod%@AE@%, %@AB@%close%@AE@%, %@AB@%creat%@AE@%, %@AB@%dup%@AE@%, %@AB@%dup2%@AE@%, %@AB@%fopen%@AE@%, %@AB@%sopen%@AE@%, %@AB@%umask%@AE@%  %@NL@%
  26404. %@NL@%
  26405. %@NL@%
  26406. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  26407. %@NL@%
  26408. %@AS@%  /* OPEN.C: This program uses open to open a file named OPEN.C for input
  26409. %@AS@%   * and a file named OPEN.OUT for output. The files are then closed.
  26410. %@AS@%   */
  26411. %@AS@%  
  26412. %@AS@%  #include <fcntl.h>
  26413. %@AS@%  #include <sys\types.h>
  26414. %@AS@%  #include <sys\stat.h>
  26415. %@AS@%  #include <io.h>
  26416. %@AS@%  #include <stdio.h>
  26417. %@AS@%  
  26418. %@AS@%  void main()
  26419. %@AS@%  {
  26420. %@AS@%     int fh1, fh2;%@AE@%%@NL@%
  26421. %@NL@%
  26422. %@AS@%  fh1 = open( "OPEN.C", O_RDONLY );
  26423. %@AS@%     if( fh1 == -1 )
  26424. %@AS@%        perror( "open failed on input file" );
  26425. %@AS@%     else
  26426. %@AS@%     {
  26427. %@AS@%        printf( "open succeeded on input file\n" );
  26428. %@AS@%        close( fh1 );
  26429. %@AS@%     }
  26430. %@AS@%  
  26431. %@AS@%     fh2 = open( "OPEN.OUT", O_WRONLY | O_CREAT, S_IREAD | S_IWRITE );
  26432. %@AS@%     if( fh2 == -1 )
  26433. %@AS@%        perror( "open failed on output file" );
  26434. %@AS@%     else
  26435. %@AS@%     {
  26436. %@AS@%        printf( "open succeeded on output file\n" );
  26437. %@AS@%        close( fh2 );
  26438. %@AS@%     }
  26439. %@AS@%  }%@AE@%%@NL@%
  26440. %@NL@%
  26441. %@NL@%
  26442. %@3@%%@AB@%Output%@AE@%%@EH@%%@NL@%
  26443. %@NL@%
  26444. %@AS@%  
  26445. %@AS@%  
  26446. %@AS@%  open succeeded on input file
  26447. %@AS@%  open succeeded on output file%@AE@%%@NL@%
  26448. %@NL@%
  26449. %@NL@%
  26450. %@NL@%
  26451. %@NL@%
  26452. %@QR:_outgtext@%%@NL@%
  26453. %@2@%%@CR:C6A02181089 @%%@AB@%_outgtext%@AE@%%@EH@%%@NL@%
  26454. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26455. %@NL@%
  26456. %@NL@%
  26457. %@3@%%@AB@%Description%@CR:C6A02181090 @%%@AE@%%@EH@%%@NL@%
  26458. %@NL@%
  26459. Prints font-based text in graphics mode.  %@NL@%
  26460. %@NL@%
  26461. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  26462. %@NL@%
  26463. %@AS@%  void _far_outgtext( unsigned char_far *text );%@AE@%%@NL@%
  26464. %@NL@%
  26465. %@AI@%text%@AE@%                              Text string to output
  26466.  
  26467. %@NL@%
  26468. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  26469. %@NL@%
  26470. The %@AB@%_outgtext%@AE@% function outputs on the screen the null-terminated string that
  26471. %@AI@%text%@AE@% points to. The text is output using the current font at the current
  26472. graphics position and in the current color.  %@NL@%
  26473. %@NL@%
  26474. No formatting is provided, in contrast to the standard console I/O library
  26475. routines such as %@AB@%printf%@AE@%.  %@NL@%
  26476. %@NL@%
  26477. After it outputs the text, %@AB@%_outgtext%@AE@% updates the current graphics position.
  26478. %@NL@%
  26479. %@NL@%
  26480. The %@AB@%_outgtext%@AE@% function operates only in graphics video modes (e.g.,
  26481. %@AB@%_MRES4COLOR%@AE@%). Because it is a graphics function, the color of text is set by
  26482. the %@AB@%_setcolor%@AE@% function, not by the %@AB@%_settextcolor%@AE@% function.  %@NL@%
  26483. %@NL@%
  26484. %@NL@%
  26485. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  26486. %@NL@%
  26487. None.  %@NL@%
  26488. %@NL@%
  26489. %@NL@%
  26490. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  26491. %@NL@%
  26492.  ANSI  %@AB@%%@AE@% DOS   OS/2   UNIX   XENIX%@NL@%
  26493. %@NL@%
  26494. %@NL@%
  26495. %@NL@%
  26496. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  26497. %@NL@%
  26498. %@AB@%_moveto%@AE@% functions,  %@AB@%_setcolor%@AE@%, %@AB@% _setfont%@AE@%  %@NL@%
  26499. %@NL@%
  26500. %@NL@%
  26501. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  26502. %@NL@%
  26503. %@AS@%  /* OUTGTXT.C illustrates font output using functions:
  26504. %@AS@%   *   _registerfonts        _setfont            _outgtext
  26505. %@AS@%   *   _unregisterfonts      _getfontinfo        _getgtextextent
  26506. %@AS@%   *   _setgtextvector
  26507. %@AS@%   */
  26508. %@AS@%  
  26509. %@AS@%  #include <conio.h>
  26510. %@AS@%  #include <stdio.h>
  26511. %@AS@%  #include <stdlib.h>
  26512. %@AS@%  #include <string.h>
  26513. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  26514. %@NL@%
  26515. %@AS@%  #define NFONTS 6
  26516. %@AS@%  
  26517. %@AS@%  unsigned char *face[NFONTS] =
  26518. %@AS@%  {
  26519. %@AS@%      "Courier", "Helvetica", "Times Roman", "Modern", "Script", "Roman"
  26520. %@AS@%  };
  26521. %@AS@%  unsigned char *options[NFONTS] =
  26522. %@AS@%  {
  26523. %@AS@%      "courier", "helv", "tms rmn", "modern", "script", "roman"
  26524. %@AS@%  };
  26525. %@AS@%  
  26526. %@AS@%  void main()
  26527. %@AS@%  {
  26528. %@AS@%      unsigned char list[20];
  26529. %@AS@%      char fondir[_MAX_PATH];
  26530. %@AS@%      struct videoconfig vc;
  26531. %@AS@%      struct _fontinfo fi;
  26532. %@AS@%      short fontnum, x, y;
  26533. %@AS@%  
  26534. %@AS@%      /* Read header info from all .FON files in current or given directory.
  26535. %@AS@%*/
  26536. %@AS@%      if( _registerfonts( "*.FON" ) <= 0 )
  26537. %@AS@%      {
  26538. %@AS@%          _outtext( "Enter full path where .FON files are located: " );
  26539. %@AS@%          gets( fondir );
  26540. %@AS@%          strcat( fondir, "\\*.FON" );
  26541. %@AS@%          if( _registerfonts( fondir ) <= 0 )
  26542. %@AS@%          {
  26543. %@AS@%              _outtext( "Error: can't register fonts" );
  26544. %@AS@%              exit( 1 );
  26545. %@AS@%          }
  26546. %@AS@%      }
  26547. %@AS@%  
  26548. %@AS@%      /* Set highest available graphics mode and get configuration. */
  26549. %@AS@%      if( !_setvideomode( _MAXRESMODE ) )
  26550. %@AS@%          exit( 1 );
  26551. %@AS@%      _getvideoconfig( &vc );
  26552. %@AS@%  
  26553. %@AS@%      /* Display each font name centered on screen. */
  26554. %@AS@%      for( fontnum = 0; fontnum < NFONTS; fontnum++ )
  26555. %@AS@%      {
  26556. %@AS@%          /* Build options string. */
  26557. %@AS@%          strcat( strcat( strcpy( list, "t'" ), options[fontnum] ), "'");
  26558. %@AS@%          strcat( list, "h30w24b" );
  26559. %@AS@%  
  26560. %@AS@%          _clearscreen( _GCLEARSCREEN );
  26561. %@AS@%          if( _setfont( list ) >= 0 )
  26562. %@AS@%          {%@AE@%%@NL@%
  26563. %@NL@%
  26564. %@AS@%  /* Use length of text and height of font to center text. */
  26565. %@AS@%              x = (vc.numxpixels / 2) - (_getgtextextent( face[fontnum] ) /
  26566. %@AS@%2);
  26567. %@AS@%              y = (vc.numypixels / 2) + (_getgtextextent( face[fontnum] ) /
  26568. %@AS@%2);
  26569. %@AS@%              if( _getfontinfo( &fi ) )
  26570. %@AS@%              {
  26571. %@AS@%                  _outtext( "Error: Can't get font information" );
  26572. %@AS@%                  break;
  26573. %@AS@%              }
  26574. %@AS@%              _moveto( x, y );
  26575. %@AS@%              if( vc.numcolors > 2 )
  26576. %@AS@%                  _setcolor( fontnum + 2 );
  26577. %@AS@%  
  26578. %@AS@%              /* Rotate and display text. */
  26579. %@AS@%              _setgtextvector( 1, 0 );
  26580. %@AS@%              _outgtext( face[fontnum] );
  26581. %@AS@%              _setgtextvector( 0, 1 );
  26582. %@AS@%              _outgtext( face[fontnum] );
  26583. %@AS@%              _setgtextvector( -1, 0 );
  26584. %@AS@%              _outgtext( face[fontnum] );
  26585. %@AS@%              _setgtextvector( 0, -1 );
  26586. %@AS@%              _outgtext( face[fontnum] );
  26587. %@AS@%          }
  26588. %@AS@%          else
  26589. %@AS@%          {
  26590. %@AS@%              _outtext( "Error: Can't set font: " );
  26591. %@AS@%              _outtext( list );
  26592. %@AS@%          }
  26593. %@AS@%          getch();
  26594. %@AS@%      }
  26595. %@AS@%      _unregisterfonts();
  26596. %@AS@%      _setvideomode( _DEFAULTMODE );
  26597. %@AS@%  }%@AE@%%@NL@%
  26598. %@NL@%
  26599. %@NL@%
  26600. %@NL@%
  26601. %@NL@%
  26602. %@QR:_outmem@%%@NL@%
  26603. %@2@%%@CR:C6A02191091 @%%@AB@%_outmem%@AE@%%@EH@%%@NL@%
  26604. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26605. %@NL@%
  26606. %@NL@%
  26607. %@3@%%@AB@%Description%@CR:C6A02191092 @%%@AE@%%@EH@%%@NL@%
  26608. %@NL@%
  26609. Prints text of a specified length in graphics mode.  %@NL@%
  26610. %@NL@%
  26611. %@AS@%  #include <graph.h>%@AE@%%@NL@%
  26612. %@NL@%
  26613. %@AS@%  void _far_outmem( unsigned char_far *text, short length );%@AE@%%@NL@%
  26614. %@NL@%
  26615. %@AI@%text%@AE@%                              Text string to output
  26616.  
  26617. %@AI@%length%@AE@%                            Length of string to output
  26618.  
  26619. %@NL@%
  26620. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  26621. %@NL@%
  26622. The %@AB@%_outmem%@AE@% function outputs the string that %@AI@%text%@AE@% points to. The %@AI@%length%@AE@%
  26623. argument specifies the number of characters to output.  %@NL@%
  26624. %@NL@%
  26625. Unlike %@AB@%_outtext%@AE@%, the %@AB@%_outmem%@AE@% function prints all characters literally,
  26626. including ASCII 10, 13, and 0 as the equivalent graphics characters. No
  26627. formatting is provided. Text is printed using the current text color,
  26628. starting at the current text position.  %@NL@%
  26629. %@NL@%
  26630. To output text using special fonts, you must use the %@AB@%_outgtext%@AE@% function.  %@NL@%
  26631. %@NL@%
  26632. %@NL@%
  26633. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  26634. %@NL@%
  26635. None.  %@NL@%
  26636. %@NL@%
  26637. %@NL@%
  26638. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  26639. %@NL@%
  26640.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  26641. %@NL@%
  26642. %@NL@%
  26643. %@NL@%
  26644. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  26645. %@NL@%
  26646. %@AB@%_outtext%@AE@%,  %@AB@%_settextcolor%@AE@%,  %@AB@%_settextposition%@AE@%,  %@AB@%_settextwindow%@AE@%  %@NL@%
  26647. %@NL@%
  26648. %@NL@%
  26649. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  26650. %@NL@%
  26651. %@AS@%  /* OUTMEM.C illustrates:
  26652. %@AS@%   *    _outmem
  26653. %@AS@%   */
  26654. %@AS@%  
  26655. %@AS@%  #include <stdio.h>
  26656. %@AS@%  #include <graph.h>
  26657. %@AS@%  
  26658. %@AS@%  void main()
  26659. %@AS@%  {
  26660. %@AS@%      int  i, len;
  26661. %@AS@%      char tmp[10];%@AE@%%@NL@%
  26662. %@NL@%
  26663. %@AS@%  _clearscreen( _GCLEARSCREEN );
  26664. %@AS@%      for( i = 0; i < 256; i++ )
  26665. %@AS@%      {
  26666. %@AS@%          _settextposition( (i % 24) + 1, (i / 24) * 7 );
  26667. %@AS@%          len = sprintf( tmp, "%3d %c", i, i );
  26668. %@AS@%          _outmem( tmp, len );
  26669. %@AS@%      }
  26670. %@AS@%      _settextposition( 24, 1 );
  26671. %@AS@%  }%@AE@%%@NL@%
  26672. %@NL@%
  26673. %@NL@%
  26674. %@NL@%
  26675. %@NL@%
  26676. %@QR:outp@%%@QR:outpw@%%@NL@%
  26677. %@2@%%@CR:C6A02201093 @%%@AB@%outp, outpw%@AE@%%@EH@%%@NL@%
  26678. %@AB@%────────────────────────────────────────────────────────────────────────────%@AE@%%@NL@%
  26679. %@NL@%
  26680. %@NL@%
  26681. %@3@%%@AB@%Description%@CR:C6A02201094 @%%@CR:C6A02201095 @% %@CR:C6A02201096 @%%@CR:C6A02201097 @%%@AE@%%@EH@%%@NL@%
  26682. %@NL@%
  26683. Outputs a byte (%@AB@%outp%@AE@%) or a word (%@AB@%outpw%@AE@%) at a port.  %@NL@%
  26684. %@NL@%
  26685. %@AS@%  #include <conio.h>    Required only for function declarations%@AE@%%@NL@%
  26686. %@NL@%
  26687. %@AS@%  int outp( unsigned port, int databyte );%@AE@%%@NL@%
  26688. %@NL@%
  26689. %@AS@%  unsigned outpw( unsigned port, unsigned dataword );%@AE@%%@NL@%
  26690. %@NL@%
  26691. %@AI@%port%@AE@%                              Port number
  26692.  
  26693. %@AI@%databyte%@AE@%                          Output value
  26694.  
  26695. %@AI@%dataword%@AE@%                          Output value
  26696.  
  26697. %@NL@%
  26698. %@3@%%@AB@%Remarks%@AE@%%@EH@%%@NL@%
  26699. %@NL@%
  26700. The %@AB@%outp%@AE@% and %@AB@%outpw%@AE@% functions write a byte and a word, respectively, to the
  26701. specified output port. The %@AI@%port%@AE@% argument can be any unsigned integer in the
  26702. range 0 - 65,535; %@AI@%byte%@AE@%  can be any integer in the range 0 - 255; and
  26703. %@AI@%dataword%@AE@% can be any value in the range 0 - 65,535.  %@NL@%
  26704. %@NL@%
  26705. Both %@AB@%outp%@AE@% and %@AB@%outpw%@AE@% are supported in OS/2. You must use a .DEF file to
  26706. declare the IOSEG segment the run-time library uses to perform input/output
  26707. on the port. In addition, the intrinsic (/Oi) versions of these functions do
  26708. not work unless you put the code in a segment that is marked with the %@AB@%IOPL%@AE@%
  26709. keyword in the .DEF file.  %@NL@%
  26710. %@NL@%
  26711. You cannot do IOPL from a regular code segment, so the run-time library has
  26712. declared a separate code segment called %@AB@%_IOSEG%@AE@%. In order to use %@AB@%inp%@AE@%, %@AB@%inpw%@AE@%,
  26713. %@AB@%outp%@AE@%, or %@AB@%outp%@AE@% in any of the protected mode run-time libraries (?LIBCP,
  26714. LLIBCDLL, LLIBCMT, or CDLLOBJS-based DLL), you must have a .DEF file with
  26715. this line in it:  %@NL@%
  26716. %@NL@%
  26717. %@AS@%  SEGMENTS _IOSEG CLASS 'IOSEG_CODE' IOPL%@AE@%%@NL@%
  26718. %@NL@%
  26719. %@NL@%
  26720. %@3@%%@AB@%Return Value%@AE@%%@EH@%%@NL@%
  26721. %@NL@%
  26722. The functions return the data output. There is no error return.  %@NL@%
  26723. %@NL@%
  26724. %@NL@%
  26725. %@3@%%@AB@%Compatibility%@AE@%%@EH@%%@NL@%
  26726. %@NL@%
  26727.  ANSI  %@AB@%%@AE@% DOS  %@AB@%%@AE@% OS/2   UNIX   XENIX%@NL@%
  26728. %@NL@%
  26729. %@NL@%
  26730. %@NL@%
  26731. %@3@%%@AB@%See Also%@AE@%%@EH@%%@NL@%
  26732. %@NL@%
  26733. %@AB@%inp%@AE@%, %@AB@%inpw%@AE@%  %@NL@%
  26734. %@NL@%
  26735. %@NL@%
  26736. %@3@%%@AB@%Example%@AE@%%@EH@%%@NL@%
  26737. %@NL@%
  26738. %@AS@%  /* OUTP.C: This program uses inp and outp to make sound of variable tone
  26739. %@AS@%   * and duration.
  26740. %@AS@%   */%@AE@%%@NL@%
  26741. %@NL@%
  26742. %@AS@%  #include <conio.h>
  26743. %@AS@%  #include <stdio.h>
  26744. %@AS@%  #include <time.h>
  26745. %@AS@%  
  26746. %@AS@%  void Beep( unsigned duration, unsigned frequency ); /* Prototypes */
  26747. %@AS@%  void Sleep( clock_t wait );
  26748. %@AS@%  
  26749. %@AS@%  void main ()
  26750. %@AS@%  {
  26751. %@AS@%      Beep( 698, 700 );
  26752. %@AS@%      Beep( 523, 500 );
  26753. %@AS@%  }
  26754. %@AS@%  
  26755. %@AS@%  /* Sounds the speaker for a time specified in microseconds by duration
  26756. %@AS@%   * at a pitch specified in hertz by frequency.
  26757. %@AS@%   */
  26758. %@AS@%  void Beep( unsigned frequency, unsigned duration )
  26759. %@AS@%  {
  26760. %@AS@%      int control;
  26761. %@AS@%  
  26762. %@AS@%      /* If frequency is 0, Beep doesn't try to make a sound. */
  26763. %@AS@%      if( frequency )
  26764. %@AS@%