a209c3ae12
This patch fixes most of current reasons to generate compiler warnings. The changes consist of: - adding missing casts - hiding or unhiding function declarations - including headers where missing - add __UNCONST when assigning a const char * to a char * - adding missing return statements - changing some types from unsigned to signed, as the code seems to want signed ints - converting old-style function definitions to current style (i.e., void func(param1, param2) short param1, param2; {...} to void func (short param1, short param2) {...}) - making the compiler silent about signed vs unsigned comparisons. We have too many of those in the new libc to fix. A number of bugs in the test set were fixed. These bugs were never triggered with our old libc. Consequently, these tests are now forced to link with the new libc or they will generate errors (in particular tests 43 and 55). Most changes in NetBSD libc are limited to moving aroudn "#ifndef __minix" or stuff related to Minix-specific things (code in sys-minix or gen/minix).
129 lines
2.8 KiB
C
129 lines
2.8 KiB
C
#include <sys/cdefs.h>
|
|
#include "namespace.h"
|
|
#include <lib.h>
|
|
|
|
#include <sys/stat.h>
|
|
#include <string.h>
|
|
|
|
|
|
/* XXX until that st_Xtime macroses used, we have to undefine them,
|
|
* because of minix_prev_stat
|
|
*/
|
|
#undef st_atime
|
|
#undef st_ctime
|
|
#undef st_mtime
|
|
|
|
static void prev_stat2new_stat(struct stat *new, struct minix_prev_stat *prev)
|
|
{
|
|
/* Copy field by field because of st_gid type mismath and
|
|
* difference in order after atime.
|
|
*/
|
|
new->st_dev = prev->st_dev;
|
|
new->st_ino = prev->st_ino;
|
|
new->st_mode = prev->st_mode;
|
|
new->st_nlink = prev->st_nlink;
|
|
new->st_uid = prev->st_uid;
|
|
new->st_gid = prev->st_gid;
|
|
new->st_rdev = prev->st_rdev;
|
|
new->st_size = prev->st_size;
|
|
new->st_atimespec.tv_sec = prev->st_atime;
|
|
new->st_mtimespec.tv_sec = prev->st_mtime;
|
|
new->st_ctimespec.tv_sec = prev->st_ctime;
|
|
}
|
|
|
|
int _stat(const char *name, struct stat *buffer);
|
|
|
|
int _stat(const char *name, struct stat *buffer)
|
|
{
|
|
message m;
|
|
int r;
|
|
struct minix_prev_stat old_sb;
|
|
|
|
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));
|
|
prev_stat2new_stat(buffer, &old_sb);
|
|
|
|
return r;
|
|
}
|
|
|
|
int _fstat(int fd, struct stat *buffer);
|
|
|
|
int _fstat(int fd, struct stat *buffer)
|
|
{
|
|
message m;
|
|
int r;
|
|
struct minix_prev_stat old_sb;
|
|
|
|
m.m1_i1 = fd;
|
|
m.m1_p1 = (char *) buffer;
|
|
|
|
if((r = _syscall(VFS_PROC_NR, FSTAT, &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 = fd;
|
|
m.m1_p1 = (char *) &old_sb;
|
|
|
|
if((r = _syscall(VFS_PROC_NR, PREV_FSTAT, &m)) < 0)
|
|
return r;
|
|
|
|
memset(buffer, 0, sizeof(struct stat));
|
|
prev_stat2new_stat(buffer, &old_sb);
|
|
|
|
return r;
|
|
}
|
|
|
|
int _lstat(const char *name, struct stat *buffer);
|
|
|
|
int _lstat(const char *name, struct stat *buffer)
|
|
{
|
|
message m;
|
|
int r;
|
|
struct minix_prev_stat old_sb;
|
|
|
|
m.m1_i1 = strlen(name) + 1;
|
|
m.m1_p1 = (char *) name;
|
|
m.m1_p2 = (char *) buffer;
|
|
|
|
if((r = _syscall(VFS_PROC_NR, LSTAT, &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_LSTAT, &m)) < 0)
|
|
return r;
|
|
|
|
memset(buffer, 0, sizeof(struct stat));
|
|
prev_stat2new_stat(buffer, &old_sb);
|
|
|
|
return r;
|
|
}
|