Mapper
is_file_closed.c
Go to the documentation of this file.
1 
2 #define _POSIX_SOURCE
3 #include <stdio.h>
4 #include <sys/stat.h>
5 char filename[200];
6 int how_old;
7 
8 struct stat buf;
9 extern int DEBUG, VERBOSE;
10 
12 {
13  /*
14  filename = file name to look at
15  how_old = number of seconds to wait before opening file
16  */
17 
18  struct stat buf;
19  long size_1, size_2, current_time;
20  int time_space;
21 
22  /* Ver 1.0 JUL 95 Dave Brandon
23 
24  An assumption is made that while files are opened
25  they are being written too, and are growing. This
26  is a fair assumption for files being written remotely
27  via RCP, or CP. If there is an error on getting the status
28  through 'stat' the return is assumed to be opened.
29  The tolerance level can be set higher to be more
30  liberal on busy systems.
31 
32  return values 0 = file exists and is closed
33  1 = file either exists and is too young
34  or does not exist for some reason
35  or there is a system problem
36 
37  VER 1.1 SEP 95 DGB
38  Add capability to wait until the file is at least x minutes
39  old, where x is a user defined tolerance. how_old is the
40  variable name, and is in units of minutes.
41 
42  VER 1.2 DEC 18 1999 dgb
43  Scrapped the check for files growing.... Just check the age of the
44  file. It is now checked in seconds, instead of minutes.
45  */
46 
47 
48  time_space = 1;
49 
50 
51  /* get size and time of file */
52  if ( stat(filename,&buf) == -1 )
53  return(1);
54  size_1 = buf.st_size;
55 
56 
57  /* see if file is old enough to look at */
58  current_time = time(NULL);
59 printf("\n current =%ld",current_time);
60 printf("\n buff.st =%ld",buf.st_ctime);
61 
62  if ( current_time - buf.st_ctime < time_space * how_old )
63  {
64  return(1);
65  }
66 
67  return(0);
68 
69 }
70 
int DEBUG
Definition: shef_structs.h:248
struct stat buf
Definition: is_file_closed.c:8
char filename[200]
Definition: is_file_closed.c:5
int VERBOSE
Definition: is_file_closed.c:9
int how_old
Definition: is_file_closed.c:6
int is_file_closed(char filename[], int how_old)
printf("fbuf is %s\n", fbuf)