[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

#include <stdio.h> #include <sys/types.h> #include

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

File: 1466732852437.jpg (4KB, 238x195px) Image search: [Google]
1466732852437.jpg
4KB, 238x195px
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

int main(void) {

int proc_cpuinfo_fd = open("/proc/cpuinfo", O_RDONLY);

if (proc_cpuinfo_fd) {
char *proc_cpuinfo = malloc(2048);
if (proc_cpuinfo != NULL) {

if (read(proc_cpuinfo_fd, proc_cpuinfo, 2047) < 0) {
printf("Read failed");
return 1;
}

*(proc_cpuinfo+2048) = '\0';

char *model = strstr(proc_cpuinfo, "model name");
int count = 0;
char *start = model;

if (model != NULL) {

model += 13; /* model name\t : <model> */
start += 13;

while (*model != '\n') {
count++;
model++;
}
}

if (write(STDOUT_FILENO, start, count) < 0) {
perror("stdout");
return 1;
}

printf("\n");

free(proc_cpuinfo);

return 0;

}
} else {
perror("file");
return -1;
}
}


Could someone compile this and see if it runs fine on your system?

Should print

thinkpad :: ~ % gcc -g -Wall -Wextra test.c -o test                                                                                                                                                                                         
thinkpad :: ~ % ./test
Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz
>>
>>55833627
Nice error checking and out-of-bounds write you mongoloid. kys.
>>
>>55833701
Instead of bashing my head in with memes, why don't you help. What is wrong with the write?
>>
>>55833777
>allocate 2048 bytes
>write null character in 2049th byte

Also, unless you're expecting massive recursion or enterprise Java -tier architecture clusterfucks you can just allocate your 2 kilobytes from the stack.
>>
>>55833627
It really abuses me when people have most of their function indented in an if switch that doesn't need to be there. Why not if (x = NULL) return -1;
>>
>>55834316
>if (x = NULL)
Dun goofed fag
>>
>>55834316
fucking this
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.