SURFEX v8.1
General documentation of Surfex
fi_libc.c
Go to the documentation of this file.
1 #include "fi_libc.h"
2 
3 #include <stdio.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <sys/time.h>
8 #include <string.h>
9 #include <errno.h>
10 
11 
12 void fi_gettimeofday_ (double * t)
13 {
14  struct timeval tv;
15  gettimeofday (&tv, NULL);
16  *t = (double)(tv.tv_sec) + (double)(tv.tv_usec) / 1e6;
17 }
18 
19 void fi_fopen_ (FILE ** fpp, const char * path, const char * mode, int path_len, int mode_len)
20 {
21  char path1[path_len+1];
22  char mode1[mode_len+1];
23  FILE * fp;
24  int i;
25 
26  for (i = path_len; (path[i-1] == ' ') && (i > 0); i--);
27  path_len = i;
28 
29  for (i = 0; i < path_len; i++)
30  path1[i] = path[i];
31  path1[path_len] = '\0';
32 
33  for (i = mode_len; (mode[i-1] == ' ') && (i > 0); i--);
34  mode_len = i;
35 
36  for (i = 0; i < mode_len; i++)
37  mode1[i] = mode[i];
38  mode1[mode_len] = '\0';
39 
40  fp = fopen (path1, mode1);
41 
42  *fpp = fp;
43 }
44 
45 void fi_fclose_ (fi_integer4 * err, FILE ** fpp)
46 {
47  *err = fclose (*fpp);
48 }
49 
50 void fi_fread_ (fi_integer8 * err, void * ptr, fi_integer8 * size, fi_integer8 * nmemb, FILE ** fpp)
51 {
52  *err = fread (ptr, *size, *nmemb, *fpp);
53 }
54 
55 void fi_fwrite_ (fi_integer8 * err, const void * ptr, fi_integer8 * size, fi_integer8 * nmemb, FILE ** fpp)
56 {
57  *err = fwrite (ptr, *size, *nmemb, *fpp);
58 }
59 
60 void fi_fseek_ (fi_integer4 * err, FILE ** fpp, fi_integer8 * offset, fi_integer4 * whence)
61 {
62  *err = fseek (*fpp, *offset, *whence);
63 }
64 
65 void fi_fileno_ (fi_integer4 * err, FILE ** fpp)
66 {
67  *err = fileno (*fpp);
68 }
69 
70 void fi_ftell_ (fi_integer8 * err, FILE ** fpp)
71 {
72  *err = ftell (*fpp);
73 }
74 
75 void fi_fstat_ (fi_integer4 *err, fi_integer4 *fd, fi_integer8 buf[13])
76 {
77  struct stat buf1;
78  *err = fstat (*fd, &buf1);
79 
80  buf[0] = buf1.st_dev;
81  buf[1] = buf1.st_ino;
82  buf[2] = buf1.st_mode;
83  buf[3] = buf1.st_nlink;
84  buf[4] = buf1.st_uid;
85  buf[5] = buf1.st_gid;
86  buf[6] = buf1.st_rdev;
87  buf[7] = buf1.st_size;
88  buf[8] = buf1.st_blksize;
89  buf[9] = buf1.st_blocks;
90  buf[10] = buf1.st_atime;
91  buf[11] = buf1.st_mtime;
92  buf[12] = buf1.st_ctime;
93 }
94 
96 {
97  *err = ftruncate (*fd, *length);
98 }
99 
100 void fi_mkdir_ (const char * path, int path_len)
101 {
102  char p[path_len+1];
103  memcpy (p, path, path_len);
104  p[path_len] = '\0';
105  mkdir (p, 0755);
106 }
107 
108 void fi_chdir_ (fi_integer4 * ierr, const char * path, int path_len)
109 {
110  char p[path_len+1];
111  memcpy (p, path, path_len);
112  p[path_len] = '\0';
113  *ierr = chdir (p);
114 }
115 
116 void fi_rename_ (fi_integer4 * ierr, const char * oldpath, const char * newpath, int oldpath_len, int newpath_len)
117 {
118  char _oldpath[oldpath_len+1];
119  char _newpath[newpath_len+1];
120 
121  strncpy (_oldpath, oldpath, oldpath_len); _oldpath[oldpath_len] = '\0';
122  strncpy (_newpath, newpath, newpath_len); _newpath[newpath_len] = '\0';
123 
124  *ierr = rename (_oldpath, _newpath);
125 }
126 
127 void fi_fflush_ (fi_integer4* err, FILE **fpp)
128 {
129  *err = fflush (*fpp);
130 }
131 
133 {
134  *err = errno;
135 }
136 
137 void fi_unlink_ (fi_integer4* err, const char * path, int path_len)
138 {
139  char p[path_len+1];
140  memcpy (p, path, path_len);
141  p[path_len] = '\0';
142  *err = unlink (p);
143 }
144 
static long size
Definition: bytes_io.c:262
void fi_fseek_(fi_integer4 *err, FILE **fpp, fi_integer8 *offset, fi_integer4 *whence)
Definition: fi_libc.c:60
void fi_fstat_(fi_integer4 *err, fi_integer4 *fd, fi_integer8 buf[13])
Definition: fi_libc.c:75
long long int fi_integer8
Definition: fi_libc.h:7
void fi_chdir_(fi_integer4 *ierr, const char *path, int path_len)
Definition: fi_libc.c:108
void fi_ftell_(fi_integer8 *err, FILE **fpp)
Definition: fi_libc.c:70
void fi_fileno_(fi_integer4 *err, FILE **fpp)
Definition: fi_libc.c:65
void fi_fflush_(fi_integer4 *err, FILE **fpp)
Definition: fi_libc.c:127
void fi_unlink_(fi_integer4 *err, const char *path, int path_len)
Definition: fi_libc.c:137
FILE * fp
Definition: opfla_perfmon.c:24
void fi_fread_(fi_integer8 *err, void *ptr, fi_integer8 *size, fi_integer8 *nmemb, FILE **fpp)
Definition: fi_libc.c:50
void fi_rename_(fi_integer4 *ierr, const char *oldpath, const char *newpath, int oldpath_len, int newpath_len)
Definition: fi_libc.c:116
void fi_mkdir_(const char *path, int path_len)
Definition: fi_libc.c:100
void fi_fwrite_(fi_integer8 *err, const void *ptr, fi_integer8 *size, fi_integer8 *nmemb, FILE **fpp)
Definition: fi_libc.c:55
void fi_fclose_(fi_integer4 *err, FILE **fpp)
Definition: fi_libc.c:45
void fi_ftruncate_(fi_integer4 *err, fi_integer4 *fd, fi_integer8 *length)
Definition: fi_libc.c:95
int fi_integer4
Definition: fi_libc.h:6
void fi_fopen_(FILE **fpp, const char *path, const char *mode, int path_len, int mode_len)
Definition: fi_libc.c:19
void fi_gettimeofday_(double *t)
Definition: fi_libc.c:12
void fi_errno_(fi_integer4 *err)
Definition: fi_libc.c:132
subroutine t(CDPREF, CDSUFF, KCODPA, LDNIVA, PMULTI)
Definition: faicor.F90:567