本文整理汇总了C++中FILE::ioctl方法的典型用法代码示例。如果您正苦于以下问题:C++ FILE::ioctl方法的具体用法?C++ FILE::ioctl怎么用?C++ FILE::ioctl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FILE
的用法示例。
在下文中一共展示了FILE::ioctl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lseek
off_t lseek(int fid, off_t offset, int whence)
{
off_t rc;
FILE *file;
#if OS_PARM_CHECK
/*-------------------------------------------------------------------*/
/* If the file descriptor is invalid, return error. */
/*-------------------------------------------------------------------*/
if (fid < 0 || fid >= FOPEN_MAX)
{
set_errno(EBADF);
return -1;
}
if (Files[fid].flags & FCB_DIR)
{
set_errno(EISDIR);
return -1;
}
#endif
/*-------------------------------------------------------------------*/
/* Get exclusive access to upper file system. */
/*-------------------------------------------------------------------*/
semPend(FileSysSem, WAIT_FOREVER);
/*-------------------------------------------------------------------*/
/* Return error if file is closed. */
/*-------------------------------------------------------------------*/
file = &Files[fid];
if (file->ioctl == NULL)
{
set_errno(EBADF);
semPost(FileSysSem);
return -1;
}
/*-------------------------------------------------------------------*/
/* Acquire exclusive access to lower file system. */
/*-------------------------------------------------------------------*/
file->acquire(file, F_READ | F_WRITE);
/*-------------------------------------------------------------------*/
/* Call file system specific FSEEK routine. */
/*-------------------------------------------------------------------*/
rc = (off_t)file->ioctl(file, FSEEK, (long)offset, whence);
/*-------------------------------------------------------------------*/
/* Release exclusive access to file systems and return result. */
/*-------------------------------------------------------------------*/
file->release(file, F_READ | F_WRITE);
semPost(FileSysSem);
return rc;
}
示例2: fcntl
int fcntl(int fid, int cmd, ...)
{
va_list ap;
FILE *file;
#if OS_PARM_CHECK
/*-------------------------------------------------------------------*/
/* If the file descriptor is invalid, return error. */
/*-------------------------------------------------------------------*/
if (fid < 0 || fid >= FOPEN_MAX)
{
set_errno(EBADF);
return -1;
}
#endif
/*-------------------------------------------------------------------*/
/* Get exclusive access to upper file system. */
/*-------------------------------------------------------------------*/
semPend(FileSysSem, WAIT_FOREVER);
/*-------------------------------------------------------------------*/
/* Return error if file is closed. */
/*-------------------------------------------------------------------*/
file = &Files[fid];
if (file->ioctl == NULL)
{
semPost(FileSysSem);
set_errno(EBADF);
return -1;
}
/*-------------------------------------------------------------------*/
/* Based on the command, execute the right instructions. */
/*-------------------------------------------------------------------*/
switch (cmd)
{
case F_DUPFD:
{
/*---------------------------------------------------------------*/
/* Use the va_arg mechanism to get the argument. */
/*---------------------------------------------------------------*/
va_start(ap, cmd);
fid = va_arg(ap, int);
va_end(ap);
#if OS_PARM_CHECK
/*---------------------------------------------------------------*/
/* If the file descriptor is invalid, return error. */
/*---------------------------------------------------------------*/
if (fid < 0 || fid >= FOPEN_MAX)
{
semPost(FileSysSem);
set_errno(EINVAL);
return -1;
}
#endif
/*---------------------------------------------------------------*/
/* Look for free file control block identifier >= fid. */
/*---------------------------------------------------------------*/
for (;;)
{
FILE *file2 = &Files[fid];
/*-------------------------------------------------------------*/
/* Check if file control block is free. */
/*-------------------------------------------------------------*/
if (file2->ioctl == NULL)
{
/*-----------------------------------------------------------*/
/* Copy previous file control block to new one. */
/*-----------------------------------------------------------*/
*file2 = *file;
/*-----------------------------------------------------------*/
/* Acquire exclusive access to lower file system. */
/*-----------------------------------------------------------*/
file2->acquire(file2, F_READ | F_WRITE);
/*-----------------------------------------------------------*/
/* Call file system specific DUP routine. */
/*-----------------------------------------------------------*/
file2->ioctl(file2, DUP);
/*-----------------------------------------------------------*/
/* Release exclusive access to lower file system. */
/*-----------------------------------------------------------*/
file2->release(file2, F_READ | F_WRITE);
break;
}
/*-------------------------------------------------------------*/
/* If none are free, set errno and break. */
/*-------------------------------------------------------------*/
if (++fid >= FOPEN_MAX)
{
set_errno(EMFILE);
fid = -1;
break;
}
//.........这里部分代码省略.........
示例3: creatn
int creatn(const char *path, mode_t mode, size_t size)
{
int rv = -1;
void *dir;
FILE *file;
#if !_PATH_NO_TRUNC
char trunc_path[PATH_MAX + 1];
#endif
#if OS_PARM_CHECK
/*-------------------------------------------------------------------*/
/* If path is NULL, return -1. */
/*-------------------------------------------------------------------*/
if (path == NULL)
{
set_errno(EFAULT);
return -1;
}
#endif
/*-------------------------------------------------------------------*/
/* Acquire exclusive access to upper file system. */
/*-------------------------------------------------------------------*/
semPend(FileSysSem, WAIT_FOREVER);
/*-------------------------------------------------------------------*/
/* Find a free file control block and initialize it. */
/*-------------------------------------------------------------------*/
for (file = &Files[0]; file->ioctl; ++file)
{
/*-----------------------------------------------------------------*/
/* If none are free, return error. */
/*-----------------------------------------------------------------*/
if (file == &Files[FOPEN_MAX - 1])
{
set_errno(EMFILE);
semPost(FileSysSem);
return -1;
}
}
FsInitFCB(file, FCB_FILE);
/*-------------------------------------------------------------------*/
/* Ensure path is valid. */
/*-------------------------------------------------------------------*/
dir = FSearch(file, &path, PARENT_DIR);
if (dir == NULL)
goto end;
/*-------------------------------------------------------------------*/
/* If path too long, return error if no truncation, else truncate. */
/*-------------------------------------------------------------------*/
if (strlen(path) > PATH_MAX)
{
#if _PATH_NO_TRUNC
set_errno(ENAMETOOLONG);
goto end;
#else
strncpy(trunc_path, path, PATH_MAX);
trunc_path[PATH_MAX] = '\0';
path = trunc_path;
#endif
}
/*-------------------------------------------------------------------*/
/* Acquire exclusive access to lower file system. */
/*-------------------------------------------------------------------*/
file->acquire(file, F_READ | F_WRITE);
/*-------------------------------------------------------------------*/
/* Call file system specific CREATN routine. */
/*-------------------------------------------------------------------*/
rv = (int)file->ioctl(file, CREATN, path, mode, size, dir);
/*-------------------------------------------------------------------*/
/* Release exclusive access to lower file system. */
/*-------------------------------------------------------------------*/
file->release(file, F_READ | F_WRITE);
/*-------------------------------------------------------------------*/
/* Free control block if error, else set return value. */
/*-------------------------------------------------------------------*/
end:
if (rv == -1)
file->ioctl = NULL;
else
rv = file - &Files[0];
/*-------------------------------------------------------------------*/
/* Release exclusive access to upper file system and return result. */
/*-------------------------------------------------------------------*/
semPost(FileSysSem);
return rv;
}