Mercurial > ~darius > hgwebdir.cgi > paradise_server
comparison pped/file.c @ 2:2719a89505ba
First entry of Paradise Server 2.9 patch 10 Beta
author | darius |
---|---|
date | Sat, 06 Dec 1997 04:37:01 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:4d6502ffaa5e | 2:2719a89505ba |
---|---|
1 /* | |
2 * file.c | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <string.h> | |
7 | |
8 #ifdef SYSV | |
9 #include <fcntl.h> | |
10 #else | |
11 #include <sys/file.h> | |
12 #endif | |
13 | |
14 #include <struct.h> | |
15 #include "common.h" | |
16 #include "db.h" | |
17 #include "main.h" | |
18 #include "file.h" | |
19 #include "data.h" | |
20 | |
21 | |
22 int ReadIt(char *fn) | |
23 { | |
24 struct statentry player; | |
25 int plfd; | |
26 | |
27 initDB(); /* set up linked-list */ | |
28 | |
29 plfd = open(fn, O_RDONLY, 0644); | |
30 if(plfd < 0) { | |
31 err_sys("Could not open %s for read", fn); | |
32 return 1; | |
33 } | |
34 | |
35 while (read(plfd, (void *)&player, sizeof(struct statentry)) == | |
36 sizeof(struct statentry)) | |
37 addDB(&player); /* add to list */ | |
38 | |
39 close(plfd); | |
40 return 0; | |
41 } | |
42 | |
43 int SaveIt(char *fn) | |
44 { | |
45 struct plnode *p; | |
46 int plfd, cc; | |
47 | |
48 plfd = open(fn, O_CREAT | O_TRUNC | O_WRONLY, 0600); | |
49 if(plfd < 0) { | |
50 err_sys("Could not open %s for write", fn); | |
51 return 1; | |
52 } | |
53 | |
54 p = firstEnt; | |
55 while(p) { | |
56 cc = write(plfd, (void *)(&p->player), (int)sizeof(struct statentry)); | |
57 if(cc != (int)sizeof(struct statentry)) { | |
58 err_sys("Write error"); | |
59 return 1; | |
60 } | |
61 p = p->next; | |
62 } | |
63 return 0; | |
64 } | |
65 | |
66 int DoSave(int mode) | |
67 { | |
68 char name[100], *c; | |
69 extern char *playerFile; | |
70 | |
71 printf("Warning! Do not write over the server .players file if there\nare people logged in!\n"); | |
72 printf("Enter filename, or press return to cancel\n"); | |
73 printf(" -->"); fflush(stdout); | |
74 | |
75 if(!fgets(name, 100, stdin)) { | |
76 err_sys("fgets fail (in DoSave)"); | |
77 return 1; | |
78 } | |
79 if(c = strrchr(name, '\n')) | |
80 *c = (char)0; | |
81 | |
82 if(!name || !(*name)) return 1; | |
83 | |
84 if(SaveIt(name)) { | |
85 Report(""); | |
86 return 1; | |
87 } | |
88 | |
89 ClearChanged(); | |
90 Report("Player database saved."); | |
91 return(0); | |
92 } | |
93 | |
94 int DoLoad(int mode) | |
95 { | |
96 } | |
97 |