Posts

Showing posts with the label stdin

Is it possible to upload a file with cURL from a pipe?

Is it possible to upload a file with cURL from a pipe? I mean POSTing a standard file upload form. Usual command line contains this switch in this case: -F "Filedata=@filename.zip" However when I try to feed a named pipe made by linux command "mkfifo", eg. "mkfifo filename.zip", I always get an error message on the producer side: curl: (23) Failed writing body (1856 != 16384) And also some error message appears at consumer side of the fifo. I fed my fifo with another curl command on producer side, eg.: curl http://example.com/archive.zip > filename.zip And on consumer side: curl http://example.com/fileupload.php -F "file=@filename.zip" When I pass a Content-Length HTTP header at the consumer side of my fifo, I don't get error message at the producer side, but error message still appears at the consumer (uploading) side, unsuccessful upload. curl http://example.com/fileupload.php -F "file=@filename.zip" -H "Content-Length: ...

C read binary stdin

C read binary stdin I'm trying to build an instruction pipeline simulator and I'm having a lot of trouble getting started. What I need to do is read binary from stdin, and then store it in memory somehow while I manipulate the data. I need to read in chunks of exactly 32 bits one after the other. How do I read in chunks of exactly 32 bits at a time? Secondly, how do I store it for manipulation later? Here's what I've got so far, but examining the binary chunks I read further, it just doesn't look right, I don't think I'm reading exactly 32 bits like I need. char buffer[4] = { 0 }; // initialize to 0 unsigned long c = 0; int bytesize = 4; // read in 32 bits while (fgets(buffer, bytesize, stdin)) { memcpy(&c, buffer, bytesize); // copy the data to a more usable structure for bit manipulation later // more stuff buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0; // set to zero before next loop } fclose(stdin); How do I read in 32 bits at a ti...