Skip to content

Mac ioctl#405

Open
systemcrash wants to merge 2 commits intojow-:masterfrom
systemcrash:mac_ioctl
Open

Mac ioctl#405
systemcrash wants to merge 2 commits intojow-:masterfrom
systemcrash:mac_ioctl

Conversation

@systemcrash
Copy link
Copy Markdown
Contributor

Provide ioctl on mac.

macOS/Darwin has ioctl, but the mappings are a bit different.

Verified using:

import * as io from 'io';
import * as struct from 'struct';

let handle = io.open('/dev/tty', io.O_RDWR);
if (!handle) {
	print('open failed:', io.error(), '\n');
	return;
}

let req = 0x40087468;   // macOS TIOCGWINSZ raw request
let buf = handle.ioctl(io.IOC_DIR_READ, req, 0, 8);
if (!buf) {
	print('ioctl failed:', io.error(), '\n');
}

/*
struct winsize {
	unsigned short ws_row;
	unsigned short ws_col;
	unsigned short ws_xpixel;
	unsigned short ws_ypixel;
};
*/
let arr = struct.unpack('HHHH', buf);

print('winsize:\n');
print('  rows:   ', arr[0], '\n');
print('  cols:   ', arr[1], '\n');
print('  xpixel: ', arr[2], '\n');
print('  ypixel: ', arr[3], '\n');

handle.close();

result:

winsize:
  rows:   71
  cols:   183
  xpixel: 2562
  ypixel: 1846

ioctl is available on macOS, but the call mappings and encodings
differ.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
ioctl is available on macOS, but the call mappings and encodings
differ.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant