Conversation
Notices
-
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:00:38 JST Pleroma-tan really confused as to why this isnt working though, i just get a glibc memory corruption error
the copy code worked fine before..? i just put it into a function so i don't have to keep doing it constantly in other programs-
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:02:06 JST Pleroma-tan fuck, i might have to use memset for the null terminator -
Embed this notice
paula (paula@comp.lain.la)'s status on Friday, 24-Nov-2023 22:05:12 JST paula @kirby if that were the problem i'd be shocked Pleroma-tan likes this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:05:30 JST Pleroma-tan @paula so it's probably not then, i wonder why this function is fucking up -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:05:44 JST Pleroma-tan @paula [the file contents function] -
Embed this notice
ロミンちゃん (romin@shitposter.club)'s status on Friday, 24-Nov-2023 22:05:54 JST ロミンちゃん @kirby
>fuck, i might have to use memset for the null terminator
No that's good, your problem is, with ftell, you aren't checking if it's returning -1 (which most definitely is doing it, as the stream given by popen isn't seekable or rewindable)Pleroma-tan likes this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:06:17 JST Pleroma-tan @romin oh shit -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:08:12 JST Pleroma-tan @romin thank you, now i need to figure out how to read the stupid bullshit from popen properly -
Embed this notice
paula (paula@comp.lain.la)'s status on Friday, 24-Nov-2023 22:08:19 JST paula @kirby so clue, i took a look at it and doesn't seem to be any obvious errors
tho i'm still in bed and super eepyPleroma-tan likes this. -
Embed this notice
ロミンちゃん (romin@shitposter.club)'s status on Friday, 24-Nov-2023 22:09:33 JST ロミンちゃん @kirby you need to read on a loop, reallocating the buffer appropriately, until there's no more data left -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:10:20 JST Pleroma-tan @romin i love tediousness -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:11:11 JST Pleroma-tan @paula it didnt work because i was using a stream from popen which doesnt let u seek -
Embed this notice
paula (paula@comp.lain.la)'s status on Friday, 24-Nov-2023 22:11:12 JST paula @kirby yeah i really see no problem
you're saying if you copy paste the function instead of calling it, then it works? -
Embed this notice
ロミンちゃん (romin@shitposter.club)'s status on Friday, 24-Nov-2023 22:11:58 JST ロミンちゃん @kirby well you're coding in SEE, you get what you deserve Pleroma-tan likes this. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:12:19 JST Pleroma-tan @romin yes i do ロミンちゃん likes this. -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Friday, 24-Nov-2023 22:14:43 JST 翠星石 @kirby I'm not exactly sure what you're trying to do there.
If you want to open a file for reading and save it to a buffer for some reason, I would do;
#include <sys/stat.h>
FILE *fp = fopen("/home/chris/file", r);
//get filesize, will be in stat.st_size
struct stat stat;
stat(fp, &stat);
char *sneed = malloc(stat.st_size);
fread(sneed, 1, stat.st_size), 1, fp);
puts(sneed);
free(sneed);
fclose(fp);
But that's a terribly broken program, I reckon I can achieve what you want to do much cleaner with like 10 lines. -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Friday, 24-Nov-2023 22:16:17 JST 翠星石 @kirby The reason why the function is breaking is because you're telling it to open a folder as a file, or something else even more broken. -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:16:26 JST Pleroma-tan @Suiseiseki it's a test program because i want to see how popen works for another project im contributing to
this function works fine for most cases -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:16:53 JST Pleroma-tan @Suiseiseki not this case though because popen is fucking <i>gay</i> -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Friday, 24-Nov-2023 22:24:15 JST 翠星石 @kirby Dumping a file to stdout takes 5 lines;
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/sendfile.h>
int main()
{
/* open file */
int fp = open("main.c", O_RDONLY);
/* get file stats */
struct stat s;
fstat(fp, &s);
/* write file directly to stdout, with length from stat */
sendfile(fileno(stdout), fp, NULL, s.st_size);
close(fp);
} -
Embed this notice
Pleroma-tan (kirby@lab.nyanide.com)'s status on Friday, 24-Nov-2023 22:25:43 JST Pleroma-tan @Suiseiseki i just need to copy the contents of a file into a buffer not write it to stdout -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Friday, 24-Nov-2023 22:46:00 JST 翠星石 @kirby Okay, here you go;
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
/* open file */
int fp = open("main.c", O_RDONLY);
/* get file stats */
struct stat s;
fstat(fp, &s);
char buffer[s.st_size];
ssize_t ignored = read(fp, buffer, s.st_size);
close(fp);
ignored = write(STDOUT_FILENO, buffer, sizeof(buffer));
}Pleroma-tan likes this. -
Embed this notice
ロミンちゃん (romin@shitposter.club)'s status on Friday, 24-Nov-2023 22:51:16 JST ロミンちゃん @kirby @Suiseiseki execl("/bin/cp", "cp", "file1", "file2", (char *) NULL); :l_hehe;
Pleroma-tan likes this. -
Embed this notice
翠星石 (suiseiseki@freesoftwareextremist.com)'s status on Friday, 24-Nov-2023 22:59:37 JST 翠星石 @romin Ah yes, based GNU cp enjoyer.
Hmm, the rename(2) function is easy to get documentation on, but I wonder where's the copy(2) function?ロミンちゃん likes this. -
Embed this notice
Fifo™ (fifo@mastodon.fifo-f.eu)'s status on Saturday, 25-Nov-2023 09:57:06 JST Fifo™ @kirby nice hostname lol
-
Embed this notice