Here's some text from my open(2) manpage: Transfer sizes, and the alignment of user buffer and file offset must all be multiples of the logical block size of the file system. It's unlikely that in practice you can get Python's sys.stdin.read() or os.read() to reliably use a buffer that fits the alignment restriction.
However, a small "C" extension could provide something like os.read() which *does* meet the restriction. The meat of it would look something like #define PAGESIZE 4096 // a guess which may be right for x86 linux #define REQUESTSIZE 1048576 ssize_t result; char *buf, *base; PyObject *pyresult; buf = malloc(bufsize, REQUESTSIZE + PAGESIZE - 1); base = round_up(buf, PAGESIZE); result = read(0, base, REQUESTSIZE); if(result == -1) { set python error from errno pyresult = NULL; goto DONE; } pyresult = PyString_FromStringAndSize(base, result); DONE: free(buf); return pyresult; Here's a clever but untested "C" macro that claims to implement round_up: #define round_up(amount, align) ((((amount) - 1) | ((align) - 1)) + 1) Jeff
pgpvapMvYEo9L.pgp
Description: PGP signature
-- http://mail.python.org/mailman/listinfo/python-list