⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iolib.c

📁 VxWorks操作系统内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        while (bytesToWrite > 0)            {            if ((bytesWritten = iosWrite (fd, pData, bytesToWrite)) == ERROR)                {                if (totalBytesWritten > 0)                    return (totalBytesWritten);                else                    return (ERROR);                }            totalBytesWritten += bytesWritten;            bytesToWrite -= bytesWritten;            pData += bytesWritten;            }        }    return (totalBytesWritten);    }/********************************************************************************* ioFullFileNameGet - resolve path name to device and full file name** This routine resolves the specified path name into a device and full* filename on that device.  If the specified path name is not a full,* absolute path name, then it is concatenated to the current default* path to derive a full path name.  This full path name is separated* into the device specification and the remaining filename on that device.* A pointer to the device header is returned in <ppDevHdr> and the* filename on that device is returned in <fullFileName>.** RETURNS:* OK, or* ERROR if the full filename has more than MAX_FILENAME_LENGTH characters.** NOMANUAL*/STATUS ioFullFileNameGet    (    char *	pathName,	/* path name */    DEV_HDR **		ppDevHdr,	/* ptr to dev hdr to complete */    char *		fullFileName	/* resulting complete filename */    )    {    char *pTail;    char fullPathName [MAX_FILENAME_LENGTH];    bzero (fullPathName, MAX_FILENAME_LENGTH);  /* initialize buffer to 0 */    /* resolve default path plus partial pathname to full path name */    if (pathCat (ioDefPath, pathName, fullPathName) == ERROR)	return (ERROR);    /* remove device name from full path name */    if ((*ppDevHdr = iosDevFind (fullPathName, &pTail)) == NULL)	return (ERROR);    strncpy (fullFileName, pTail, MAX_FILENAME_LENGTH);    return (OK);    }/********************************************************************************* ioDefPathSet - set the current default path** This routine sets the default I/O path.  All relative pathnames specified* to the I/O system will be prepended with this pathname.  This pathname* must be an absolute pathname, i.e., <name> must begin with an existing* device name.** RETURNS:* OK, or ERROR if the first component of the pathname is not an existing* device.** SEE ALSO: ioDefPathGet(), chdir(), getcwd()*/STATUS ioDefPathSet    (    char *name          /* name of the new default device and path */    )    {    char *pTail = name;    if (iosDevFind (name, &pTail) == NULL)	return (ERROR);    if (pTail == name)	{	/* name does not begin with an existing device's name */	errnoSet (S_ioLib_NO_DEVICE_NAME_IN_PATH);	return (ERROR);	}    if (strlen (name) >= MAX_FILENAME_LENGTH)	{	errnoSet (S_ioLib_NAME_TOO_LONG);	return (ERROR);	}    strcpy (ioDefPath, name);    return (OK);    }/********************************************************************************* ioDefPathGet - get the current default path** This routine copies the name of the current default path to <pathname>.* The parameter <pathname> should be MAX_FILENAME_LENGTH characters long.** RETURNS: N/A** SEE ALSO: ioDefPathSet(), chdir(), getcwd()*/void ioDefPathGet    (    char *pathname              /* where to return the name */    )    {    strcpy (pathname, ioDefPath);    }/********************************************************************************* chdir - set the current default path** This routine sets the default I/O path.  All relative pathnames specified* to the I/O system will be prepended with this pathname.  This pathname* must be an absolute pathname, i.e., <name> must begin with an existing* device name.** RETURNS:* OK, or ERROR if the first component of the pathname is not an existing device.** SEE ALSO: ioDefPathSet(), ioDefPathGet(), getcwd()*/STATUS chdir    (    char *pathname      /* name of the new default path */    )    {    return (ioDefPathSet (pathname));    }/********************************************************************************* getcwd - get the current default path (POSIX)** This routine copies the name of the current default path to <buffer>.* It provides the same functionality as ioDefPathGet() and* is provided for POSIX compatibility.** RETURNS:* A pointer to the supplied buffer, or NULL if <size> is too small to hold* the current default path.** SEE ALSO: ioDefPathSet(), ioDefPathGet(), chdir()*/char *getcwd    (    char *buffer,       /* where to return the pathname */    int  size           /* size in bytes of buffer      */    )    {    if (size <= 0)	{	errnoSet (EINVAL);	return (NULL);	}    if (size < strlen (ioDefPath) + 1)	{	errnoSet (ERANGE);	return (NULL);	}    strcpy (buffer, ioDefPath);    return (buffer);    }/********************************************************************************* getwd - get the current default path** This routine copies the name of the current default path to <pathname>.* It provides the same functionality as ioDefPathGet() and getcwd().* It is provided for compatibility with some older UNIX systems.** The parameter <pathname> should be MAX_FILENAME_LENGTH characters long.** RETURNS: A pointer to the resulting path name.*/char *getwd    (    char *pathname      /* where to return the pathname */    )    {    strcpy (pathname, ioDefPath);    return (pathname);    }/********************************************************************************* ioDefPathCat - concatenate to current default path** This routine changes the current default path to include the specified* <name>.  If <name> is itself an absolute pathname beginning with* a device name, then it becomes the new default path.  Otherwise <name>* is appended to the current default path in accordance with the rules* of concatenating path names.** RETURNS:* OK, or* ERROR if a valid pathname cannot be derived from the specified name.** NOMANUAL*/STATUS ioDefPathCat    (    char *name          /* path to be concatenated to current path */    )    {    char newPath [MAX_FILENAME_LENGTH];    char *pTail;    /* interpret specified path in terms of current default path */    if (pathCat (ioDefPath, name, newPath) == ERROR)	return (ERROR);    /* make sure that new path starts with a device name */    iosDevFind (newPath, &pTail);    if (pTail == newPath)	{	errnoSet (S_ioLib_NO_DEVICE_NAME_IN_PATH);	return (ERROR);	}    pathCondense (newPath);	/* resolve ".."s, "."s, etc */    strncpy (ioDefPath, newPath, MAX_FILENAME_LENGTH);    return (OK);    }/********************************************************************************* ioDefDevGet - get current default device** This routine copies the name of the device associated with the current* default pathname to <devName>.** NOTE: This routine was public in 4.0.2 but is obsolete.  It is made* no-manual in 5.0 and should be removed in the next release.** NOMANUAL*/void ioDefDevGet    (    char *devName               /* where to return the device name */    )    {    DEV_HDR *pDevHdr;	/* pointer to device header */    char *pTail;    /* find the device of the default pathname */    if ((pDevHdr = iosDevFind (ioDefPath, &pTail)) == NULL)	{	*devName = EOS;		/* no default device, return null device name */	}    else	{	strcpy (devName, pDevHdr->name);	/* return device name */	}    }/********************************************************************************* ioDefDirGet - get current default directory** This routine copies the current default directory to <dirName>.* The current default directory is derived from the current default* pathname minus the leading device name.** <dirname> should be MAX_FILENAME_LENGTH characters long.** NOTE: This routine was public in 4.0.2 but is obsolete.  It is made* no-manual in 5.0 and should be removed in the next release.** NOMANUAL*/void ioDefDirGet    (    char *dirName               /* where to return the directory name */    )    {    char *pTail;    /* find the directory name in the default path name */    if (iosDevFind (ioDefPath, &pTail) == NULL)	{	*dirName = EOS;	/* no default device, return null directory name */	}    else	{	strcpy (dirName, pTail);	}    }/********************************************************************************* ioGlobalStdSet - set the file descriptor for global standard input/output/error** This routine changes the assignment of a specified global standard file* descriptor <stdFd> (0, 1, or, 2) to the specified underlying file* descriptor <newFd>.  <newFd> should be a file descriptor open to the* desired device or file.  All tasks will use this new assignment when doing* I/O to <stdFd>, unless they have specified a task-specific standard file* descriptor (see ioTaskStdSet()).  If <stdFd> is not 0, 1, or 2, this* routine has no effect.** RETURNS: N/A** SEE ALSO: ioGlobalStdGet(), ioTaskStdSet()*/void ioGlobalStdSet    (    int stdFd,  /* std input (0), output (1), or error (2) */    int newFd   /* new underlying file descriptor          */    )    {    if (STD_VALID (stdFd))	ioStdFd [stdFd] = newFd;    }/********************************************************************************* ioGlobalStdGet - get the file descriptor for global standard input/output/error** This routine returns the current underlying file descriptor for global * standard input, output, and error.** RETURNS:* The underlying global file descriptor, or ERROR if <stdFd> is not 0, 1, or 2.** SEE ALSO: ioGlobalStdSet(), ioTaskStdGet()*/int ioGlobalStdGet    (    int stdFd   /* std input (0), output (1), or error (2) */    )    {    return (STD_VALID (stdFd) ? ioStdFd [stdFd] : ERROR);    }/********************************************************************************* ioTaskStdSet - set the file descriptor for task standard input/output/error** This routine changes the assignment of a specified task-specific standard* file descriptor <stdFd> (0, 1, or, 2) to the specified underlying file* descriptor<newFd>.  <newFd> should be a file descriptor open to the* desired device or file.  The calling task will use this new assignment* when doing I/O to <stdFd>, instead of the system-wide global assignment* which is used by default.  If <stdFd> is not 0, 1, or 2, this routine has* no effect.** NOTE: This routine has no effect if it is called at interrupt level.** RETURNS: N/A** SEE ALSO: ioGlobalStdGet(), ioTaskStdGet()*/void ioTaskStdSet    (    int taskId, /* task whose std fd is to be set (0 = self) */    int stdFd,  /* std input (0), output (1), or error (2)   */    int newFd   /* new underlying file descriptor            */    )    {    WIND_TCB *pTcb;    if (STD_VALID (stdFd) && (pTcb = taskTcb (taskId)) != NULL)	pTcb->taskStd [stdFd] = newFd;    }/********************************************************************************* ioTaskStdGet - get the file descriptor for task standard input/output/error** This routine returns the current underlying file descriptor for task-specific* standard input, output, and error.** RETURNS:* The underlying file descriptor, or ERROR if <stdFd> is not 0, 1, or 2, or* the routine is called at interrupt level.** SEE ALSO: ioGlobalStdGet(), ioTaskStdSet()*/int ioTaskStdGet    (    int taskId, /* ID of desired task (0 = self)           */    int stdFd   /* std input (0), output (1), or error (2) */    )    {    WIND_TCB *pTcb;    int taskFd;    if (STD_VALID (stdFd) && (pTcb = taskTcb (taskId)) != NULL)	{	taskFd = pTcb->taskStd [stdFd];	if (STD_VALID (taskFd))	    return (ioStdFd [taskFd]);	else	    return (taskFd);	}    return (ERROR);    }/********************************************************************************* isatty - return whether the underlying driver is a tty device** This routine simply invokes the ioctl() function FIOISATTY on the* specified file descriptor.** RETURNS: TRUE, or FALSE if the driver does not indicate a tty device.*/BOOL isatty    (    int fd      /* file descriptor to check */    )    {    return (ioctl (fd, FIOISATTY, 0 /*XXX*/) == TRUE);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -