FreeCalypso > hg > freecalypso-tools
view rvinterf/etmsync/l1tmops.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 | 4469d73bbc60 |
children | 4694c7686ccd |
line wrap: on
line source
/* * In this module we implement the functions that access the L1TM operations * which we are going to use in fc-tmsync and fc-readcal. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "pktmux.h" #include "tm3.h" #include "l1tm.h" #include "exitcodes.h" extern u_char rvi_msg[]; extern int rvi_msg_len; do_tms(arg) { u_char cmdpkt[5]; cmdpkt[1] = TM_MODE_SET; cmdpkt[2] = arg; cmdpkt[3] = arg >> 8; etm_pkt_exch(cmdpkt, 3); if (rvi_msg[3]) { fprintf(stderr, "target error %u in response to tms\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len != 5) { fprintf(stderr, "target error: tms response wrong length\n"); return(ERROR_TARGET); } return(0); } do_rfpr(index, retp) u_short *retp; { u_char cmdpkt[5]; cmdpkt[1] = RF_PARAM_READ; cmdpkt[2] = index; cmdpkt[3] = index >> 8; etm_pkt_exch(cmdpkt, 3); if (rvi_msg[3]) { fprintf(stderr, "target error %u in response to rfpr\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len != 8) { fprintf(stderr, "target error: rfpr response wrong length\n"); return(ERROR_TARGET); } if (rvi_msg[4] != index) { fprintf(stderr, "target error: rfpr response wrong index\n"); return(ERROR_TARGET); } *retp = rvi_msg[5] | (rvi_msg[6] << 8); return(0); } do_rfpw(index, value) { u_char cmdpkt[7]; cmdpkt[1] = RF_PARAM_WRITE; cmdpkt[2] = index; cmdpkt[3] = index >> 8; cmdpkt[4] = value; cmdpkt[5] = value >> 8; etm_pkt_exch(cmdpkt, 5); if (rvi_msg[3]) { fprintf(stderr, "target error %u in response to rfpw\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len != 6) { fprintf(stderr, "target error: rfpw response wrong length\n"); return(ERROR_TARGET); } if (rvi_msg[4] != index) { fprintf(stderr, "target error: rfpw response wrong index\n"); return(ERROR_TARGET); } return(0); } do_rftr(index, table, size) u_char *table; { u_char cmdpkt[4]; cmdpkt[1] = RF_TABLE_READ; cmdpkt[2] = index; etm_pkt_exch(cmdpkt, 2); if (rvi_msg[3]) { fprintf(stderr, "target error %u in response to rftr\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len < size + 6) { fprintf(stderr, "target error: rftr response too short\n"); return(ERROR_TARGET); } if (rvi_msg[4] != index) { fprintf(stderr, "target error: rftr response wrong index\n"); return(ERROR_TARGET); } bcopy(rvi_msg + 5, table, size); return(0); } do_ttr(index, buf) u_char *buf; { u_char cmdpkt[4]; cmdpkt[1] = TX_TEMPLATE_READ; cmdpkt[2] = index; etm_pkt_exch(cmdpkt, 2); if (rvi_msg[3]) { fprintf(stderr, "target error %u in response to ttr\n", rvi_msg[3]); return(ERROR_TARGET); } if (rvi_msg_len != 38) { fprintf(stderr, "target error: ttr response wrong length\n"); return(ERROR_TARGET); } if (rvi_msg[4] != index) { fprintf(stderr, "target error: ttr response wrong index\n"); return(ERROR_TARGET); } bcopy(rvi_msg + 5, buf, 32); return(0); }