minix/lib/libc/posix/_stat.c

38 lines
775 B
C
Raw Normal View History

2005-04-21 16:53:53 +02:00
#include <lib.h>
#define stat _stat
#include <sys/stat.h>
#include <string.h>
PUBLIC int stat(name, buffer)
_CONST char *name;
struct stat *buffer;
{
message m;
int r;
struct minix_prev_stat old_sb;
2005-04-21 16:53:53 +02:00
m.m1_i1 = strlen(name) + 1;
m.m1_p1 = (char *) name;
m.m1_p2 = (char *) buffer;
if((r = _syscall(VFS_PROC_NR, STAT, &m)) >= 0 || errno != ENOSYS)
return r;
errno = 0;
/* ENOSYS: new binary and old VFS, fallback to PREV_STAT.
* User has struct stat (buffer), VFS still fills minix_prev_stat.
*/
m.m1_i1 = strlen(name) + 1;
m.m1_p1 = (char *) name;
m.m1_p2 = (char *) &old_sb;
if((r = _syscall(VFS_PROC_NR, PREV_STAT, &m)) < 0)
return r;
memset(buffer, 0, sizeof(struct stat));
COPY_PREV_STAT_TO_NEW(buffer, &old_sb);
return r;
2005-04-21 16:53:53 +02:00
}