Deleted Added
full compact
readfilemap.c (104349) readfilemap.c (178848)
1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
3*/
4
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
8#include <stdlib.h>
9#include <stdio.h>
10
1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
3*/
4
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
8#include <stdlib.h>
9#include <stdio.h>
10
11#ifdef __WATCOMC__
12#ifndef __LINUX__
13#include <io.h>
14#else
15#include <unistd.h>
16#endif
17#endif
18
19#ifdef __BEOS__
20#include <unistd.h>
21#endif
22
11#ifndef S_ISREG
12#ifndef S_IFREG
13#define S_IFREG _S_IFREG
14#endif
15#ifndef S_IFMT
16#define S_IFMT _S_IFMT
17#endif
18#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)

--- 29 unchanged lines hidden (view full) ---

48 perror(name);
49 return 0;
50 }
51 if (!S_ISREG(sb.st_mode)) {
52 fprintf(stderr, "%s: not a regular file\n", name);
53 return 0;
54 }
55 nbytes = sb.st_size;
23#ifndef S_ISREG
24#ifndef S_IFREG
25#define S_IFREG _S_IFREG
26#endif
27#ifndef S_IFMT
28#define S_IFMT _S_IFMT
29#endif
30#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)

--- 29 unchanged lines hidden (view full) ---

60 perror(name);
61 return 0;
62 }
63 if (!S_ISREG(sb.st_mode)) {
64 fprintf(stderr, "%s: not a regular file\n", name);
65 return 0;
66 }
67 nbytes = sb.st_size;
68 /* malloc will return NULL with nbytes == 0, handle files with size 0 */
69 if (nbytes == 0) {
70 static const char c = '\0';
71 processor(&c, 0, name, arg);
72 close(fd);
73 return 1;
74 }
56 p = malloc(nbytes);
57 if (!p) {
58 fprintf(stderr, "%s: out of memory\n", name);
75 p = malloc(nbytes);
76 if (!p) {
77 fprintf(stderr, "%s: out of memory\n", name);
78 close(fd);
59 return 0;
60 }
61 n = read(fd, p, nbytes);
62 if (n < 0) {
63 perror(name);
79 return 0;
80 }
81 n = read(fd, p, nbytes);
82 if (n < 0) {
83 perror(name);
84 free(p);
64 close(fd);
65 return 0;
66 }
67 if (n != nbytes) {
68 fprintf(stderr, "%s: read unexpected number of bytes\n", name);
85 close(fd);
86 return 0;
87 }
88 if (n != nbytes) {
89 fprintf(stderr, "%s: read unexpected number of bytes\n", name);
90 free(p);
69 close(fd);
70 return 0;
71 }
72 processor(p, nbytes, name, arg);
73 free(p);
74 close(fd);
75 return 1;
76}
91 close(fd);
92 return 0;
93 }
94 processor(p, nbytes, name, arg);
95 free(p);
96 close(fd);
97 return 1;
98}