]> pd.if.org Git - pdclib/blob - internals/_PDCLIB_glue.h
09f47b7852581cf725ce68480ced2bc264f878f8
[pdclib] / internals / _PDCLIB_glue.h
1 #ifndef _PDCLIB_GLUE_H
2 #define _PDCLIB_GLUE_H
3 /* $Id$ */
4
5 /* OS glue functions declaration <_PDCLIB_glue.h>
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #include <_PDCLIB_int.h>
12 #include <stdbool.h>
13 #include <stddef.h>
14 _PDCLIB_BEGIN_EXTERN_C
15
16 /* -------------------------------------------------------------------------- */
17 /* OS "glue", part 2                                                          */
18 /* These are the functions you will have to touch, as they are where PDCLib   */
19 /* interfaces with the operating system.                                      */
20 /* They operate on data types partially defined by _PDCLIB_config.h.          */
21 /* -------------------------------------------------------------------------- */
22
23 /* stdlib.h */
24
25 /* A system call that terminates the calling process, returning a given status
26    to the environment.
27 */
28 void _PDCLIB_Exit( int status ) _PDCLIB_NORETURN;
29
30 /* A system call which allocates n pages of memory and returns a pointer to 
31    them. On failure, returns NULL
32 */
33 void * _PDCLIB_allocpages( size_t n );
34
35 /* A system call which frees the n pages of memory pointed to by p */
36 void _PDCLIB_freepages( void * p, size_t n );
37
38 #ifdef _PDCLIB_HAVE_REALLOCPAGES
39 /* A system call which attempts to reallocate the group of \p on pages starting
40    at \p p, resizing the chunk to be \p nn pages long. If \p mayMove is true, 
41    then then the group of pages may move; otherwise, if the group cannot be 
42    resized in its current position, failure must be reported.
43
44    On failure, returns NULL; on success, returns the address of the group of 
45    pages (if mayMove == false, then this must be equal to \p p)
46 */
47 void * _PDCLIB_reallocpages( void* p, size_t on, size_t nn, bool mayMove);
48 #endif
49
50 /* stdio.h */
51
52 /* A system call that opens a file identified by name in a given mode. Return 
53    a file descriptor uniquely identifying that file.
54    (The mode is the return value of the _PDCLIB_filemode() function.)
55 */
56 _PDCLIB_fd_t _PDCLIB_open( char const * const filename, unsigned int mode );
57
58 /* A system call that writes a stream's buffer.
59    Returns 0 on success, EOF on write error.
60    Sets stream error flags and errno appropriately on error.
61 */
62 int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream );
63
64 /* A system call that fills a stream's buffer.
65    Returns 0 on success, EOF on read error / EOF.
66    Sets stream EOF / error flags and errno appropriately on error.
67 */
68 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream );
69
70 /* A system call that repositions within a file. Returns new offset on success,
71    -1 / errno on error.
72 */
73 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence );
74
75 /* A system call that closes a file identified by given file descriptor. Return
76    zero on success, non-zero otherwise.
77 */
78 int _PDCLIB_close( _PDCLIB_fd_t fd );
79
80 /* A system call that removes a file identified by name. Return zero on success,
81    non-zero otherwise.
82 */
83 int _PDCLIB_remove( const char * filename );
84
85 /* A system call that renames a file from given old name to given new name.
86    Return zero on success, non-zero otherwise. In case of failure, the file
87    must still be accessible by old name. Any handling of open files etc. is
88    done by standard rename() already.
89 */
90 int _PDCLIB_rename( const char * old, const char * newn);
91
92 _PDCLIB_END_EXTERN_C
93 #endif