I am trying to implement my own version of clock() using asm and rdtsc. However I am quite unsure about its return value. Is it cycles? Oder is it micro seconds?
I am also confused about CLOCKS_PER_SEC. How can this be constant?
Is there any kind…
I'm currently struggling with clang++, and after looking on the web for a long time I decided asking my question. I'm on OS X and using clang++ via Emacs (it's used by flycheck to highlight errors, among other things). I have a very simple file that…
I am trying to use pread and pwrite so that I can lseek to the beginning of the file and start reading or writing in one atomic operation. Both of these functions will do that for me however, the issue I am having is that the compiler is giving me…
I have used syscalls read() and write() in my program WITHOUT including "unistd.h" header file in the program. But still the program works and gives expected results.
After running the program, i thought i will read the man page for read() and…
I am now trying to understand how read(2) function works by looking into the actual code implementation and first, I try to see how it is defined in #include header file.
In that file, I found this :
ssize_t read(int, void *, size_t)…
in unistd.h
using open() with the O_APPEND flag gives atomic writes always to the end of the file...
this is great and all, but what if i need to know the offset at which it atomically appended to the file...?
i realize O_APPEND is often used for…
I am trying to write into a file using the write() function (included in ). The program is simple: when running the executable, I type a message and then, the message and my user id (Linux UID) are saved into the file.
$ ./notetaker…
In the following snippet, no matter how long of an input I put in (EDIT: I'm copy and pasting in a random string), say a string with 9998 characters, read() stops when i = 4095. It states it read in an EOF character, but my string does not have an…
I have a problem when I create a file in Linux it makes my file write-protected and I don't know why it does that.
void fileOperation::openFileWrite(char x, off_t s)
{
int fd;
char c[2] = {x};
fd = open("/home/stud/txtFile", O_CREAT |…
I have a C++ File class with read function, that is supposed to read whole contents of a file (just like Python does) into a buffer. However, when I tried to call read function from unistd.h, I get:
file.cpp:21: error: no matching function for call…
If i input paths with wildcards as command line parameters, like:
testprogramm a* b*
and the directory contains the following content:
aa ab ba bb
my argv string will contain:
{"testprogramm","aa","ab","ba","bb"}
However, i want to differentiate…
I was trying to read input from the terminal using read() in a while loop as a condition, but the code doesn't get executed until the loop ends.
Here is my code:
#include
int main(void)
{
char ch;
while(read(STDIN_FILENO,&ch,1) ==…
I want to learn to implement the function like cat, which just take input from a file and print to stdout.
But I am not sure the line of write() is robust in all cases as it may write less than n. But I am not able to create a test case to make this…
I love getopt to parse options from the argv argument. Unfortunately I'm not able to make getopt parse options that are between nonoptions or at the end of argv. Example Program:
#include
#include
int o_help = 0;
int main(int…
I was trying to Implement my own printf function and I discovered this strange behavior, when you try to print something using printf() and after it you try to print something else using write(), the output of write() is printed before the output of…