X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/file_nit.c b/lib/standard/file_nit.c index cf14118..f6a6987 100644 --- a/lib/standard/file_nit.c +++ b/lib/standard/file_nit.c @@ -2,6 +2,7 @@ * * Copyright 2004-2008 Jean Privat * Copyright 2008 Floréal Morandat + * Copyright 2008 Jean-Sébastien Gélinas * * This file is free software, which comes along with NIT. This software is * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; @@ -12,13 +13,16 @@ * another product. */ -#define _POSIX_C_SOURCE 1 #include #include #include #include #include #include +#include +#include + +#include "file_nit.h" int string_NativeString_NativeString_file_exists_0(char *f){ FILE *hdl = fopen(f,"r"); @@ -28,22 +32,44 @@ int string_NativeString_NativeString_file_exists_0(char *f){ return hdl != NULL; } -static int to_nit_file_stat(struct stat* st){ +void *to_nit_file_stat(struct stat* st){ struct stat* stat_element; stat_element = malloc(sizeof(struct stat)); - return (int)memcpy(stat_element, st, sizeof(struct stat)); + return memcpy(stat_element, st, sizeof(struct stat)); } -int string_NativeString_NativeString_file_stat_0(char *f){ +void *string_NativeString_NativeString_file_stat_0(char *f){ struct stat buff; if(stat(f, &buff) != -1) return to_nit_file_stat(&buff); return 0; } -int file_NativeFile_NativeFile_file_stat_0(FILE *f){ +void *file_NativeFile_NativeFile_file_stat_0(FILE *f){ struct stat buff; if(fstat(fileno(f), &buff) != -1) return to_nit_file_stat(&buff); return 0; } + +extern int string_NativeString_NativeString_file_delete_0(char *f){ + return (remove(f) == 0); +} + +int file_stdin_poll_in_(void) { + struct pollfd fd = {0, POLLIN, 0}; + int res = poll(&fd, 1, 0); + if (res == -1) { + perror("Error poll stdin"); + exit(EXIT_FAILURE); + } + return res > 0; +} + +FILE* file_int_fdtostream(int fd, char* mode){ + return fdopen(fd, mode); +} + +int file_NativeFile_NativeFile_set_buffering_type_0(FILE* f, int buf_sz, int mode){ + return setvbuf(f, NULL, mode, buf_sz); +}