source: trunk/gsdl/packages/mg/lib/filestats.c@ 10853

Last change on this file since 10853 was 439, checked in by sjboddie, 25 years ago

renamed mg-1.3d directory mg

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/**************************************************************************
2 *
3 * filestats.c -- Functions for keeping stats on file accesses
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id: filestats.c 439 1999-08-10 21:23:37Z sjboddie $
21 *
22 **************************************************************************/
23
24
25/*
26 $Log$
27 Revision 1.1 1999/08/10 21:16:48 sjboddie
28 renamed mg-1.3d directory mg
29
30 Revision 1.1 1998/11/17 09:31:54 rjmcnab
31 *** empty log message ***
32
33 * Revision 1.1 1994/08/22 00:24:42 tes
34 * Initial placement under CVS.
35 *
36 */
37
38static char *RCSID = "$Id: filestats.c 439 1999-08-10 21:23:37Z sjboddie $";
39
40#include "sysfuncs.h"
41
42#include "memlib.h"
43#include "filestats.h"
44#include "netorder.h" /* [RPAP - Jan 97: Endian Ordering] */
45
46
47File *
48Fopen (char *name, char *mode, unsigned long magic)
49{
50 FILE *f;
51 File *F;
52 unsigned long m;
53 if (!(f = fopen (name, mode)))
54 return (NULL);
55 if (magic)
56 switch (*mode)
57 {
58 case 'r':
59 fread ((char *) &m, sizeof (m), 1, f);
60 NTOHUL(m); /* [RPAP - Jan 97: Endian Ordering] */
61 if (m != magic)
62 {
63 fclose (f);
64 return (NULL);
65 }
66 break;
67 case 'w':
68 HTONUL(magic); /* [RPAP - Jan 97: Endian Ordering] */
69 fwrite ((char *) &magic, sizeof (magic), 1, f);
70 }
71 if (!(F = Xmalloc (sizeof (File))))
72 {
73 fclose (f);
74 return (NULL);
75 }
76 F->pathname = Xstrdup (name);
77 F->name = strrchr (F->pathname, '/');
78 F->name = F->name ? F->name + 1 : F->pathname;
79 F->f = f;
80 F->Current.NumSeeks = F->Current.NumReads = F->Current.NumBytes = 0;
81 F->Cumulative = F->Current;
82 return (F);
83}
84
85
86int
87Fclose (File * F)
88{
89 int num;
90 if (!F)
91 return (0);
92 num = fclose (F->f);
93 if (F->pathname)
94 Xfree (F->pathname);
95 Xfree (F);
96 return (num);
97}
98
99size_t
100Fread (void *ptr, size_t size, size_t nitems, File * F)
101{
102 int num;
103 num = fread ((char *) ptr, size, nitems, F->f);
104 F->Current.NumReads++;
105 F->Current.NumBytes += num * size;
106 return (num);
107}
108
109int
110Fseek (File * F, long offset, int ptrname)
111{
112 int num;
113 num = fseek (F->f, offset, ptrname);
114 F->Current.NumSeeks++;
115 return (num);
116}
117
118void
119Rewind (File * F)
120{
121 rewind (F->f);
122 F->Current.NumSeeks++;
123}
124
125
126void
127ZeroFileStats (File * F)
128{
129 F->Cumulative.NumSeeks += F->Current.NumSeeks;
130 F->Cumulative.NumReads += F->Current.NumReads;
131 F->Cumulative.NumBytes += F->Current.NumBytes;
132 F->Current.NumSeeks = F->Current.NumReads = F->Current.NumBytes = 0;
133}
Note: See TracBrowser for help on using the repository browser.