mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
Add isc_file_progname(), with trivial POSIX implementation, and
call it from main(). A separate WIN32 implementation will be needed.
This commit is contained in:
parent
8fbd23c0aa
commit
c3ebcedbe5
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: main.c,v 1.108 2001/05/08 03:42:28 gson Exp $ */
|
||||
/* $Id: main.c,v 1.109 2001/05/08 19:47:53 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include <isc/app.h>
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/entropy.h>
|
||||
#include <isc/file.h>
|
||||
#include <isc/os.h>
|
||||
#include <isc/platform.h>
|
||||
#include <isc/resource.h>
|
||||
@ -62,7 +63,7 @@
|
||||
/* #include "xxdb.h" */
|
||||
|
||||
static isc_boolean_t want_stats = ISC_FALSE;
|
||||
static const char * program_name = "named";
|
||||
static char program_name[256] = "named";
|
||||
static char saved_command_line[512];
|
||||
|
||||
void
|
||||
@ -264,21 +265,9 @@ static void
|
||||
parse_command_line(int argc, char *argv[]) {
|
||||
int ch;
|
||||
int port;
|
||||
char *s;
|
||||
|
||||
save_command_line(argc, argv);
|
||||
|
||||
/*
|
||||
* See if we should run as lwresd.
|
||||
*/
|
||||
s = strrchr(argv[0], '/');
|
||||
if (s == NULL)
|
||||
s = argv[0];
|
||||
else
|
||||
s++;
|
||||
if (strcmp(s, "lwresd") == 0)
|
||||
ns_g_lwresdonly = ISC_TRUE;
|
||||
|
||||
isc_commandline_errprint = ISC_FALSE;
|
||||
while ((ch = isc_commandline_parse(argc, argv,
|
||||
"c:C:d:fgi:ln:N:p:P:st:u:vx:")) !=
|
||||
@ -517,7 +506,13 @@ int
|
||||
main(int argc, char *argv[]) {
|
||||
isc_result_t result;
|
||||
|
||||
program_name = argv[0];
|
||||
result = isc_file_progname(argv[0], program_name, sizeof(program_name));
|
||||
if (result != ISC_R_SUCCESS)
|
||||
ns_main_earlyfatal("program name too long");
|
||||
|
||||
if (strcmp(program_name, "lwresd") == 0)
|
||||
ns_g_lwresdonly = ISC_TRUE;
|
||||
|
||||
isc_assertion_setcallback(assertion_failed);
|
||||
isc_error_setfatal(library_fatal_error);
|
||||
isc_error_setunexpected(library_unexpected_error);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: file.h,v 1.17 2001/05/05 02:47:19 bwelling Exp $ */
|
||||
/* $Id: file.h,v 1.18 2001/05/08 19:47:54 gson Exp $ */
|
||||
|
||||
#ifndef ISC_FILE_H
|
||||
#define ISC_FILE_H 1
|
||||
@ -183,6 +183,22 @@ isc_file_basename(const char *filename);
|
||||
* Return the final component of the path in the file name.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_file_progname(const char *filename, char *buf, size_t buflen);
|
||||
/*
|
||||
* Given an operating system specific file name "filename"
|
||||
* referring to a program, return the canonical program name.
|
||||
* Any directory prefix or executable file name extension (if
|
||||
* used on the OS in case) is stripped. On systems where program
|
||||
* names are case insensitive, the name is canonicalized to all
|
||||
* lower case. The name is written to 'buf', an array of 'buflen'
|
||||
* chars, and null terminated.
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS
|
||||
* ISC_R_NOSPACE The name did not fit in 'buf'.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_file_template(const char *path, const char *templet, char *buf,
|
||||
size_t buflen);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: file.c,v 1.32 2001/05/05 02:47:21 bwelling Exp $ */
|
||||
/* $Id: file.c,v 1.33 2001/05/08 19:47:55 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -244,3 +244,13 @@ isc_file_basename(const char *filename) {
|
||||
return (filename);
|
||||
return (s + 1);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_file_progname(const char *filename, char *buf, size_t buflen) {
|
||||
const char *base = isc_file_basename(filename);
|
||||
size_t len = strlen(base) + 1;
|
||||
if (len > buflen)
|
||||
return (ISC_R_NOSPACE);
|
||||
memcpy(buf, base, len);
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user