annotate uptools/atcmd/smsend_concat.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents 076d533f840d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
370
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the messy code for automatic generation and
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * increment of concat SMS reference numbers.
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/param.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/file.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/time.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <ctype.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <unistd.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../../rvinterf/include/exitcodes.h"
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static int
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 initial_seed()
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct timeval tv;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char refno, *cp, *endp;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 gettimeofday(&tv, 0);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cp = (u_char *) &tv;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 endp = cp + sizeof(struct timeval);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 refno = 0;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 while (cp < endp)
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 refno ^= *cp++;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return refno;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 get_concsms_refno_from_host_fs()
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 char *homedir, statefile[MAXPATHLEN];
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 int fd, cc;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 char buf[6];
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 u_char refno;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 homedir = getenv("HOME");
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (!homedir) {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(stderr,
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 "error: no HOME= defined, needed for concat SMS refno\n");
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 exit(ERROR_UNIX);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 sprintf(statefile, "%s/.concat_sms_refno", homedir);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fd = open(statefile, O_RDWR|O_CREAT, 0666);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (fd < 0) {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 perror(statefile);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(ERROR_UNIX);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 cc = read(fd, buf, 5);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (cc == 5 && buf[0] == '0' && buf[1] == 'x' && isxdigit(buf[2]) &&
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 isxdigit(buf[3]) && buf[4] == '\n')
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 refno = strtoul(buf, 0, 16) + 1;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 else
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 refno = initial_seed();
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 sprintf(buf, "0x%02X\n", refno);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 lseek(fd, 0, SEEK_SET);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 write(fd, buf, 5);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 close(fd);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return refno;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }