File.chardev? for Win32

D

Daniel Berger

Hi all,

According to the MSDN docs, the _isatty() function will return true
for any character device (terminal, console, printer, or serial port).
Thus, this works as expected:

File.new("NUL").isatty # true

But this doesn't:

File.chardev?("NUL") # false

I've provided some sample C code below. I can add this into
win32-file, but I'd like to see it corrected in core Ruby.

Also, does anyone know how to detect a block device on Win32?

Regards,

Dan

/* chardev test */
#include <stdio.h>
#include <io.h>

int main(){
FILE *fd;

// Also works with "aux", etc
if( (fd = fopen("NUL","r")) == NULL){
printf("Failed!\n");
return -1;
}

if(_isatty(_fileno(fd))){
printf("Char device!\n"); // True
}

fclose(fd);

printf("done\n");
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,432
Latest member
GTRNorbert

Latest Threads

Top