posix

Dynamic Linking in C (lib*.so) library

I have written a code where in it would take in a executable file and the [lib*.so] library as my arguments and link @ Run-time. I want to also take in the function in the (*.o) file @ run-time and link it. But I don't know how to go about it. EDIT 1: The function I'm trying to link is a part of the .o file in the lib*.so library. So I...

Equivalent to pread/pwrite in MSVC?

What calls best emulate pread/pwrite in MSVC 10? ...

Zombie processes......

I'v some questions about zombie processes what the benefits from zombie process concept? know that the kernel keeps (PID,termination status, resource usage information) for zombie process what's the meaning of "resource usage information" how zombie's PPID() = 1 and it still zombie , (init reaps Zombies because it wait() by default) ...

Why does bash in posix mode fail to chase my symlinks?

I'm seeing weird behavior when I run "ssh " to a Linux system. I tracked it down part way to a difference in bash when started in posix mode. % bash --posix % ln -s /tmp mytmp % cd mytmp % pwd /home/user/mytmp The bash man page has these items under posix mode: --> When the cd builtin is invoked in logical mode, and the pathname con...

Best way to provide options for specifying NIC, determining IP on subnet?

I am writing a C library which involves telling other computers on the subnet to send me messages. Therefore I must announce to them my IP address. This library should work on Linux, OS X and Windows. Currently I'm thinking mostly about the POSIX layer. Given that a computer can have more than one address (for example if it has more ...

What is select supposed to do if you close a monitored fd?

I can test this to find the behavior but that's not the point. In my answer to another question, a commenter recommended closing a monitored fd from another thread to wake up select. Another commenter couldn't find a reference to this behavior in the standard, and I can't find one either. Can someone provide a pointer to the standard on...

How to determine (using C API) the system's default NIC?

In Linux, after establishing a DHCP lease, when I run the command route, the last line gives me the system's default route and NIC. e.g., Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use IFace 142.157.138.0 * 255.255.254.0 U 2 0 0 wlan0 link-local * ...

POSIX Sockets; Deciphering Hostname from sockaddr_in structure

Hi. Is it possible to decipher the hostname given the sockaddr_in strucure? struct sockaddr_in { short sin_family; // e.g. AF_INET, AF_INET6 unsigned short sin_port; // e.g. htons(3490) struct in_addr sin_addr; // see struct in_addr, below char sin_zero[8]; // zero this if you want ...

How to obtain total available disk space in Posix systems?

Hi! I'm writing a cross-platform application, and I need the total available disk space. For posix systems (Linux and Macos) I'm using statvfs. I created this C++ method: long OSSpecificPosix::getFreeDiskSpace(const char* absoluteFilePath) { struct statvfs buf; if (!statvfs(absoluteFilePath, &buf)) { unsigned long blksize, ...

Does posix aio in linux 2.6 support socket file descriptor?

I've seached such question in google and got different answers.I cann't determine whether posix aio in linux 2.6 support socket file descriptor or not. if it support tcp socket,does the aiocb.aio_offset=0 relative to the first byte readed from the tcp socket fd? if it doesn't,does any asynchronous io library in linux support socket fd?...

How much overhead is there when creating a thread?

Hey all, I just reviewed some really terrible code - code that sends messages on a serial port by creating a new thread to package and assemble the message in a new thread for every single message sent. Yes, for every message a pthread is created, bits are properly set up, then the thread terminates. I haven't a clue why anyone would do...

What are the threading semantics for Cocoa file ops? e.g. NSData read/write methods

If I have two threads in my Cocoa app, and (let's say), I'm reading from file X on the disk with an NSData +dataWithContentsOfFile:, and another thread is concurrently updating or replacing that same file X, with, say a -writeToPath:atomically:? I'm unfamiliar with what Cocoa's standard file read/writes modes are. Could the read operat...

POSIX seekdir() and telldir() behaviour after target folder modification

Hello, consider the following task : 1) read a target directory contents, pass each found dirent structure to some filter function and remember filtered elements somehow for the later processing 2) some time later, iterate through the filtered elements and process them (do some I/O) The most obvious way is to save names of sub-direc...

Standard Error and popen(): how to do it?

I want to open a process from C code, and be able to read its standard output and standard error, while being able to write to its standard input. The closest I get to achieving this is using popen(), but this does not allow you to read the standard error stream. You could add "2>&1" to the command, but this will not make it possible to...

Finding unique path name for a given input

I'm working on a problem where I need to have a way to convert a user inputted filename to a unique path name. Let's say I let the user specify a path name that points to a file that contains some data. I can then do Data* pData=Open(PathName). Now if the user specifies the same path name again, I'd like to be able to have a table of ...

What determines maximum local datagram size? (PF_UNIX / SOCK_DGRAM)

Can local message-based sockets transfer messages up to the SO_SNDBUF/SO_RCVBUF limits, or where can the so-called 'fixed maximum length' be determined for a descriptor created with socket(PF_UNIX, SOCK_SEQPACKET, 0) or socket(PF_UNIX, SOCK_DGRAM, 0)? ...

Does the function basename strip away the \n at the end of a path?

Does basename strip away \n at the end of path? For example basename("/home/user/apple\n") would basename return "apple\n" or "apple" without the \n? If basename doesn't get rid of the \n does anyone have any suggestions as to a means of getting rid of the \ ...

Obtaining the include paths cpp searches through

How do I obtain the system include search paths of the C preprocessor? This is for a script that parses arbitrary source files and needs to know the full pathnames of the headers they #include. Let's ignore for a moment that the user can alter this sequence of search paths with compiler flags. I'd prefer a solution that uses standard too...

Convert errno.h error values to Win32 GetLastError() equivalents

I'm writing a layer between a POSIX filesystem, and Windows using Dokan, and need to convert error values of the errno kind (EINVAL, ENOENT, etc.), to the Win32 equivalents you'd receive when calling GetLastError() (such as ERROR_INVALID_PARAMETER). Is there an existing function, library, or reference I can use to perform these conversi...

How to tell if a file handle is a socket?

I need to log socket usage, and I wrote a LD_PRELOAD library. The problem is when I override read() and write() than ordinary file operations are get logged too (of course). So how can I tell ordinary file descriptors and socket descriptors apart? ...