在vxworks下,怎么判断指定的路径有无写权限?
在vxworks下,怎么判断指定的路径有无写权限?
类似于linux下的access 系统调用
[解决办法]
可参考ll命令的源码,我们输入ll命令后,会显示类似下面的信息
drwxrwxrwx 1 0 0 3267 Dec 12 14:07 BC31/
drwxrwxrwx这个显示目录是否可读写。它的原理是:struct stat * fileStat,/* stat() structure */
可查看一下ll命令的源码:
C:\Tornado2.2\target\src\usr\usrFsLib.c
LOCAL STATUS dirListEnt
(
intfd,/* file descriptor for output */
char *fileName,/* file name */
struct stat * fileStat,/* stat() structure */
char *prefix,/* prefix for short output */
BOOLdoLong/* do Long listing format */
)
{
time_tnow;/* current clock */
struct tmnowDate;/* current date & time */
struct tmfileDate;/* file date/time (long listing) */
const char *monthNames[] = {"???", "Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec"};
char fType, modbits[10] ;
char suffix = ' ';/* print '/' after directory name */
if(doLong)
{
/* Break down file modified time */
time( &now );
localtime_r (&now, &nowDate);
localtime_r (&fileStat->st_mtime, &fileDate);
if (fileStat->st_attrib & DOS_ATTR_RDONLY)
fileStat->st_mode &= ~(S_IWUSR
[解决办法]
S_IWGRP
[解决办法]
S_IWOTH);
if (S_ISDIR (fileStat->st_mode))
{
fType = 'd' ;
suffix = '/';
}
else if (S_ISREG (fileStat->st_mode))
fType = '-' ;
else
fType = '?' ;
strcpy( modbits, "---------" );
modbits[0] = (fileStat->st_mode & S_IRUSR)? 'r':'-';
modbits[1] = (fileStat->st_mode & S_IWUSR)? 'w':'-';
modbits[2] = (fileStat->st_mode & S_IXUSR)? 'x':'-';
modbits[3] = (fileStat->st_mode & S_IRGRP)? 'r':'-';
modbits[4] = (fileStat->st_mode & S_IWGRP)? 'w':'-';
modbits[5] = (fileStat->st_mode & S_IXGRP)? 'x':'-';
modbits[6] = (fileStat->st_mode & S_IROTH)? 'r':'-';
modbits[7] = (fileStat->st_mode & S_IWOTH)? 'w':'-';
modbits[8] = (fileStat->st_mode & S_IXOTH)? 'x':'-';
if (fileStat->st_attrib & DOS_ATTR_ARCHIVE)
modbits[6] = 'A';
if(fileStat->st_attrib & DOS_ATTR_SYSTEM)
modbits[7] = 'S';
if(fileStat->st_attrib & DOS_ATTR_HIDDEN)
modbits[8] = 'H';
modbits[9] = EOS ;
/* print file mode */
fdprintf(fd, "%c%9s", fType, modbits);
/* fake links, user and group fields */
fdprintf(fd, " %2d %-7d %-7d ", fileStat->st_nlink,
fileStat->st_uid, fileStat->st_gid );
/* print file size - XXX: add 64 bit file size support */
fdprintf(fd, " %9lu ", fileStat->st_size );
/* print date */
if (fileDate.tm_year == nowDate.tm_year)
{
fdprintf(fd, "%s %2d %02d:%02d ",
monthNames [fileDate.tm_mon + 1],/* month */
fileDate.tm_mday, /* day of month */
fileDate.tm_hour,/* hour */
fileDate.tm_min/* minute */
);
}
else
{
fdprintf(fd, "%s %2d %04d ",
monthNames [fileDate.tm_mon + 1],/* month */
fileDate.tm_mday,/* day of month */
fileDate.tm_year+1900/* year */
);
}
} /* if doLong */
else
{ /* short listing */
if (strcmp(prefix , ".") == 0
[解决办法]
prefix[0] == EOS)
/* dint print "." prefix */ ;
else if (prefix != NULL && prefix [ strlen(prefix) -1 ] != '/')
fdprintf(fd, "%s/", prefix);
else if (prefix != NULL)
fdprintf(fd, prefix);
}
/* last, print file name */
if (fdprintf(fd, "%s%c\n", fileName, suffix ) == ERROR)
return ERROR;
return OK ;
}