(sh-mode-map): Remove bindings for
[emacs.git] / lib-src / test-distrib.c
blobc2e9a2510edd5385109c80d5b9dc7f8a8fc79f60
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
5 #include <stdio.h>
7 #ifdef HAVE_UNISTD_H
8 #include <unistd.h>
9 #endif
11 #ifndef O_RDONLY
12 #define O_RDONLY 0
13 #endif
15 /* Break string in two parts to avoid buggy C compilers that ignore characters
16 after nulls in strings. */
18 char string1[] = "Testing distribution of nonprinting chars:\n\
19 Should be 0177: \177 Should be 0377: \377 Should be 0212: \212.\n\
20 Should be 0000: ";
22 char string2[] = ".\n\
23 This file is read by the `test-distribution' program.\n\
24 If you change it, you will make that program fail.\n";
26 char buf[300];
28 /* Like `read' but keeps trying until it gets SIZE bytes or reaches eof. */
29 int
30 cool_read (fd, buf, size)
31 int fd;
32 char *buf;
33 int size;
35 int num, sofar = 0;
37 while (1)
39 if ((num = read (fd, buf + sofar, size - sofar)) == 0)
40 return sofar;
41 else if (num < 0)
42 return num;
43 sofar += num;
47 int
48 main (argc, argv)
49 int argc;
50 char **argv;
52 int fd;
54 if (argc != 2)
56 fprintf (stderr, "Usage: %s testfile\n", argv[0]);
57 exit (2);
59 fd = open (argv[1], O_RDONLY);
60 if (fd < 0)
62 perror (argv[1]);
63 exit (2);
65 if (cool_read (fd, buf, sizeof string1) != sizeof string1 ||
66 strcmp (buf, string1) ||
67 cool_read (fd, buf, sizeof string2) != sizeof string2 - 1 ||
68 strncmp (buf, string2, sizeof string2 - 1))
70 fprintf (stderr, "Data in file `%s' has been damaged.\n\
71 Most likely this means that many nonprinting characters\n\
72 have been corrupted in the files of Emacs, and it will not work.\n",
73 argv[1]);
74 exit (2);
76 close (fd);
77 #ifdef VMS
78 exit (1); /* On VMS, success is 1. */
79 #endif
80 return (0);