/******************************************************** * File: exec.c * Created at Sun Jan 28 22:10:26 MSK 2001 by raorn // raorn@binec.ru * Exec stuff * $Id: exec.c,v 1.4 2002/10/27 22:47:52 raorn Exp $ *******************************************************/ #include #include #include #include #include #ifdef HAVE_SYS_STAT_H # include #endif #include #ifdef HAVE_UNISTD_H # include #endif #ifdef HAVE_SYS_WAIT_H # include #endif #ifndef WEXITSTATUS # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) #endif #ifndef WIFEXITED # define WIFEXITED(stat_val) (((stat_val) & 255) == 0) #endif #include "jblist.h" #include "exec.h" /* Returns -1 if dir was not found and errorlevel otherwise */ int ChDirExecute(uchar * dir, uchar * cmd, int *rc) { char olddir[300]; int res; if (!getcwd(olddir, 300)) return -1; if (chdir(dir) != 0) return -1; res = Execute(cmd, rc); chdir(olddir); return (res); } int Execute(uchar * cmd, int *rc) { int res; res = system(cmd); if (WIFEXITED(res)) { *rc = WEXITSTATUS(res); return 0; } return res; }