FreeCalypso > hg > freecalypso-tools
view rvinterf/asyncshell/tchplay.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 | 971906d7763d |
children |
line wrap: on
line source
/* * TCH uplink play-from-file functionality */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "pktmux.h" #include "tch_feature.h" extern u_char rvi_msg[]; extern int rvi_msg_len; extern void async_msg_output(); static FILE *play_file; static int queued_frames; #define QUEUE_LIMIT 3 static void sync_msgout(msg) char *msg; { printf("%s\n", msg); } static decode_hex_digit(ch) { if (isdigit(ch)) return(ch - '0'); else if (isupper(ch)) return(ch - 'A' + 10); else return(ch - 'a' + 10); } static decode_hex_line(line, bytes) char *line; u_char *bytes; { int i; for (i = 0; i < 33; i++) { if (!isxdigit(line[0]) || !isxdigit(line[1])) return(-1); bytes[i] = (decode_hex_digit(line[0]) << 4) | decode_hex_digit(line[1]); line += 2; } for (; *line; line++) if (!isspace(*line)) return(-1); return(0); } static void fill_uplink(msgout) void (*msgout)(); { char line[80]; u_char sendpkt[35]; int cc; sendpkt[0] = RVT_TCH_HEADER; sendpkt[1] = TCH_ULBITS_REQ; while (queued_frames < QUEUE_LIMIT) { if (!fgets(line, sizeof line, play_file)) { msgout("TCH UL: file play finished"); fclose(play_file); play_file = 0; return; } if (decode_hex_line(line, sendpkt + 2) < 0) { msgout("TCH UL: bad file input, play aborted"); fclose(play_file); play_file = 0; return; } send_pkt_to_target(sendpkt, 35); queued_frames++; } } void tch_ulbits_conf() { if (queued_frames > 0) queued_frames--; if (play_file) fill_uplink(async_msg_output); } static void cmd_tch_play_start(filename) char *filename; { if (play_file) { printf("error: tch play session already in progress\n"); return; } play_file = fopen(filename, "r"); if (!play_file) { perror(filename); return; } printf("Starting TCH UL play from file\n"); tch_rx_control(1); fill_uplink(sync_msgout); } static void cmd_tch_play_stop() { if (!play_file) { printf("error: no tch play session in progress\n"); return; } fclose(play_file); play_file = 0; printf("TCH UL play from file terminated\n"); } void cmd_tch_play(argc, argv) char **argv; { if (argc < 2) { printf("error: too few arguments\n"); return; } if (strcmp(argv[1], "stop")) cmd_tch_play_start(argv[1]); else cmd_tch_play_stop(); } void show_tch_play_status() { printf("TCH UL play from file: %s\n", play_file ? "RUNNING" : "not running"); printf("Outstanding UL frames: %d\n", queued_frames); }