Is there a replacement for unistd.h for Windows (Visual C)?

I’m porting a relatively simple console program written for Unix to the Windows platform (Visual C++ 8.0). All the source files include “unistd.h”, which doesn’t exist. Removing it, I get complaints about misssing prototypes for ‘srandom’, ‘random’, and ‘getopt’. I know I can replace the random functions, and I’m pretty sure I can find/hack-up a … Read more

Why does glibc’s strlen need to be so complicated to run quickly?

I was looking through the strlen code here and I was wondering if the optimizations used in the code are really needed? For example, why wouldn’t something like the following work equally good or better? unsigned long strlen(char s[]) { unsigned long i; for (i = 0; s[i] != ‘\0’; i++) continue; return i; } … Read more

Is there a portable way to get the current username in Python?

What is a portable way (e.g. for Linux and Windows) to get the current user’s username? Something similar to os.getuid() would be nice: >>> os.getuid() 42 >>> os.getusername() ‘slartibartfast’ The pwd module works for Unix only. Some people suggest that getting the username under Windows can be complicated in certain circumstances (e.g., running as a … Read more

How do SO_REUSEADDR and SO_REUSEPORT differ?

The man pages and programmer documentations for the socket options SO_REUSEADDR and SO_REUSEPORT are different for different operating systems and often highly confusing. Some operating systems don’t even have the option SO_REUSEPORT. The WEB is full of contradicting information regarding this subject and often you can find information that is only true for one socket … Read more