lib/file: some methods return a nullable Error on error
[nit.git] / lib / standard / file_nit.h
1 #ifndef __FILE_H
2 #define __FILE_H
3 /* This file is part of NIT ( http://www.nitlanguage.org ).
4 *
5 * Copyright 2004-2008 Jean Privat <jean@pryen.org>
6 * Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
7 * Copyright 2008 Jean-Sébastien Gélinas <calestar@gmail.com>
8 *
9 * This file is free software, which comes along with NIT. This software is
10 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
13 * is kept unaltered, and a notification of the changes is added.
14 * You are allowed to redistribute it and sell it, alone or is a part of
15 * another product.
16 */
17
18 #include <sys/stat.h>
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <sys/types.h>
22
23 extern int string_NativeString_NativeString_file_exists_0(char *f);
24 extern void *string_NativeString_NativeString_file_stat_0(char *f);
25 extern void *file_NativeFile_NativeFile_file_stat_0(FILE *f);
26 extern int string_NativeString_NativeString_file_delete_0(char *f);
27 FILE* file_int_fdtostream(int fd, char* mode);
28 int file_NativeFile_NativeFile_set_buffering_type_0(FILE* f, int buf_sz, int mode);
29
30 #define file_NativeFile_NativeFile_io_read_2(p, b, l) fread((b), 1, (l), (FILE*)(p))
31 #define file_NativeFile_NativeFile_io_write_2(p, b, l) fwrite((b), 1, (l), (FILE*)(p))
32 #define file_NativeFile_NativeFile_io_close_0(self) fclose((FILE*)(self))
33
34 #define file_NativeFileCapable_NativeFileCapable_io_open_read_1(p0) fopen((p0), "r")
35
36 #define file_NativeFileCapable_NativeFileCapable_io_open_write_1(p0) fopen((p0), "w")
37 #define file_NativeFileCapable_NativeFileCapable_native_stdin_0() stdin
38 #define file_NativeFileCapable_NativeFileCapable_native_stdout_0() stdout
39 #define file_NativeFileCapable_NativeFileCapable_native_stderr_0() stderr
40 #define file_FileStat_FileStat_mode_0(self) (((struct stat*)self)->st_mode)
41 #define file_FileStat_FileStat_atime_0(self) (((struct stat*)self)->st_atime)
42 #define file_FileStat_FileStat_ctime_0(self) (((struct stat*)self)->st_ctime)
43 #define file_FileStat_FileStat_mtime_0(self) (((struct stat*)self)->st_mtime)
44 #define file_FileStat_FileStat_size_0(self) (((struct stat*)self)->st_size)
45 #define file_Sys_Sys_buffer_mode_full_0(self) _IOFBF
46 #define file_Sys_Sys_buffer_mode_line_0(self) _IOLBF
47 #define file_Sys_Sys_buffer_mode_none_0(self) _IONBF
48
49 #define string_NativeString_NativeString_file_mkdir_0(p) (!mkdir(p, 0777))
50 #define string_NativeString_NativeString_file_getcwd_0(p) (getcwd(NULL, 0))
51 #define string_NativeString_NativeString_file_chdir_0(p) (!chdir(p))
52 #define file_NativeString_realpath(p) (realpath(p, NULL))
53
54 #define file_stdin_poll_in(self) file_stdin_poll_in_()
55 int file_stdin_poll_in_(void);
56 #endif
57