home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / V1 < prev    next >
Encoding:
Text File  |  1992-01-07  |  10.5 KB  |  289 lines

  1. /*
  2.  *   system.cf -- non-ANSI 
  3.  *
  4.  *   Operating-system services.
  5.  *
  6.  *           Copyright (c) 1990, MetaWare Incorporated
  7.  */
  8.  
  9. #ifndef _SYSTEM_CF
  10. #define _SYSTEM_CF
  11.  
  12. #if ! _system_defs_included
  13. /*    High C Interface to Xenix-DOS or Concurrent DOS 286 I/O Services. */
  14. /* This file makes use of a define "CDOS" that is set True under
  15.    Concurrent DOS 286 systems.  A few of the system-level routines differ
  16.    for this OS.
  17. */   
  18.  
  19. #include <implemen.cf>
  20. #include <language.cf>
  21.  
  22. #pragma Global_aliasing_convention(_Private_routine_prefix "%r");
  23. #pragma Calling_convention(PASCAL);
  24.  
  25. /* Some routines are additionally aliased to prevent conflicts     */
  26. /* with Pascal intrinsic routines Write, Read, Trunc, and Close. */
  27. typedef int File_handle;     /* Small integer file handle. */
  28. typedef enum{From_beginning,From_current,From_end} Seek_method;
  29.  
  30. /* For networking access:  MSDOS 3.x only. */
  31. typedef enum{Compatibility,Deny_read_write,Deny_write,Deny_read,Deny_none} 
  32.         Sharing_mode_type;
  33.     /* Use data pragma to share with Pascal system.pf package: */        
  34.     #pragma data(common,"?" _Private_prefix "system");
  35. Sharing_mode_type Sharing_mode; /* Initialized to Compatibility. */
  36.     #pragma data;
  37. typedef enum{For_reading, For_writing, For_updating} Open_method;
  38.  
  39. /* File attributes: */
  40. #define Attr_read_only 1       /* File may not be modified. */
  41. #define Attr_hidden    2       /* File is hidden. */
  42. #define Attr_system    4       /* File is a "system" file. */
  43. #define Attr_volume_id 8       /* File is the volume id. */
  44. #define Attr_directory 16      /* File is a directory. */
  45. #define Attr_archive   32      /* File has not been archived. */
  46. #if defined(CDOS)
  47. #define Attr_security  64      /* File has security enabled. */
  48. #endif
  49.  
  50. #if defined(ADOS)
  51. typedef unsigned      File_mode;/* A word set of the above bits. */
  52. #else
  53. typedef unsigned char File_mode;/* A byte set of the above bits. */
  54. #endif
  55.  
  56. /* File class: */
  57. #define Disk_file      0      /* File is on disk. */
  58. #define Console_input  1      /* File is the keyboard. */
  59. #define Console_output 2      /* File is the monitor. */
  60. #define Printer_device 3      /* File is the printer. */
  61. #define Other_device   4      /* File is something else. */
  62. typedef unsigned char File_class;
  63.  
  64. /*
  65.   NOTE: Following every call, if an error occurred, 
  66.         the imported variable errno contains the status of the call. 
  67.     errno will contain one of the error codes specified after each
  68.     routine declaration below.
  69.         If no error occurred,
  70.         the errno variable is left UNTOUCHED (it is not cleared),
  71.         in accordance with the philosophy of the ANSI C library.
  72. */
  73.  
  74.  
  75. /* Return the mode of a file. */
  76. extern File_mode c_filemode(char *Name);
  77.    /* Error_path_not_found. */
  78.    /* Error_access_denied. */
  79.    /* Error_invalid_function -- this error should never occur. */
  80.  
  81. /* Return the class of a file. */
  82. extern File_class fileclass(File_handle F);
  83.  
  84. /* Close file whose handle is "F". */
  85. extern void close(File_handle F);
  86.    /* Error_invalid_handle -- file was not open, or "F" contains garbage. */
  87.    #pragma Alias(close,_Private_routine_prefix "zclose");
  88.    /* The Alias avoids external conflict with Pascal Close intrinsic. */
  89.  
  90. /* Create file "name" and open it for writing. */
  91. extern File_handle c_create(char *Name, File_mode Mode);
  92.    /* Error_access_denied. */
  93.    /* Error_path_not_found. */
  94.    /* Error_too_many_files - file created but not opened. */
  95. #if defined(CDOS)
  96. extern unsigned _open_and_mask, _open_or_mask;
  97.    /* And/or the CDOS open/create flags with these values: */
  98.    /* Flags = (Flags & _open_and_mask) | _open_or_mask;    */
  99.    /* This applies for both c_create and c_open calls.        */
  100.    /* These are initialized to 0xffff and 0x0 initially.   */
  101. #endif
  102.  
  103. /* Reposition the file pointer assoicated with "F" to location "Loc" */
  104. /* according to the method specified in "Method". */
  105. /* Return the new position. */
  106. extern long lseek(File_handle F, long Loc, Seek_method Method);
  107.    /* Error_invalid_handle. */
  108.    /* Error_invalid_function - the parameter "method" contains garbage. */
  109.    #pragma Alias(lseek,_Private_routine_prefix "lseek");
  110.  
  111. /* Make a new directory named "Name". */
  112. extern void c_mkdir(char *Name);
  113.    /* Error_path_not_found. */
  114.    /* Error_access_denied - file already exists or directory overflow. */
  115.  
  116. /* Open file "Name" for reading, writing, or updating. */
  117. extern File_handle c_open(char *Name, Open_method Method);
  118.    /* Error_invalid_access -- "method" parameter contains garbage         */
  119.    /* Error_file_not_found                          */
  120.    /* Error_access_denied  -- file is a directory, volume id or read-only */
  121.    /* Error_too_many_files -- limit in CONFIG.SYS has been reached      */
  122.  
  123. /* Read "Cnt" bytes from file "F" into buffer whose address is "Bufp". */
  124. /* Returns the number of bytes actually read. */
  125. extern unsigned read(File_handle F, void *Buf, unsigned Cnt);
  126.    /* Error_invalid_handle  -- file not open. */
  127.    /* Error_access_denied   -- "F" was opened but not for reading. */
  128.    #pragma Alias(read,_Private_routine_prefix "zread");
  129.  
  130. /* Remove directory. */
  131. extern void c_rmdir(char *Name);
  132.    /* Error_path_not_found. */
  133.    /* Error_access_denied. */
  134.    /* Error_current_directory - "Name" is the name of the current directory. */
  135.  
  136. /* Erase file from directory. */
  137. extern void c_unlink(char *Name);
  138.    /* Error_file_not_found. */
  139.    /* Error_access_denied. */
  140.  
  141. /* Rename a file. */
  142. extern void c_rename(char *Old, char *New);
  143.   /* Error_file_not_found. */
  144.   /* Error_not_same_device. */
  145.   /* Error_access_denied. */
  146.  
  147. /* Write "Cnt" bytes from buffer whose address is "Bufp" into file "F". */
  148. /* Note: If disk overflow occurs, Errno will have the value Error_disk_overflow */
  149. /*     and Write will return with the number of bytes actually written. */
  150.  
  151. extern unsigned write(File_handle F, void *Buf, unsigned Cnt);
  152.    /* Error_invalid_handle - file not open. */
  153.    /* Error_access_denied  - file not open for writing. */
  154.    #pragma Alias(write ,_Private_routine_prefix "zwrite");
  155.  
  156. /* Truncates file at current position. */
  157. extern void trunc(File_handle F);
  158.    /* Error_invalid_handle. */
  159.    /* Error_access_denied. */
  160.    #pragma Alias(trunc,_Private_routine_prefix "ztrunc");
  161.  
  162. #if defined(CDOS)
  163. typedef _packed struct {
  164.    unsigned short Year; char Month, Day, Hour, Min, Sec;
  165.    } Time_and_date;
  166. #elif defined(ADOS)
  167. typedef struct {
  168.    unsigned short Creation_date, Creation_time, Access_date, Access_time,
  169.       Write_date, Write_time;
  170.       } File_time_type;
  171. #endif
  172.     
  173. typedef struct {
  174. #if defined(ADOS)
  175.    File_time_type TD;
  176.    long EOF_data,     /* Who knows what this is? */
  177.        Size;        /* Size of file. */
  178.    File_mode Attr;
  179.    unsigned char Namelen; /* Length of upcoming name; redundant with nul-terminator. */
  180.    char Name[13];   /* Includes trailing nul. */
  181. #elif defined(CDOS)
  182.    long Key;        /* For subsequent finds. */
  183.    char Name[18];    /* 18 bytes of name; 0-terminated. */
  184.    File_mode Attr;      /* Attribute bits. */
  185.    char Padding1;    /* Attr is only 8 bits; CDOS supplies 16. */
  186.    unsigned short Recsize;
  187.    char User, Group;
  188.    unsigned short Protection;
  189.    char Reserved1[6];
  190.    unsigned long Size;    /* File size. */
  191.    Time_and_date TD;
  192.    char Reserved2;
  193. #else           /* MS-DOS. */
  194.    char Reserved[21];
  195.    File_mode Attr;
  196.    unsigned short Time, Date;
  197.    long Size;
  198.    char Name[13];   /* File name. */
  199. #endif   
  200.    } Find_buffer;
  201.  
  202. extern void c_find_first(char *Path, Find_buffer *S
  203. #if !defined(CDOS)
  204.     , File_mode Attr
  205. #if defined(ADOS)
  206.         , unsigned *Dirhandle     /* Must be presented next time. */  
  207. #endif      
  208. #endif    
  209.     );
  210.    /* "Path" is a path name with wild card characters.  The first file
  211.     * encountered that matches the path name and has a subset of the
  212.     * attributes specified in "Attr" is returned in S.  (Attr is not
  213.     * applicable for Concurrent DOS 286.)
  214.     * This value of S must be passed to Find_next to get subsequent
  215.     * matches.
  216.     */
  217.    /*      Error_file_not_found    -- invalid path name  */
  218.    /*      Error_no_more_files    -- no files matching this specification */
  219.  
  220. #if defined(ADOS)
  221. extern void find_next(unsigned Dirhandle, Find_buffer *S);
  222. extern void find_close(unsigned Dirhandle);    /* terminate find. */
  223. #elif !defined(CDOS)
  224. extern void find_next(Find_buffer *S);
  225.    /* Called after Find_first to retrieve subsequent matches. */
  226.    /* Error_no_more_files    -- no more files that match. */
  227. #else   
  228. extern void c_find_next(
  229.     char *Path,    /* CDOS requires the path a second time. */
  230.     Find_buffer *S);
  231.    /* Called after Find_first to retrieve subsequent matches. */
  232.    /* Error_no_more_files    -- no more files that match. */
  233. #endif   
  234.  
  235. #if !defined(CDOS)
  236. extern void switch_char(char *C, int Set_it);
  237.    /* Set or retrieve the Switch character. */
  238.    /* If Set_it, then set it; otherwise return it in C. */
  239. #endif   
  240.  
  241. #if !defined(CDOS)
  242. extern void file_times(File_handle F, unsigned short *Date, unsigned short *Time);
  243. #else   
  244. extern void file_times(File_handle F, Time_and_date *TD);
  245. #endif   
  246.    /* Returns the date and time of an open file. */
  247.    /* Error_invalid_handle   -- file not open.     */
  248.  
  249. #if !defined(CDOS)
  250. extern void set_file_times(File_handle F, unsigned Date, unsigned Time);
  251. #else   
  252. extern void set_file_times(File_handle F, Time_and_date *TD);
  253. #endif   
  254.    /* Sets the date/time of a file. */
  255.    /* Error_invalid_handle  -- File not open.     */
  256.  
  257. extern void get_date(unsigned short *Day, unsigned short *Month, unsigned short *Year);
  258. extern void get_time(unsigned short *Hrs, unsigned short *Mins, unsigned short *Secs);
  259.  
  260. #define Clock_precision 100 /* Clock returns time in hundredths of a second. */
  261. extern long clock();        /* Time in 100ths of a second. */
  262.  
  263. extern void dos_exit(unsigned char Return_code);
  264.  
  265. /* Change the current working directory to "name". */
  266. extern void c_chdir(char *Name);
  267.    /* Error_path_not_found. */
  268.  
  269. /* Change mode of file "name" to "Mode". */
  270. extern void c_chmod(char *Name, File_mode Mode);
  271.    /* Error_path_not_found. */
  272.    /* Error_access_denied. */
  273.    /* Error_invalid_function -- this error should never occur. */
  274.  
  275. /* Duplicate file handle "F". */
  276. extern File_handle dup(File_handle F);
  277.    /* Error_invalid_handle. */
  278.    /* Error_too_many_open_files -- file limit of CONFIG.SYS exceeded. */
  279.  
  280. /* Duplicate file handle "F" as file handle "Newfh". */
  281. extern void dup2(File_handle F, File_handle Newfh);
  282.    /* Error_invalid_handle. */
  283.  
  284. #pragma Global_aliasing_convention();
  285. #pragma Calling_convention();
  286. #define _system_defs_included 1 
  287. #endif
  288. #endif /* _SYSTEM_CF */
  289.