2 * fileops.h - OS agnostic disk io operations
4 * This header describes the strictly internal part of the api
6 #ifndef INCLUDE_fileops_h__
7 #define INCLUDE_fileops_h__
16 GIT_INLINE(int) link(const char *GIT_UNUSED(old
), const char *GIT_UNUSED(new))
24 GIT_INLINE(int) git__mkdir(const char *path
, int GIT_UNUSED(mode
))
30 extern int git__unlink(const char *path
);
31 extern int git__mkstemp(char *template);
32 extern int git__fsync(int fd
);
34 # ifndef GIT__WIN32_NO_HIDE_FILEOPS
35 # define unlink(p) git__unlink(p)
36 # define mkstemp(t) git__mkstemp(t)
37 # define mkdir(p,m) git__mkdir(p, m)
38 # define fsync(fd) git__fsync(fd)
40 #endif /* GIT_WIN32 */
43 #if !defined(O_BINARY)
47 #define GITFO_BUF_INIT {NULL, 0}
50 typedef struct gitfo_cache gitfo_cache
;
52 typedef struct { /* file io buffer */
53 void *data
; /* data bytes */
54 size_t len
; /* data length */
57 extern int gitfo_exists(const char *path
);
58 extern int gitfo_open(const char *path
, int flags
);
59 extern int gitfo_creat(const char *path
, int mode
);
60 #define gitfo_close(fd) close(fd)
62 extern int gitfo_read(git_file fd
, void *buf
, size_t cnt
);
63 extern int gitfo_write(git_file fd
, void *buf
, size_t cnt
);
64 #define gitfo_lseek(f,n,w) lseek(f, n, w)
65 extern off_t
gitfo_size(git_file fd
);
67 extern int gitfo_read_file(gitfo_buf
*obj
, const char *path
);
68 extern void gitfo_free_buf(gitfo_buf
*obj
);
69 extern int gitfo_move_file(char *from
, char *to
);
71 #define gitfo_stat(p,b) stat(p, b)
72 #define gitfo_fstat(f,b) fstat(f, b)
74 #define gitfo_unlink(p) unlink(p)
75 #define gitfo_rmdir(p) rmdir(p)
76 #define gitfo_chdir(p) chdir(p)
77 #define gitfo_mkdir(p,m) mkdir(p, m)
79 #define gitfo_mkstemp(t) mkstemp(t)
80 #define gitfo_fsync(fd) fsync(fd)
81 #define gitfo_chmod(p,m) chmod(p, m)
84 * Read-only map all or part of a file into memory.
85 * When possible this function should favor a virtual memory
86 * style mapping over some form of malloc()+read(), as the
87 * data access will be random and is not likely to touch the
88 * majority of the region requested.
90 * @param out buffer to populate with the mapping information.
91 * @param fd open descriptor to configure the mapping from.
92 * @param begin first byte to map, this should be page aligned.
93 * @param end number of bytes to map.
95 * - GIT_SUCCESS on success;
96 * - GIT_EOSERR on an unspecified OS related error.
98 extern int gitfo_map_ro(
105 * Release the memory associated with a previous memory mapping.
106 * @param map the mapping description previously configured.
108 extern void gitfo_free_map(git_map
*map
);
111 * Walk each directory entry, except '.' and '..', calling fn(state).
113 * @param pathbuf buffer the function reads the initial directory
114 * path from, and updates with each successive entry's name.
115 * @param pathmax maximum allocation of pathbuf.
116 * @param fn function to invoke with each entry. The first arg is
117 * the input state and the second arg is pathbuf. The function
118 * may modify the pathbuf, but only by appending new text.
119 * @param state to pass to fn as the first arg.
121 extern int gitfo_dirent(
124 int (*fn
)(void *, char *),
127 extern gitfo_cache
*gitfo_enable_caching(git_file fd
, size_t cache_size
);
128 extern int gitfo_write_cached(gitfo_cache
*ioc
, void *buf
, size_t len
);
129 extern int gitfo_flush_cached(gitfo_cache
*ioc
);
130 extern int gitfo_close_cached(gitfo_cache
*ioc
);
132 #endif /* INCLUDE_fileops_h__ */