12 *-----------------------------------------------------------------------------
13 * generic file information and manipulation routines (public)
14 *-----------------------------------------------------------------------------
17 /* first we try the HOME environment var, if that doesn't work, we try getpwuid(). */
20 gchar *home = getenv("HOME");
25 struct passwd *pw = getpwuid(getuid());
29 return NULL ; /* now we've got a problem */
37 if ((!s)||(!*s)) return 0;
38 if (stat(s,&st)<0) return 0;
39 if (S_ISREG(st.st_mode)) return 1;
47 if ((!s)||(!*s)) return 0;
48 if (stat(s,&st)<0) return 0;
49 if (S_ISDIR(st.st_mode)) return 1;
57 if ((!s)||(!*s)) return 0;
58 if (stat(s,&st)<0) return 0;
59 return (int)st.st_size;
62 time_t filetime(gchar *s)
66 if ((!s)||(!*s)) return 0;
67 if (stat(s,&st)<0) return 0;
71 int copy_file(char *s, char *t)
90 while((b = fread(buf, sizeof(char), 4096, fi)) && b != 0)
92 if (fwrite(buf, sizeof(char), b, fo) != b)
105 int move_file(char *s, char *t)
107 if (rename (s, t) < 0)
109 /* this may have failed because moving a file across filesystems
110 was attempted, so try copy and delete instead */
115 /* err, now we can't delete the source file so return FALSE */
126 gchar *get_current_dir()
129 if (getcwd(buf, 510) == NULL)
134 dbuf = get_current_dir_name();
137 ret = g_strdup(dbuf); /* don't mix free w/ g_free */
142 return (g_strdup(".")); /* well, return something! broken? */
144 return g_strdup(buf);