1 /* ============================================================================
2 * Copyright (C) 1999-2000 Angus Mackay. All rights reserved;
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
10 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
11 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
13 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
14 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
15 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
16 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
17 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
19 * ============================================================================
37 # include <sys/stat.h>
45 #include <config/autoconf.h>
48 #include <cache_file.h>
53 # define error_string strerror(errno)
54 #elif HAVE_SYS_ERRLIST
55 extern const char *const sys_errlist[];
57 # define error_string (sys_errlist[errno])
59 # define error_string "error message not found"
62 static void sync_file(void)
64 #ifdef CONFIG_USER_FLATFSD_FLATFSD
65 system("exec flatfsd -s");
69 int read_cache_file(char *file, time_t *date, char **ipaddr)
88 if(stat(file, &st) != 0)
98 if((fp=fopen(file, "r")) == NULL)
103 if(fgets(buf, BUFSIZ, fp) != NULL)
108 while(*p != '\0' && *p != '\r' && *p != '\n') { p++; }
111 /* find the first comma */
113 while(*p != '\0' && *p != ',') { p++; }
125 *date = strtoul(datestr, NULL, 10);
126 *ipaddr = strdup(ipstr);
140 if(fp) { fclose(fp); }
144 int write_cache_file(char *file, time_t date, char *ipaddr)
148 if((fp=fopen(file, "w")) == NULL)
153 fprintf(fp, "%ld,%s\n", date, ipaddr);
162 int write_block_file(char *file)
166 if((fp=fopen(file, "w")) == NULL)