diff --git a/src/ChangeLog b/src/ChangeLog index 1ffd1ac5d..f600559bf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2002-07-29 Pavel Roskin + * util.c: Remove unused functions. + * utilunix.c: Likewise. + * util.h: Update to match. + * cons.saver.c: Use SEEK_SET instead of 0 in lseek(). * view.c: Likewise. diff --git a/src/util.c b/src/util.c index e3ec3f591..fe393a74d 100644 --- a/src/util.c +++ b/src/util.c @@ -55,10 +55,8 @@ /* "$Id$" */ -const char app_text [] = "Midnight-Commander"; - +static const char app_text [] = "Midnight-Commander"; int easy_patterns = 1; -int tilde_trunc = 1; #ifndef VFS_STANDALONE int is_printable (int c) @@ -199,6 +197,7 @@ char *name_trunc (char *txt, int trunc_len) static char x [MC_MAXPATHLEN+MC_MAXPATHLEN]; int txt_len; char *p; + const int tilde_trunc = 1; if (!txt) txt = PATH_SEP_STR; @@ -680,13 +679,6 @@ char *file_date (time_t when) return timebuf; } -/* Like file_date, but packs the data to fit in 10 columns */ -char *file_date_pck (time_t when) -{ - /* FIXME: Should return only 10 chars, not 14 */ - return file_date (when); -} - char *extract_line (char *s, char *top) { static char tmp_line [BUF_MEDIUM]; @@ -760,16 +752,6 @@ char *unix_error_string (int error_num) } #ifndef VFS_STANDALONE -long blocks2kilos (int blocks, int bsize) -{ - if (bsize > 1024){ - return blocks * (bsize / 1024); - } else if (bsize < 1024){ - return blocks / (1024 /bsize); - } else - return blocks; -} - char *skip_separators (char *s) { for (;*s; s++) @@ -910,51 +892,6 @@ decompress_extension (int type) return 0; } -char * -decompress_command (int type) -{ - switch (type){ - case COMPRESSION_GZIP: - return "gzip -cdf"; - - case COMPRESSION_BZIP: - return "bzip -d"; - - case COMPRESSION_BZIP2: - return "bzip2 -d"; - } - /* Should never reach this place */ - fprintf (stderr, "Fatal: decompress_command called with an unknown argument\n"); - return 0; -} - -void -decompress_command_and_arg (int type, char **cmd, char **flags) -{ - switch (type){ - case COMPRESSION_GZIP: - *cmd = "gzip"; - *flags = "-cdf"; - return; - - case COMPRESSION_BZIP: - *cmd = "bzip"; - *flags = "-d"; - return; - - - case COMPRESSION_BZIP2: - *cmd = "bzip2"; - *flags = "-d"; - return; - } - *cmd = 0; - *flags = 0; - - /* Should never reach this place */ - fprintf (stderr, "Fatal: decompress_command called with an unknown argument\n"); -} - #ifndef VFS_STANDALONE /* Hooks */ void add_hook (Hook **hook_list, void (*hook_fn)(void *), void *data) @@ -1083,7 +1020,7 @@ char *reverse_string (char *string) return string; } -char *resolve_symlinks (char *path) +static char *resolve_symlinks (char *path) { char *buf, *buf2, *p, *q, *r, c; int len; @@ -1203,44 +1140,6 @@ char *diff_two_paths (char *first, char *second) g_free (second); return buf; } - -#ifndef HAVE_TRUNCATE -/* On SCO and Windows NT systems */ -int my_ftruncate (int fd, long size) -{ -#ifdef OS2_NT - if(_chsize(fd, size)) - return -1; - else - return 0; -#else - struct flock lk; - - lk.l_whence = 0; - lk.l_start = size; - lk.l_len = 0; - - return fcntl (fd, F_FREESP, &lk); -#endif /* !OS2_NT */ -} - -int truncate (const char *path, long size) -{ - int fd; - int res; - - fd = open (path, O_RDWR, 0); - if (fd < 0) - return fd; - res = my_ftruncate (fd, size); - close (fd); - if (res < 0) - return res; - return 0; - -} - -#endif /* !HAVE_TRUNCATE */ #endif /* !VFS_STANDALONE */ /* If filename is NULL, then we just append PATH_SEP to the dir */ diff --git a/src/util.h b/src/util.h index 98a0d100d..759bb8bf2 100644 --- a/src/util.h +++ b/src/util.h @@ -6,10 +6,6 @@ /* String managing functions */ -#if defined(SCO_FLAVOR) && defined(__GNUC__) -extern char*g_strdup (const char*); -#endif - int is_printable (int c); int msglen (char *text, int *lines); char *trim (char *s, char *d, int len); @@ -32,12 +28,9 @@ char *strip_ctrl_codes (char *s); char *convert_controls (char *s); void wipe_password (char *passwd); char *reverse_string (char *string); -char *resolve_symlinks (char *path); char *diff_two_paths (char *first, char *second); -int set_nonblocking (int fd); char *x_basename (char *s); -char *g_readlink (char *path); /* Profile managing functions */ int set_int (char *, char *, int); @@ -62,7 +55,6 @@ char *get_owner (int); size_t i18n_checktimelength (void); char *file_date (time_t); -char *file_date_pck (time_t); int exist_file (char *name); /* Returns a copy of *s until a \n is found and is below top */ @@ -89,7 +81,6 @@ void my_putenv (char*, char*); #define EXECUTE_SETUID 8 #define EXECUTE_WAIT 16 int my_system (int flags, const char *shell, const char *command); -int my_system_get_child_pid (int flags, const char *shell, const char *command, pid_t *pid); void save_stop_handler (void); extern struct sigaction startup_handler; @@ -100,7 +91,6 @@ char *tilde_expand (const char *); char *canonicalize_pathname (char *); /* Misc Unix functions */ -long blocks2kilos (int blocks, int bsize); char *get_current_wd (char *buffer, int size); int my_mkdir (char *s, mode_t mode); int my_rmdir (char *s); @@ -124,9 +114,7 @@ enum { }; int get_compression_type (int fd); -char *decompress_command (int type); char *decompress_extension (int type); -void decompress_command_and_arg (int type, char **cmd, char **flags); int mc_doublepopen (int inhandle, int inlen, pid_t *tp, char *command, ...); int mc_doublepclose (int pipehandle, pid_t pid); @@ -144,8 +132,6 @@ void execute_hooks (Hook *hook_list); void delete_hook (Hook **hook_list, void (*hook_fn)(void *)); int hook_present (Hook *hook_list, void (*hook_fn)(void *)); -int max_open_files (void); - #ifdef OS2_NT # define PATH_SEP '\\' # define PATH_SEP_STR "\\" diff --git a/src/utilunix.c b/src/utilunix.c index 95d822f50..caf41f349 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -44,31 +44,11 @@ struct sigaction startup_handler; -int -max_open_files (void) -{ - static int files; - - if (files) - return files; - -#ifdef HAVE_SYSCONF - files = sysconf (_SC_OPEN_MAX); - if (files != -1) - return files; -#endif -#ifdef OPEN_MAX - return files = OPEN_MAX; -#else - return files = 256; -#endif -} - #ifndef VFS_STANDALONE /* uid of the MC user */ -uid_t current_user_uid = -1; +static uid_t current_user_uid = -1; /* List of the gids of the user */ -GTree *current_user_gid = NULL; +static GTree *current_user_gid = NULL; /* Helper function to compare 2 gids */ static gint @@ -335,15 +315,6 @@ char *tilde_expand (const char *directory) } #ifndef VFS_STANDALONE -int -set_nonblocking (int fd) -{ - int val; - - val = fcntl (fd, F_GETFL, 0); - val |= O_NONBLOCK; - return fcntl (fd, F_SETFL, val) != -1; -} /* Pipes are guaranteed to be able to hold at least 4096 bytes */ /* More than that would be unportable */ @@ -675,6 +646,15 @@ int gettimeofday( struct timeval * tv, struct timezone * tz) } #endif /* SCO_FLAVOR */ +#ifdef HAVE_GET_PROCESS_STATS +# include + +int gettimeofday (struct timeval *tp, void *tzp) +{ + return get_process_stats(tp, PS_SELF, 0, 0); +} +#endif /* HAVE_GET_PROCESS_STATS */ + #ifndef HAVE_PUTENV /* The following piece of code was copied from the GNU C Library */ @@ -738,15 +718,6 @@ putenv (const char *string) } #endif /* !HAVE_PUTENV */ -#ifdef HAVE_GET_PROCESS_STATS -# include - -int gettimeofday (struct timeval *tp, void *tzp) -{ - return get_process_stats(tp, PS_SELF, 0, 0); -} -#endif - #ifdef SCO_FLAVOR /* Define this only for SCO */ #ifdef USE_NETCODE @@ -783,7 +754,7 @@ int gettimeofday (struct timeval *tp, void *tzp) /* s_pipe returns 0 if OK, -1 on error */ /* two file descriptors are returned */ -int s_pipe(int fd[2]) +static int s_pipe(int fd[2]) { struct strfdinsert ins; /* stream I_FDINSERT ioctl format */ queue_t *pointer; @@ -847,45 +818,3 @@ int socketpair(int dummy1, int dummy2, int dummy3, int fd[2]) #endif /* ifdef USE_NETCODE */ #endif /* SCO_FLAVOR */ #endif /* VFS_STANDALONE */ - -char * -g_readlink (char *path) -{ - char small_buffer [80]; - char *str; - int n, size; - - n = readlink (path, small_buffer, sizeof (small_buffer)-1); - if (n == -1) - return NULL; - - if (n < sizeof (small_buffer)-1){ - small_buffer [n] = 0; - return g_strdup (small_buffer); - } - - str = NULL; - for (size = 256; size < 8192; size += 128){ - if (str) - g_free (str); - - str = g_malloc (size); - - n = readlink (path, str, size-1); - if (n == -1){ - g_free (str); - return NULL; - } - - if (n < size-1){ - char *s; - - str [n] = 0; - s = g_strdup (str); - g_free (str); - return s; - } - } - str [n] = 0; - return str; -}