Skip to content

Commit

Permalink
Merge pull request #262 from akgrant43/unixFileDescriptorType
Browse files Browse the repository at this point in the history
sqFilePluginBasicPrims.c add sqFileDescriptorType()

Add the Unix implementation of sqFileDescriptorType() to answer an
enumerated type indicating whether the supplied file descriptor is a
terminal, pipe or file.

The Windows implementation was added 15 May 2018 in commit 858bed2.
  • Loading branch information
akgrant43 committed May 17, 2018
2 parents d0c7f21 + d997f35 commit be591fd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Expand Up @@ -582,8 +582,19 @@ sqFileStdioHandlesInto(SQFile files[])
* 4 - cygwin terminal (windows only)
*/
sqInt sqFileDescriptorType(int fdNum) {
/* TODO Implement the unix version */
return isatty(fdNum);
int status;
struct stat statBuf;

/* Is this a terminal? */
if (isatty(fdNum)) return 1;

/* Is this a pipe? */
status = fstat(fdNum, &statBuf);
if (status) return -1;
if (S_ISFIFO(statBuf.st_mode)) return 2;

/* Must be a normal file */
return 3;
}


Expand Down

0 comments on commit be591fd

Please sign in to comment.