version 1.110, 2023/03/30 07:26:15 |
version 1.111, 2023/03/30 19:00:02 |
|
|
* the terminal driver in particular), accepts a suffix to be appended |
* the terminal driver in particular), accepts a suffix to be appended |
* to the startup file name. |
* to the startup file name. |
*/ |
*/ |
char * |
FILE * |
startupfile(char *suffix, char *conffile) |
startupfile(char *suffix, char *conffile, char *path, size_t len) |
{ |
{ |
static char file[NFILEN]; |
FILE *ffp; |
char *home; |
char *home; |
int ret; |
int ret; |
|
|
|
|
goto nohome; |
goto nohome; |
|
|
if (conffile != NULL) { |
if (conffile != NULL) { |
(void)strlcpy(file, conffile, NFILEN); |
(void)strlcpy(path, conffile, len); |
} else if (suffix == NULL) { |
} else if (suffix == NULL) { |
ret = snprintf(file, sizeof(file), _PATH_MG_STARTUP, home); |
ret = snprintf(path, len, _PATH_MG_STARTUP, home); |
if (ret < 0 || ret >= sizeof(file)) |
if (ret < 0 || ret >= len) |
return (NULL); |
return (NULL); |
} else { |
} else { |
ret = snprintf(file, sizeof(file), _PATH_MG_TERM, home, suffix); |
ret = snprintf(path, len, _PATH_MG_TERM, home, suffix); |
if (ret < 0 || ret >= sizeof(file)) |
if (ret < 0 || ret >= len) |
return (NULL); |
return (NULL); |
} |
} |
|
|
if (access(file, R_OK) == 0) |
ret = ffropen(&ffp, path, NULL); |
return (file); |
if (ret == FIOSUC) |
|
return (ffp); |
|
if (ret == FIODIR) |
|
(void)ffclose(ffp, NULL); |
nohome: |
nohome: |
#ifdef STARTUPFILE |
#ifdef STARTUPFILE |
if (suffix == NULL) { |
if (suffix == NULL) { |
ret = snprintf(file, sizeof(file), "%s", STARTUPFILE); |
ret = snprintf(path, len, "%s", STARTUPFILE); |
if (ret < 0 || ret >= sizeof(file)) |
if (ret < 0 || ret >= len) |
return (NULL); |
return (NULL); |
} else { |
} else { |
ret = snprintf(file, sizeof(file), "%s%s", STARTUPFILE, |
ret = snprintf(path, len, "%s%s", STARTUPFILE, |
suffix); |
suffix); |
if (ret < 0 || ret >= sizeof(file)) |
if (ret < 0 || ret >= len) |
return (NULL); |
return (NULL); |
} |
} |
|
|
if (access(file, R_OK) == 0) |
ret = ffropen(&ffp, path, NULL); |
return (file); |
if (ret == FIOSUC) |
|
return (ffp); |
|
if (ret == FIODIR) |
|
(void)ffclose(ffp, NULL); |
#endif /* STARTUPFILE */ |
#endif /* STARTUPFILE */ |
return (NULL); |
return (NULL); |
} |
} |