summaryrefslogtreecommitdiff
path: root/uisimulator/common/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r--uisimulator/common/io.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index fe7bad438f..56abf4b6ad 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -28,6 +28,7 @@
28#include "config.h" 28#include "config.h"
29 29
30#define HAVE_STATVFS (!defined(WIN32)) 30#define HAVE_STATVFS (!defined(WIN32))
31#define HAVE_LSTAT (!defined(WIN32))
31 32
32#if HAVE_STATVFS 33#if HAVE_STATVFS
33#include <sys/statvfs.h> 34#include <sys/statvfs.h>
@@ -314,7 +315,7 @@ struct sim_dirent *sim_readdir(MYDIR *dir)
314 static struct sim_dirent secret; 315 static struct sim_dirent secret;
315 STAT_T s; 316 STAT_T s;
316 DIRENT_T *x11 = READDIR(dir->dir); 317 DIRENT_T *x11 = READDIR(dir->dir);
317 struct tm* tm; 318 struct tm tm;
318 319
319 if(!x11) 320 if(!x11)
320 return (struct sim_dirent *)0; 321 return (struct sim_dirent *)0;
@@ -324,20 +325,35 @@ struct sim_dirent *sim_readdir(MYDIR *dir)
324 /* build file name */ 325 /* build file name */
325 snprintf(buffer, sizeof(buffer), "%s/%s", 326 snprintf(buffer, sizeof(buffer), "%s/%s",
326 get_sim_pathname(dir->name), secret.d_name); 327 get_sim_pathname(dir->name), secret.d_name);
327 STAT(buffer, &s); /* get info */ 328 if (STAT(buffer, &s)) /* get info */
329 return NULL;
328 330
329#define ATTR_DIRECTORY 0x10 331#define ATTR_DIRECTORY 0x10
330 332
331 secret.info.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0; 333 secret.info.attribute = 0;
334
335 if (S_ISDIR(s.st_mode))
336 secret.info.attribute = ATTR_DIRECTORY;
337
332 secret.info.size = s.st_size; 338 secret.info.size = s.st_size;
339
340 if (localtime_r(&(s.st_mtime), &tm) == NULL)
341 return NULL;
342 secret.info.wrtdate = ((tm.tm_year - 80) << 9) |
343 ((tm.tm_mon + 1) << 5) |
344 tm.tm_mday;
345 secret.info.wrttime = (tm.tm_hour << 11) |
346 (tm.tm_min << 5) |
347 (tm.tm_sec >> 1);
348
349#ifdef HAVE_LSTAT
350#define ATTR_LINK 0x80
351 if (!lstat(buffer, &s) && S_ISLNK(s.st_mode))
352 {
353 secret.info.attribute |= ATTR_LINK;
354 }
355#endif
333 356
334 tm = localtime(&(s.st_mtime));
335 secret.info.wrtdate = ((tm->tm_year - 80) << 9) |
336 ((tm->tm_mon + 1) << 5) |
337 tm->tm_mday;
338 secret.info.wrttime = (tm->tm_hour << 11) |
339 (tm->tm_min << 5) |
340 (tm->tm_sec >> 1);
341 return &secret; 357 return &secret;
342} 358}
343 359