misc/vim: inform the user when no results are found
[nit.git] / c_src / file_nit.c
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2 *
3 * Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 * Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
5 * Copyright 2008 Jean-Sébastien Gélinas <calestar@gmail.com>
6 *
7 * This file is free software, which comes along with NIT. This software is
8 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
11 * is kept unaltered, and a notification of the changes is added.
12 * You are allowed to redistribute it and sell it, alone or is a part of
13 * another product.
14 */
15
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20 #include <sys/types.h>
21 #include <string.h>
22 #include <dirent.h>
23 #include <poll.h>
24
25 #include "file_nit.h"
26
27 int string_NativeString_NativeString_file_exists_0(char *f){
28 FILE *hdl = fopen(f,"r");
29 if(hdl != NULL){
30 fclose(hdl);
31 }
32 return hdl != NULL;
33 }
34
35 void *to_nit_file_stat(struct stat* st){
36 struct stat* stat_element;
37 stat_element = malloc(sizeof(struct stat));
38 return memcpy(stat_element, st, sizeof(struct stat));
39 }
40
41 void *string_NativeString_NativeString_file_stat_0(char *f){
42 struct stat buff;
43 if(stat(f, &buff) != -1)
44 return to_nit_file_stat(&buff);
45 return 0;
46 }
47
48 void *file_NativeFile_NativeFile_file_stat_0(FILE *f){
49 struct stat buff;
50 if(fstat(fileno(f), &buff) != -1)
51 return to_nit_file_stat(&buff);
52 return 0;
53 }
54
55 extern int string_NativeString_NativeString_file_delete_0(char *f){
56 return (remove(f) == 0);
57 }
58
59 int file_stdin_poll_in_(void) {
60 struct pollfd fd = {0, POLLIN, 0};
61 int res = poll(&fd, 1, 0);
62 if (res == -1) {
63 perror("Error poll stdin");
64 exit(EXIT_FAILURE);
65 }
66 return res > 0;
67 }
68
69 FILE* file_int_fdtostream(int fd, char* mode){
70 return fdopen(fd, mode);
71 }
72
73 int file_NativeFile_NativeFile_set_buffering_type_0(FILE* f, int buf_sz, int mode){
74 return setvbuf(f, NULL, mode, buf_sz);
75 }