FreeCalypso > hg > freecalypso-tools
view libpwon/readconf.c @ 964:a96cb97b66a2
ringtools/imy: fix duplicate definition of tdma_durations[]
The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>,
although the present fix is slightly different from the contributed
patch: because main.c doesn't need this tdma_durations[] array
at all, let's simply remove the reference to this array from main.c
rather than turn it into an extern.
I no longer remember my original thought flow that resulted (by mistake)
in tdma_durations[] being multiply defined in main.c and durations.c.
My intent might have been to define all globals in main.c and have
the reference in durations.c be an extern - and I missed that extern -
but without clear memory, I have no certainty. In any case, having
this data array defined in the same module that fills it (durations.c)
is sensible, so let's make it the new way.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 31 Aug 2023 19:38:18 +0000 |
parents | ab54957dbe35 |
children |
line wrap: on
line source
#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> static char conf_file_pathname[] = "/opt/freecalypso/bootctrl.conf"; #define MAX_BOOTCTRL_CONF_LINE 510 char bootctrl_pwon_cmd[MAX_BOOTCTRL_CONF_LINE+1]; int bootctrl_etmoff_mode; find_bootctrl_entry(soughtname) char *soughtname; { FILE *inf; char linebuf[MAX_BOOTCTRL_CONF_LINE+2]; int lineno; char *cp, *np; if (bootctrl_check_duart28c(soughtname)) return(0); if (!strcmp(soughtname, "etmoff")) { bootctrl_etmoff_mode = 1; return(0); } inf = fopen(conf_file_pathname, "r"); if (!inf) { perror(conf_file_pathname); return(-1); } for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { cp = index(linebuf, '\n'); if (!cp) { fprintf(stderr, "%s line %d: too long or missing newline\n", conf_file_pathname, lineno); fclose(inf); return(-1); } *cp = '\0'; for (cp = linebuf; isspace(*cp); cp++) ; if (*cp == '\0' || *cp == '#') continue; for (np = cp; *cp && !isspace(*cp); cp++) ; if (!*cp) { invalid_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", conf_file_pathname, lineno); fclose(inf); return(-1); } *cp++ = '\0'; while (isspace(*cp)) cp++; if (*cp == '\0' || *cp == '#') goto invalid_syntax; if (!strcmp(np, soughtname)) { strcpy(bootctrl_pwon_cmd, cp); fclose(inf); return(0); } } fclose(inf); fprintf(stderr, "error: no \"%s\" entry found in %s\n", soughtname, conf_file_pathname); return(-1); }