* util.c [!HAVE_X] (is_printable): Don't duplicate declarations from
main.h. (load_file): Use fopen and fstat to prevent race conditions. (size_trunc): Make suffix const array. (strip_password): Make prefixes const array. (file_date): Make fmt auto variable.
Этот коммит содержится в:
родитель
24385045ce
Коммит
78dbe61c6a
18
src/util.c
18
src/util.c
@ -106,12 +106,6 @@ int is_printable (int c)
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern int xterm_flag;
|
extern int xterm_flag;
|
||||||
#ifdef HAVE_CHARSET
|
|
||||||
extern int display_codepage;
|
|
||||||
#else
|
|
||||||
extern int eight_bit_clean;
|
|
||||||
extern int full_eight_bits;
|
|
||||||
#endif /* !HAVE_CHARSET */
|
|
||||||
|
|
||||||
c &= 0xff;
|
c &= 0xff;
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
@ -325,7 +319,7 @@ size_trunc_len (char *buffer, int len, off_t size)
|
|||||||
static const off_t power10 [] =
|
static const off_t power10 [] =
|
||||||
{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000,
|
{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000,
|
||||||
1000000000};
|
1000000000};
|
||||||
static const char *suffix [] =
|
static const char * const suffix [] =
|
||||||
{"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL};
|
{"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL};
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
@ -395,7 +389,7 @@ char *string_perm (mode_t mode_bits)
|
|||||||
char *
|
char *
|
||||||
strip_password (char *p, int has_prefix)
|
strip_password (char *p, int has_prefix)
|
||||||
{
|
{
|
||||||
static struct {
|
static const struct {
|
||||||
char *name;
|
char *name;
|
||||||
size_t len;
|
size_t len;
|
||||||
} prefixes[] = { {"/#ftp:", 6},
|
} prefixes[] = { {"/#ftp:", 6},
|
||||||
@ -620,10 +614,11 @@ char *load_file (char *filename)
|
|||||||
char *data;
|
char *data;
|
||||||
long read_size;
|
long read_size;
|
||||||
|
|
||||||
if (stat (filename, &s) != 0){
|
if ((data_file = fopen (filename, "r")) == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((data_file = fopen (filename, "r")) == NULL){
|
if (fstat (fileno (data_file), &s) != 0){
|
||||||
|
fclose (data_file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
data = (char *) g_malloc (s.st_size+1);
|
data = (char *) g_malloc (s.st_size+1);
|
||||||
@ -701,7 +696,8 @@ char *file_date (time_t when)
|
|||||||
static char timebuf [MAX_I18NTIMELENGTH + 1];
|
static char timebuf [MAX_I18NTIMELENGTH + 1];
|
||||||
time_t current_time = time ((time_t) 0);
|
time_t current_time = time ((time_t) 0);
|
||||||
static size_t i18n_timelength = 0;
|
static size_t i18n_timelength = 0;
|
||||||
static char *fmt, *fmtyear, *fmttime;
|
static char *fmtyear, *fmttime;
|
||||||
|
char *fmt;
|
||||||
|
|
||||||
if (i18n_timelength == 0){
|
if (i18n_timelength == 0){
|
||||||
i18n_timelength = i18n_checktimelength() + 1;
|
i18n_timelength = i18n_checktimelength() + 1;
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user