1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

mysql_test_run_new.c:

Included header fnmatch.h on Unix
  Changed C++ comments to C comments
  Corrected indentation of code written on Windows
  Split up lines to fit into 80 columns
  Initiated some variables to avoid warnings
  Added __attribute__((unused)) to unused function parameters
  Replace tab characters with space
  Put space after 'for', 'while' etc
  Added value to 'return' from non void function removef()
  On Unix strlwr() was incorrectly declared and a no op,
  replaced it with a macro that does nothing
  Split several statements on the same line
  Other minor changes to conform to coding standard
This commit is contained in:
kent@mysql.com
2004-11-06 14:01:27 +01:00
parent ca355c8a46
commit f9715d06dc
3 changed files with 750 additions and 716 deletions

View File

@ -30,6 +30,7 @@
#ifndef __WIN__ #ifndef __WIN__
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <fnmatch.h>
#else #else
#include <direct.h> #include <direct.h>
#include <stdlib.h> #include <stdlib.h>
@ -52,36 +53,37 @@ extern char **environ;
/****************************************************************************** /******************************************************************************
macros macros
******************************************************************************/ ******************************************************************************/
/****************************************************************************** /******************************************************************************
global variables global variables
******************************************************************************/ ******************************************************************************/
/****************************************************************************** /******************************************************************************
functions functions
******************************************************************************/ ******************************************************************************/
/****************************************************************************** /******************************************************************************
init_args() init_args()
Init an argument list. Init an argument list.
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *al) void init_args(arg_list_t *al)
{ {
ASSERT(al != NULL); ASSERT(al != NULL);
al->argc = 0; al->argc= 0;
al->size = ARG_BUF; al->size= ARG_BUF;
al->argv = malloc(al->size * sizeof(char *)); al->argv= malloc(al->size * sizeof(char *));
ASSERT(al->argv != NULL); ASSERT(al->argv != NULL);
return; return;
@ -89,11 +91,12 @@ void init_args(arg_list_t *al)
/****************************************************************************** /******************************************************************************
add_arg() add_arg()
Add an argument to a list. Add an argument to a list.
******************************************************************************/ ******************************************************************************/
void add_arg(arg_list_t *al, const char *format, ...) void add_arg(arg_list_t *al, const char *format, ...)
{ {
va_list ap; va_list ap;
@ -101,11 +104,11 @@ void add_arg(arg_list_t *al, const char *format, ...)
ASSERT(al != NULL); ASSERT(al != NULL);
// increase size /* increase size */
if (al->argc >= (int)al->size) if (al->argc >= (int)al->size)
{ {
al->size += ARG_BUF; al->size+= ARG_BUF;
al->argv = realloc(al->argv, al->size * sizeof(char *)); al->argv= realloc(al->argv, al->size * sizeof(char *));
ASSERT(al->argv != NULL); ASSERT(al->argv != NULL);
} }
@ -115,7 +118,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
vsprintf(temp, format, ap); vsprintf(temp, format, ap);
va_end(ap); va_end(ap);
al->argv[al->argc] = malloc(strlen(temp)+1); al->argv[al->argc]= malloc(strlen(temp)+1);
ASSERT(al->argv[al->argc] != NULL); ASSERT(al->argv[al->argc] != NULL);
strcpy(al->argv[al->argc], temp); strcpy(al->argv[al->argc], temp);
@ -123,7 +126,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
} }
else else
{ {
al->argv[al->argc] = NULL; al->argv[al->argc]= NULL;
} }
return; return;
@ -131,102 +134,108 @@ void add_arg(arg_list_t *al, const char *format, ...)
/****************************************************************************** /******************************************************************************
free_args() free_args()
Free an argument list. Free an argument list.
******************************************************************************/ ******************************************************************************/
void free_args(arg_list_t *al) void free_args(arg_list_t *al)
{ {
int i; int i;
ASSERT(al != NULL); ASSERT(al != NULL);
for(i = 0; i < al->argc; i++) for (i= 0; i < al->argc; i++)
{ {
ASSERT(al->argv[i] != NULL); ASSERT(al->argv[i] != NULL);
free(al->argv[i]); free(al->argv[i]);
al->argv[i] = NULL; al->argv[i]= NULL;
} }
free(al->argv); free(al->argv);
al->argc = 0; al->argc= 0;
al->argv = NULL; al->argv= NULL;
return; return;
} }
/****************************************************************************** /******************************************************************************
sleep_until_file_deleted() sleep_until_file_deleted()
Sleep until the given file is no longer found. Sleep until the given file is no longer found.
******************************************************************************/ ******************************************************************************/
#ifndef __WIN__ #ifndef __WIN__
int sleep_until_file_deleted(char *pid_file) int sleep_until_file_deleted(char *pid_file)
#else #else
int sleep_until_file_deleted(HANDLE pid_file) int sleep_until_file_deleted(HANDLE pid_file)
#endif #endif
{ {
int err; int err= 0; /* Initiate to supress warning */
#ifndef __WIN__ #ifndef __WIN__
struct stat buf; struct stat buf;
int i; int i;
for(i = 0; (i < TRY_MAX) && (err = !stat(pid_file, &buf)); i++) sleep(1); for (i= 0; (i < TRY_MAX) && (err= !stat(pid_file, &buf)); i++) sleep(1);
if (err != 0) err = errno; if (err != 0) err= errno;
#else #else
err= (WaitForSingleObject(pid_file, TRY_MAX*1000) == WAIT_TIMEOUT); err= (WaitForSingleObject(pid_file, TRY_MAX*1000) == WAIT_TIMEOUT);
#endif #endif
return err; return err;
} }
/****************************************************************************** /******************************************************************************
sleep_until_file_exists() sleep_until_file_exists()
Sleep until the given file exists. Sleep until the given file exists.
******************************************************************************/ ******************************************************************************/
#ifndef __WIN__ #ifndef __WIN__
int sleep_until_file_exists(char *pid_file) int sleep_until_file_exists(char *pid_file)
#else #else
int sleep_until_file_exists(HANDLE pid_file) int sleep_until_file_exists(HANDLE pid_file)
#endif #endif
{ {
int err; int err= 0; /* Initiate to supress warning */
#ifndef __WIN__ #ifndef __WIN__
struct stat buf; struct stat buf;
int i; int i;
for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1); for (i= 0; (i < TRY_MAX) && (err= stat(pid_file, &buf)); i++) sleep(1);
if (err != 0) err = errno; if (err != 0) err= errno;
#else #else
err= (WaitForSingleObject(pid_file, TRY_MAX*1000) == WAIT_TIMEOUT); err= (WaitForSingleObject(pid_file, TRY_MAX*1000) == WAIT_TIMEOUT);
#endif #endif
return err; return err;
} }
/****************************************************************************** /******************************************************************************
wait_for_server_start() wait_for_server_start()
Wait for the server on the given port to start. Wait for the server on the given port to start.
******************************************************************************/ ******************************************************************************/
int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port,char *tmp_dir)
int wait_for_server_start(char *bin_dir __attribute__((unused)),
char *mysqladmin_file,
char *user, char *password, int port,char *tmp_dir)
{ {
arg_list_t al; arg_list_t al;
int err, i; int err= 0, i;
char trash[PATH_MAX]; char trash[PATH_MAX];
// mysqladmin file /* mysqladmin file */
snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir); snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
// args /* args */
init_args(&al); init_args(&al);
add_arg(&al, "%s", mysqladmin_file); add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults"); add_arg(&al, "--no-defaults");
@ -235,7 +244,7 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
add_arg(&al, "--password=%s", password); add_arg(&al, "--password=%s", password);
add_arg(&al, "--silent"); add_arg(&al, "--silent");
//#ifdef NOT_USED /* #ifdef NOT_USED */
#ifndef __NETWARE__ #ifndef __NETWARE__
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "connect_timeout=10"); add_arg(&al, "connect_timeout=10");
@ -245,20 +254,22 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
add_arg(&al, "--host=localhost"); add_arg(&al, "--host=localhost");
#ifndef __NETWARE__ #ifndef __NETWARE__
add_arg(&al, "--protocol=tcp"); add_arg(&al, "--protocol=tcp");
#endif #endif
add_arg(&al, "ping"); add_arg(&al, "ping");
// NetWare does not support the connect timeout in the TCP/IP stack /*
// -- we will try the ping multiple times NetWare does not support the connect timeout in the TCP/IP stack
-- we will try the ping multiple times
*/
#ifndef __WIN__ #ifndef __WIN__
for(i = 0; (i < TRY_MAX) for (i= 0; (i < TRY_MAX)
&& (err = spawn(mysqladmin_file, &al, TRUE, NULL, && (err= spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL, NULL)); i++) sleep(1); trash, NULL, NULL)); i++) sleep(1);
#else #else
err = spawn(mysqladmin_file, &al, TRUE, NULL,trash, NULL, NULL); err= spawn(mysqladmin_file, &al, TRUE, NULL,trash, NULL, NULL);
#endif #endif
// free args /* free args */
free_args(&al); free_args(&al);
return err; return err;
@ -266,38 +277,39 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
/****************************************************************************** /******************************************************************************
spawn() spawn()
Spawn the given path with the given arguments. Spawn the given path with the given arguments.
******************************************************************************/ ******************************************************************************/
#ifdef __NETWARE__ #ifdef __NETWARE__
int spawn(char *path, arg_list_t *al, int join, char *input, int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error, char *pid_file) char *output, char *error, char *pid_file)
{ {
pid_t pid; pid_t pid;
int result = 0; int result= 0;
wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED }; wiring_t wiring= { FD_UNUSED, FD_UNUSED, FD_UNUSED };
unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD; unsigned long flags= PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
// open wiring /* open wiring */
if (input) if (input)
wiring.infd = open(input, O_RDONLY); wiring.infd= open(input, O_RDONLY);
if (output) if (output)
wiring.outfd = open(output, O_WRONLY | O_CREAT | O_TRUNC); wiring.outfd= open(output, O_WRONLY | O_CREAT | O_TRUNC);
if (error) if (error)
wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC); wiring.errfd= open(error, O_WRONLY | O_CREAT | O_TRUNC);
// procve requires a NULL /* procve requires a NULL */
add_arg(al, NULL); add_arg(al, NULL);
// go /* go */
pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0, pid= procve(path, flags, NULL, &wiring, NULL, NULL, 0,
NULL, (const char **)al->argv); NULL, (const char **)al->argv);
// close wiring /* close wiring */
if (wiring.infd != -1) if (wiring.infd != -1)
close(wiring.infd); close(wiring.infd);
@ -307,7 +319,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
if (wiring.errfd != -1) if (wiring.errfd != -1)
close(wiring.errfd); close(wiring.errfd);
return result; return result;
} }
#elif __WIN__ #elif __WIN__
@ -322,18 +334,16 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
char win_args[1024]= ""; char win_args[1024]= "";
char command_line[1024]= ""; char command_line[1024]= "";
/* /* Skip the first parameter */
Skip the first parameter for (i= 1; i < al->argc; i++)
*/
for(i = 1; i < al->argc; i++)
{ {
ASSERT(al->argv[i] != NULL); ASSERT(al->argv[i] != NULL);
strcat(win_args,al->argv[i]); strcat(win_args,al->argv[i]);
strcat(win_args," "); strcat(win_args," ");
} }
memset(&startup_info,0,sizeof(STARTUPINFO)); memset(&startup_info,0,sizeof(STARTUPINFO));
startup_info.cb = sizeof(STARTUPINFO); startup_info.cb= sizeof(STARTUPINFO);
if (input) if (input)
freopen(input, "rb", stdin); freopen(input, "rb", stdin);
@ -361,7 +371,8 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
{ {
if (join) if (join)
{ {
if (WaitForSingleObject(process_information.hProcess, mysqld_timeout) == WAIT_TIMEOUT) if (WaitForSingleObject(process_information.hProcess, mysqld_timeout)
== WAIT_TIMEOUT)
{ {
exit_code= -1; exit_code= -1;
} }
@ -393,76 +404,60 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
} }
#else #else
int spawn(char *path, arg_list_t *al, int join, char *input, int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error, char *pid_file) char *output, char *error, char *pid_file __attribute__((unused)))
{ {
pid_t pid; pid_t pid;
int res_exec = 0; int res_exec= 0;
int result = 0; int result= 0;
pid = fork(); pid= fork();
if (pid == -1) if (pid == -1)
{ {
fprintf(stderr, "fork was't created\n"); fprintf(stderr, "fork was't created\n");
/* /* We can't create the fork...exit with error */
We can't create the fork...exit with error return EXIT_FAILURE;
*/
return EXIT_FAILURE;
} }
if (pid > 0) if (pid > 0)
{ {
/* /* The parent process is waiting for child process if join is not zero */
The parent process is waiting for child process if join is not zero
*/
if (join) if (join)
{ {
waitpid(pid, &result, 0); waitpid(pid, &result, 0);
if (WIFEXITED(result) != 0) if (WIFEXITED(result) != 0)
{ {
result = WEXITSTATUS(result); result= WEXITSTATUS(result);
} }
else else
{ {
result = EXIT_FAILURE; result= EXIT_FAILURE;
} }
} }
} }
else else
{ {
/*
Child process
*/
add_arg(al, NULL); /* Child process */
add_arg(al, NULL);
/* Reassign streams */
/*
Reassign streams
*/
if (input) if (input)
freopen(input, "r", stdin); freopen(input, "r", stdin);
if (output) if (output)
freopen(output, "w", stdout); freopen(output, "w", stdout);
if (error) if (error)
freopen(error, "w", stderr); freopen(error, "w", stderr);
/* Spawn the process */ /* Spawn the process */
if ((res_exec = execve(path, al->argv, environ)) < 0) if ((res_exec= execve(path, al->argv, environ)) < 0)
{
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
/* /* Restore streams */
Restore streams
*/
if (input) if (input)
freopen("/dev/tty", "r", stdin); freopen("/dev/tty", "r", stdin);
if (output) if (output)
freopen("/dev/tty", "w", stdout); freopen("/dev/tty", "w", stdout);
@ -472,32 +467,34 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
exit(0); exit(0);
} }
return result; return result;
} }
#endif #endif
/****************************************************************************** /******************************************************************************
stop_server() stop_server()
Stop the server with the given port and pid file. Stop the server with the given port and pid file.
******************************************************************************/ ******************************************************************************/
int stop_server(char *bin_dir __attribute__((unused)), char *mysqladmin_file,
char *user, char *password, int port,
#ifndef __WIN__ #ifndef __WIN__
int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port, char *pid_file,
char *pid_file,char *tmp_dir)
#else #else
int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port, HANDLE pid_file,
HANDLE pid_file,char *tmp_dir)
#endif #endif
char *tmp_dir)
{ {
arg_list_t al; arg_list_t al;
int err = 0; int err= 0;
char trash[PATH_MAX]; char trash[PATH_MAX];
snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir); snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
// args /* args */
init_args(&al); init_args(&al);
add_arg(&al, "%s", mysqladmin_file); add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults"); add_arg(&al, "--no-defaults");
@ -508,33 +505,33 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
add_arg(&al, "shutdown_timeout=20"); add_arg(&al, "shutdown_timeout=20");
#ifndef __NETWARE__ #ifndef __NETWARE__
add_arg(&al, "--protocol=tcp"); add_arg(&al, "--protocol=tcp");
#endif #endif
add_arg(&al, "shutdown"); add_arg(&al, "shutdown");
// spawn /* spawn */
if ((err = spawn(mysqladmin_file, &al, TRUE, NULL, if ((err= spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL, NULL)) == 0) trash, NULL, NULL)) == 0)
{ {
sleep_until_file_deleted(pid_file); sleep_until_file_deleted(pid_file);
} }
else else
{ {
#ifndef __WIN__ #ifndef __WIN__
pid_t pid = get_server_pid(pid_file); pid_t pid= get_server_pid(pid_file);
// shutdown failed - kill server /* shutdown failed - kill server */
kill_server(pid); kill_server(pid);
sleep(TRY_MAX); sleep(TRY_MAX);
// remove pid file if possible /* remove pid file if possible */
err = remove(pid_file); err= remove(pid_file);
#else #else
TerminateProcess(pid_file,err); TerminateProcess(pid_file,err);
#endif #endif
} }
// free args /* free args */
free_args(&al); free_args(&al);
return err; return err;
@ -542,57 +539,59 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
/****************************************************************************** /******************************************************************************
get_server_pid() get_server_pid()
Get the VM id with the given pid file. Get the VM id with the given pid file.
******************************************************************************/ ******************************************************************************/
#ifndef __WIN__ #ifndef __WIN__
pid_t get_server_pid(char *pid_file) pid_t get_server_pid(char *pid_file)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
int fd, err; int fd, err;
char *p; char *p;
pid_t id = 0; pid_t id= 0;
// discover id /* discover id */
fd = open(pid_file, O_RDONLY); fd= open(pid_file, O_RDONLY);
err = read(fd, buf, PATH_MAX); err= read(fd, buf, PATH_MAX);
close(fd); close(fd);
if (err > 0) if (err > 0)
{ {
// terminate string /* terminate string */
if ((p = strchr(buf, '\n')) != NULL) if ((p= strchr(buf, '\n')) != NULL)
{ {
*p = '\0'; *p= '\0';
// check for a '\r' /* check for a '\r' */
if ((p = strchr(buf, '\r')) != NULL) if ((p= strchr(buf, '\r')) != NULL)
{ {
*p = '\0'; *p= '\0';
} }
} }
else else
{ {
buf[err] = '\0'; buf[err]= '\0';
} }
id = strtol(buf, NULL, 0); id= strtol(buf, NULL, 0);
} }
return id; return id;
} }
/****************************************************************************** /******************************************************************************
kill_server() kill_server()
Force a kill of the server with the given pid. Force a kill of the server with the given pid.
******************************************************************************/ ******************************************************************************/
void kill_server(pid_t pid) void kill_server(pid_t pid)
{ {
if (pid > 0) if (pid > 0)
@ -603,51 +602,52 @@ void kill_server(pid_t pid)
#else /* __NETWARE__ */ #else /* __NETWARE__ */
/* destroy vm */ /* destroy vm */
NXVmDestroy(pid); NXVmDestroy(pid);
#endif #endif
} }
} }
#endif #endif
/****************************************************************************** /******************************************************************************
del_tree() del_tree()
Delete the directory and subdirectories. Delete the directory and subdirectories.
******************************************************************************/ ******************************************************************************/
void del_tree(char *dir) void del_tree(char *dir)
{ {
#ifndef __WIN__ #ifndef __WIN__
DIR *parent = opendir(dir); DIR *parent= opendir(dir);
struct dirent *entry; struct dirent *entry;
char temp[PATH_MAX]; char temp[PATH_MAX];
if (parent == NULL) if (parent == NULL)
{ {
return; return;
} }
while((entry = readdir(parent)) != NULL) while ((entry= readdir(parent)) != NULL)
{ {
// create long name /* create long name */
snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name); snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
if (entry->d_name[0] == '.') if (entry->d_name[0] == '.')
{ {
// Skip /* Skip */
} }
else else
if (S_ISDIR(entry->d_type)) if (S_ISDIR(entry->d_type))
{ {
// delete subdirectory /* delete subdirectory */
del_tree(temp); del_tree(temp);
} }
else else
{ {
// remove file /* remove file */
remove(temp); remove(temp);
} }
} }
// remove directory /* remove directory */
rmdir(dir); rmdir(dir);
#else #else
struct _finddata_t parent; struct _finddata_t parent;
@ -664,50 +664,51 @@ void del_tree(char *dir)
do do
{ {
// create long name /* create long name */
snprintf(temp, PATH_MAX, "%s/%s", dir, parent.name); snprintf(temp, PATH_MAX, "%s/%s", dir, parent.name);
if (parent.name[0] == '.') if (parent.name[0] == '.')
{ {
// Skip /* Skip */
} }
else else
if (parent.attrib & _A_SUBDIR) if (parent.attrib & _A_SUBDIR)
{ {
// delete subdirectory /* delete subdirectory */
del_tree(temp); del_tree(temp);
} }
else else
{ {
// remove file /* remove file */
remove(temp); remove(temp);
} }
} while (_findnext(handle,&parent) == 0); } while (_findnext(handle,&parent) == 0);
_findclose(handle); _findclose(handle);
// remove directory /* remove directory */
_rmdir(dir); _rmdir(dir);
#endif #endif
} }
/****************************************************************************** /******************************************************************************
removef() removef()
******************************************************************************/ ******************************************************************************/
int removef(const char *format, ...) int removef(const char *format, ...)
{ {
#ifdef __NETWARE__ #ifdef __NETWARE__
va_list ap; va_list ap;
char path[PATH_MAX]; char path[PATH_MAX];
va_start(ap, format); va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap); vsnprintf(path, PATH_MAX, format, ap);
va_end(ap); va_end(ap);
return remove(path); return remove(path);
#eldef __WIN__ #eldef __WIN__
{ {
va_list ap; va_list ap;
@ -716,25 +717,23 @@ int removef(const char *format, ...)
intptr_t handle; intptr_t handle;
char temp[PATH_MAX]; char temp[PATH_MAX];
char *p; char *p;
va_start(ap, format); va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap); vsnprintf(path, PATH_MAX, format, ap);
va_end(ap); va_end(ap);
p = path + strlen(path); p= path + strlen(path);
while (*p != '\\' && *p != '/' && p > path) p--; while (*p != '\\' && *p != '/' && p > path) p--;
if ((handle=_findfirst(path,&parent)) == -1L) if ((handle=_findfirst(path,&parent)) == -1L)
{ {
/* /* if there is not files....it's ok */
if there is not files....it's ok.
*/
return 0; return 0;
} }
*p = '\0'; *p= '\0';
do do
{ {
@ -754,89 +753,80 @@ int removef(const char *format, ...)
va_list ap; va_list ap;
char path[PATH_MAX]; char path[PATH_MAX];
char *p; char *p;
/* /* Get path with mask */
Get path with mask
*/
va_start(ap, format); va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap); vsnprintf(path, PATH_MAX, format, ap);
va_end(ap); va_end(ap);
p = path + strlen(path); p= path + strlen(path);
while (*p != '\\' && *p != '/' && p > path) p--; while (*p != '\\' && *p != '/' && p > path) p--;
*p = '\0'; *p= '\0';
p++; p++;
parent = opendir(path); parent= opendir(path);
if (parent == NULL) if (parent == NULL)
{ {
return; return 1; /* Error, directory missing */
} }
while((entry = readdir(parent)) != NULL) while ((entry= readdir(parent)) != NULL)
{ {
/* /* entry is not directory and entry matches with mask */
entry is not directory and entry matches with mask
*/
if (!S_ISDIR(entry->d_type) && !fnmatch(p, entry->d_name,0)) if (!S_ISDIR(entry->d_type) && !fnmatch(p, entry->d_name,0))
{ {
// create long name /* create long name */
snprintf(temp, PATH_MAX, "%s/%s", path, entry->d_name); snprintf(temp, PATH_MAX, "%s/%s", path, entry->d_name);
// Delete only files /* Delete only files */
remove(temp); remove(temp);
} }
} }
#endif #endif
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
get_basedir() get_basedir()
******************************************************************************/ ******************************************************************************/
void get_basedir(char *argv0, char *basedir) void get_basedir(char *argv0, char *basedir)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
char *p; char *p;
int position; int position;
ASSERT(argv0 != NULL); ASSERT(argv0 != NULL);
ASSERT(basedir != NULL); ASSERT(basedir != NULL);
strcpy(temp, strlwr(argv0)); strcpy(temp, strlwr(argv0));
while((p = strchr(temp, '\\')) != NULL) *p = '/'; while ((p= strchr(temp, '\\')) != NULL) *p= '/';
if ((position = strinstr(temp, "/bin/")) != 0) if ((position= strinstr(temp, "/bin/")) != 0)
{ {
p = temp + position; p= temp + position;
*p = '\0'; *p= '\0';
strcpy(basedir, temp); strcpy(basedir, temp);
} }
} }
#if !defined(__NETWARE__) && !defined(__WIN__)
char *strlwr(const char *s)
{
return s;
}
#endif
uint strinstr(reg1 const char *str,reg4 const char *search) uint strinstr(reg1 const char *str,reg4 const char *search)
{ {
reg2 my_string i,j; reg2 my_string i,j;
my_string start = (my_string) str; my_string start= (my_string) str;
skipp: skipp:
while (*str != '\0') while (*str != '\0')
{ {
if (*str++ == *search) if (*str++ == *search)
{ {
i=(my_string) str; j= (my_string) search+1; i=(my_string) str;
j= (my_string) search+1;
while (*j) while (*j)
if (*i++ != *j++) goto skipp; if (*i++ != *j++) goto skipp;
return ((uint) (str - start)); return ((uint) (str - start));
} }
} }
@ -845,13 +835,14 @@ uint strinstr(reg1 const char *str,reg4 const char *search)
/****************************************************************************** /******************************************************************************
remove_empty_file() remove_empty_file()
******************************************************************************/ ******************************************************************************/
void remove_empty_file(const char *file_name) void remove_empty_file(const char *file_name)
{ {
struct stat file; struct stat file;
if (!stat(file_name,&file)) if (!stat(file_name,&file))
{ {
if (!file.st_size) if (!file.st_size)

View File

@ -21,8 +21,8 @@
/****************************************************************************** /******************************************************************************
includes includes
******************************************************************************/ ******************************************************************************/
#include <stdlib.h> #include <stdlib.h>
@ -36,7 +36,7 @@
#ifndef __WIN__ #ifndef __WIN__
#define strnicmp strncasecmp #define strnicmp strncasecmp
char *strlwr(const char *s); #define strlwr(STRARG) (STRARG)
#else #else
int my_vsnprintf_(char *to, size_t n, const char* value, ...); int my_vsnprintf_(char *to, size_t n, const char* value, ...);
#endif #endif
@ -44,12 +44,12 @@ int my_vsnprintf_(char *to, size_t n, const char* value, ...);
/****************************************************************************** /******************************************************************************
macros macros
******************************************************************************/ ******************************************************************************/
#define ARG_BUF 10 #define ARG_BUF 10
#define TRY_MAX 5 #define TRY_MAX 5
#ifdef __WIN__ #ifdef __WIN__
#define PATH_MAX _MAX_PATH #define PATH_MAX _MAX_PATH
@ -71,8 +71,8 @@ bool skip_first_param;
/****************************************************************************** /******************************************************************************
structures structures
******************************************************************************/ ******************************************************************************/
typedef struct typedef struct
@ -90,14 +90,14 @@ typedef int pid_t;
#endif #endif
/****************************************************************************** /******************************************************************************
global variables global variables
******************************************************************************/ ******************************************************************************/
/****************************************************************************** /******************************************************************************
prototypes prototypes
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *); void init_args(arg_list_t *);

File diff suppressed because it is too large Load Diff