2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
7 #include <gclib/gclib.h>
8 #include <gclib/gclib_c.h>
9 #include <sys/syscall.h>
12 __export
int Dfnread (char * f_name
, void * p_lp_buffer
, int int_size
)
14 int n_bytes
= int_size
> fsize (f_name
) ? fsize (f_name
) : int_size
;
17 fd
= open (f_name
, O_RDONLY
);
21 if (read (fd
, p_lp_buffer
, n_bytes
) < 0)
28 __export
char * Dread_to_eof (int fd
, int *d_out_size
)
30 char * d_buf
= (char *) malloc (4096);
42 d_ret
= read (fd
, &d_buf
[d_pos
], d_size
- d_pos
- 1);
50 if ((d_size
- d_pos
) < 4096) {
51 d_buf
= gc_realloc (d_buf
, d_size
, d_size
<< 1);
69 __export DArray
* Dfiles (char * path
)
73 struct dirent
* m_dirent
;
78 m_dir
= opendir (path
);
84 m_dirent
= readdir (m_dir
);
87 m_dirent
= (struct dirent
*) memdup (m_dirent
, sizeof (struct dirent
));
88 Ret
->add (LPCHAR (strdup (m_dirent
->d_name
)));
96 __export
int logToFile (char * fileName
, char * fmt
, ...)
100 myfile
= fopen (fileName
, "a");
102 myfile
= fopen (fileName
, "w");
106 va_start (alist
, fmt
);
107 vfprintf (myfile
, fmt
, alist
);
113 #ifdef __NR_fadvise64
114 int Dposix_fadvise (int fd
, int offset
, int len
, int advice
)
116 return posix_fadvise (fd
, offset
, len
, advice
);
117 // return syscall (__NR_fadvise64, fd, 0, offset, len, advice);
120 int Dposix_fadvise (int fd
, int offset
, int len
, int advice
)
122 #warning "Dposix_fadvise is broken.\n"