home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / OSLib / OSLib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  9.4 KB  |  438 lines

  1.  
  2. /*
  3.  *    Operating system library.  
  4.  *
  5.  *    This module handles interaction with the operating-system specific
  6.  *    intricacies with file manipulation, memory management, process
  7.  *    spawning, etc.
  8.  *
  9.  */
  10.  
  11. #ifndef __OSLIB_H__
  12. #define __OSLIB_H__
  13.  
  14. #include <conf.h>
  15.  
  16. #include "centry.h"
  17. #include "clstandardtypes.h"
  18. #include "clstandardheaders.h"
  19.  
  20. #include "sysdeps.h"
  21.  
  22. /*    Operating system implementation */
  23.  
  24. /*    Guess the type;
  25.  
  26.     although there are references to compilers,
  27.     these are only based on what I know; these
  28.     xxx_FS defines should not make assumptions
  29.     about the C library                         
  30. */
  31. #if defined(UNDER_MACOS)
  32. #define MAC_FS 1
  33. #endif
  34.  
  35. #if defined(UNDER_QNX)
  36. #define QNX_FS         1
  37. #define POSIX_FS     1
  38. #endif
  39.  
  40. #if defined(UNDER_BEOS)
  41. #define BEWORKS_FS    1
  42. #define POSIX_FS    1
  43. #endif
  44.  
  45. #if defined(UNDER_UNIX)
  46. #define POSIX_FS    1
  47. #endif
  48.  
  49. #if defined(UNDER_WIN32)
  50. #define WIN32_FS    1
  51. #endif
  52.  
  53. #if (defined(WIN32_FS) && defined(POSIX_FS)) || \
  54.     (defined(WIN32_FS) && defined(QNX_FS)) || \
  55.     (defined(MAC_FS) && defined(POSIX_FS)) || \
  56.     (defined(MAC_FS) && defined(WIN32_FS))
  57. #error Conflicting operating systems selected.
  58. #elif !defined(WIN32_FS) && !defined(POSIX_FS) && !defined(MAC_FS)
  59. #error No operating system specified.
  60. #endif
  61.  
  62. #if WIN32_FS
  63. #include "Win32.h"
  64. #elif POSIX_FS
  65. #include "Posix.h"
  66. #elif MAC_FS
  67. #include "MacOS.h"
  68. #endif
  69.  
  70. /*    OS specifier */
  71.  
  72. typedef
  73. struct    OSSpec
  74. {
  75.     OSPathSpec    path;
  76.     OSNameSpec    name;
  77. }    OSSpec;
  78.  
  79.  
  80. /*    get error text for an OSError */
  81. char
  82. *OS_GetErrText(OSError err);                
  83.  
  84. /*********************/
  85.  
  86. /*    Initialize C program context  */
  87. OSError
  88. OS_InitProgram(int *argc, char ***argv);
  89.  
  90. /*    Terminate C program context  */
  91. OSError
  92. OS_TermProgram(void);
  93.  
  94. /*********************/
  95.  
  96. typedef unsigned long    OSSize;
  97. typedef signed long        OSPos;
  98.  
  99. /*    create a new file, overwrite an old one if existing */
  100. OSError    
  101. OS_Create(const OSSpec *spec, OSFileType *type);
  102.  
  103. /*    get status of a file */
  104. OSError
  105. OS_Status(const OSSpec *spec);
  106.  
  107. /*  get type of a file */
  108. OSError
  109. OS_GetFileType(const OSSpec *spec, OSFileType *type);
  110.  
  111. /*  set type for a file */
  112. OSError
  113. OS_SetFileType(const OSSpec *spec, OSFileType *type);
  114.  
  115. /*  get timestamps of a file */
  116. OSError
  117. OS_GetFileTime(const OSSpec *spec, OSTime *crtm, OSTime *chtm);
  118.  
  119. /*  set timestamps of a file; crtm or chtm may be NULL */
  120. OSError
  121. OS_SetFileTime(const OSSpec *spec, OSTime *crtm, OSTime *chtm);
  122.  
  123. /*    modify protection on a file */
  124. OSError
  125. OS_ModifyProtection(const OSSpec *spec, bool protect);
  126.  
  127. /*    get protection on a file */
  128. OSError
  129. OS_CheckProtection(const OSSpec *spec, bool *is_protected);
  130.  
  131. /*    get disk space info */
  132. OSError
  133. OS_GetDiskStats(const OSPathSpec *spec, 
  134.                 OSSize *blocksize, OSSize *total, OSSize *free);
  135.                 
  136.  
  137. /*************************************/
  138.  
  139. typedef enum    
  140. {
  141.     OSReadOnly,                         /* only read */
  142.     OSWrite,                             /* only write */
  143.     OSReadWrite,                         /* read and write */
  144.     OSAppend                             /* only append */
  145. OSOpenMode;
  146.  
  147. typedef enum 
  148.      OSSeekRel,                             /* seek relative to current position */
  149.     OSSeekAbs,                             /* absolute position */
  150.     OSSeekEnd                             /* from end of file */
  151. }
  152. OSSeekMode;
  153.  
  154. /*    open an existing file */
  155. OSError
  156. OS_Open(const OSSpec *spec, OSOpenMode mode, OSRef *ref);
  157.  
  158. /*    write binary data, up to length bytes;
  159.     length==0 can extend file;
  160.     update length;
  161.     error indicates serious failure */
  162. OSError
  163. OS_Write(OSRef ref, void *buffer, OSSize *length);
  164.  
  165. /*    read binary data, up to length bytes;
  166.     update length;
  167.     error indicates serious failure.  */
  168. OSError
  169. OS_Read(OSRef ref, void *buffer, OSSize *length);
  170.  
  171. /*    seek a file;
  172.     illegal seek is revealed by next write or read;
  173.     error indicates serious failure.  */
  174. OSError
  175. OS_Seek(OSRef ref, OSSeekMode how, OSPos offset);
  176.  
  177. /*    tell file position */
  178. OSError
  179. OS_Tell(OSRef ref, OSPos *offs);
  180.  
  181. /*    close a file */
  182. OSError
  183. OS_Close(OSRef ref);
  184.  
  185. /*  get length of a file;
  186.     return error if directory or not found */
  187. OSError
  188. OS_GetSize(OSRef ref, OSSize *length);
  189.  
  190. /*  set length of a file;
  191.     return error if directory or not found */
  192. OSError
  193. OS_SetSize(OSRef ref, OSSize length);
  194.  
  195.  
  196. /*******************************************/
  197.  
  198. /*    delete a file */
  199. OSError
  200. OS_Delete(const OSSpec *spec);
  201.  
  202. /*    rename a file */
  203. OSError
  204. OS_Rename(const OSSpec *oldspec, const OSSpec *newspec);
  205.  
  206. /*    make directory */
  207. OSError
  208. OS_Mkdir(const OSSpec *spec);
  209.  
  210. /*    remove directory */
  211. OSError
  212. OS_Rmdir(const OSPathSpec *spec);
  213.  
  214. /*    change directory */
  215. OSError
  216. OS_Chdir(const OSPathSpec *spec);
  217.  
  218. /*    get current working directory */
  219. OSError
  220. OS_GetCWD(OSPathSpec *spec);
  221.  
  222. /*    spawn a subprocess; 
  223.     pass the full environment block or NULL for the    current one */
  224. OSError
  225. OS_Execute(const OSSpec *spec, char **argv, char **envp, 
  226.             const char *stdoutfile, const char *stderrfile, int *exitcode);
  227.  
  228. /*************************************/
  229.  
  230. /*    tell if a canonical filepath is legal for filesystem */
  231. OSError
  232. OS_IsLegalPath(const char *path);
  233.  
  234. /*    tell if a canonical filepath represents a full path */
  235. int
  236. OS_IsFullPath(const char *path);
  237.  
  238. /*    return ptr to directory in a vol+dir path */
  239. const char *
  240. OS_GetDirPtr(const char *path);
  241.  
  242. /*    compare paths */
  243. int
  244. OS_EqualPath(const char *a, const char *b);
  245.  
  246. /*************************************/
  247.  
  248. /*    make OSSpec from a path;
  249.     path may be relative or absolute, or a filename. */
  250. OSError
  251. OS_MakeSpec(const char *path, OSSpec *spec, bool *isfile);
  252.  
  253. /*    make OSSpec from a path;
  254.     must resolve to a file. */
  255. OSError
  256. OS_MakeFileSpec(const char *path, OSSpec *spec);
  257.  
  258. /*    make OSPathSpec from a volume and directory;
  259.     does not necessarily validate 'vol' as a volume
  260.     or 'dir' as a directory; but only the final path;
  261.     'vol' or 'dir' may each be NULL. */
  262. OSError
  263. OS_MakePathSpec(const char *vol, const char *dir, OSPathSpec *spec);
  264.  
  265. /*    make OSNameSpec from a filename;
  266.     tests name for illegal characters */
  267. OSError
  268. OS_MakeNameSpec(const char *name, OSNameSpec *spec);
  269.  
  270. /*    return FS root spec */
  271. OSError
  272. OS_GetRootSpec(OSPathSpec *spec);
  273.  
  274. /*************************************/
  275.  
  276. /*
  277.     For the OS_xxxToString functions, the string buffer
  278.     and its maximum size are passed.  If the output is too
  279.     big for the buffer, the output is truncated.  If the
  280.     buffer is given as NULL, the buffer is malloc()ed.
  281.     
  282.     A pointer to the buffer is returned, or NULL if memory is out.
  283. */
  284.  
  285. extern char STSbuf[OS_PATHSIZE];
  286.  
  287. /*    make a full pathname from OSSpec */
  288. char *
  289. OS_SpecToString(const OSSpec *spec, char *fullpath, int size);
  290.  
  291. #define OS_SpecToString1(spec) \
  292.     OS_SpecToString(spec, STSbuf, OS_PATHSIZE)
  293. #define OS_SpecToString2(spec,buf) \
  294.     OS_SpecToString(spec, buf, OS_PATHSIZE)
  295.  
  296. /*    make a path from OSPathSpec */
  297. char *
  298. OS_PathSpecToString(const OSPathSpec *spec, char *path, int size);
  299.  
  300. #define OS_PathSpecToString1(spec) \
  301.     OS_PathSpecToString(spec, STSbuf, OS_PATHSIZE)
  302. #define OS_PathSpecToString2(spec,buf) \
  303.     OS_PathSpecToString(spec, buf, OS_PATHSIZE)
  304.  
  305. /*    make a name from OSNameSpec */
  306. char *
  307. OS_NameSpecToString(const OSNameSpec *spec, char *name, int size);
  308.  
  309. #define OS_NameSpecToString1(spec) \
  310.     OS_NameSpecToString(spec, STSbuf, OS_PATHSIZE)
  311. #define OS_NameSpecToString2(spec,buf) \
  312.     OS_NameSpecToString(spec, buf, OS_PATHSIZE)
  313.  
  314. /*    return the size of an OSPathSpec, for duplication purposes */
  315. int
  316. OS_SizeOfPathSpec(const OSPathSpec *spec);
  317.  
  318. /*    return the size of an OSNameSpec, for duplication purposes */
  319. int
  320. OS_SizeOfNameSpec(const OSNameSpec *spec);
  321.  
  322. /*    compare OSSpecs */
  323. int
  324. OS_EqualSpec(const OSSpec *a, const OSSpec *b);
  325.  
  326. /*    compare OSPathSpecs */
  327. int
  328. OS_EqualPathSpec(const OSPathSpec *a, const OSPathSpec *b);
  329.  
  330. /*    compare OSNameSpecs */
  331. int
  332. OS_EqualNameSpec(const OSNameSpec *a, const OSNameSpec *b);
  333.  
  334. /*    tell if OSSpec is a directory */
  335. int
  336. OS_IsDir(const OSSpec *spec);
  337.  
  338. /*    tell if OSSpec is a file */
  339. int
  340. OS_IsFile(const OSSpec *spec);
  341.  
  342. /*    tell if OSSpec is a [soft] link / alias */
  343. int
  344. OS_IsLink(const OSSpec *spec);
  345.  
  346. /*    resolve a [soft] link / alias;  link ptr may be equal to target ptr */
  347. OSError
  348. OS_ResolveLink(const OSSpec *link, OSSpec *target);
  349.  
  350. /*************************************/
  351.  
  352. /*    open a directory for reading */
  353. OSError 
  354. OS_OpenDir(const OSPathSpec *spec, OSDirRef *ref);
  355.  
  356. /*    read an entry from a directory;
  357.     don't return "." or "..";
  358.     return error when end-of-directory reached */
  359. OSError
  360. OS_ReadDir(OSDirRef *ref, OSSpec *entry, char *filename, bool *isfile);
  361.  
  362. /*    close directory */
  363. OSError
  364. OS_CloseDir(OSDirRef *ref);
  365.  
  366.  
  367. /*************************************/
  368.  
  369. /*    return time in milliseconds */
  370. unsigned long
  371. OS_GetMilliseconds(void);
  372.  
  373. /*    return current time */
  374. void
  375. OS_GetTime(OSTime *tm);
  376.  
  377. /*    allocate a memory handle */
  378. OSError
  379. OS_NewHandle(OSSize size, OSHandle *hand);
  380.  
  381. /*    resize handle; handle may not be locked  */
  382. OSError
  383. OS_ResizeHandle(OSHandle *hand, OSSize size);
  384.  
  385. /*    lock handle into memory; always succeeds  */
  386. void *
  387. OS_LockHandle(OSHandle *hand);
  388.  
  389. /*    unlock handle  */
  390. void
  391. OS_UnlockHandle(OSHandle *hand);
  392.  
  393. /*    free handle  */
  394. OSError
  395. OS_FreeHandle(OSHandle *hand);
  396.  
  397. /*    get handle size */
  398. OSError
  399. OS_GetHandleSize(OSHandle *hand, OSSize *size);
  400.  
  401. /*    invalidate handle */
  402. void
  403. OS_InvalidateHandle(OSHandle *hand);
  404.  
  405. /*    tell whether a handle is valid */
  406. bool
  407. OS_ValidHandle(OSHandle *hand);
  408.  
  409. /*************************************/
  410.  
  411. /*    Shared library / DLL routines  */
  412.  
  413. /*    open a shared library  */
  414. OSError
  415. OS_OpenLibrary(const OSSpec *spec, OSLibrary *lib);
  416.  
  417. /*    find a symbol in the library */
  418. OSError
  419. OS_GetLibrarySymbol(OSLibrary lib, char *name, void **sym);
  420.  
  421. /*    close a shared library */
  422. OSError
  423. OS_CloseLibrary(OSLibrary lib);
  424.  
  425. /*************************************/
  426.  
  427. #define __INSIDE_OSLIB_H__
  428. #include "OSLibGeneric.h"
  429. #include "OSLibExtras.h"
  430. #undef __INSIDE_OSLIB_H__
  431.  
  432.  
  433. #include "cexit.h"
  434.  
  435. #endif    //__OSLIB_H__
  436.