/tech/ - Technology

Buffer Overflow

Index Catalog Archive Bottom Refresh
+
-
Options
Subject
Message

Max message length: 0/12000

files

Max file size: 32.00 MB

Total max file size: 50.00 MB

Max files: 5

Supported file types: GIF, JPG, PNG, WebM, OGG, and more

E-mail
Password

(used to delete files and posts)

Misc

Remember to follow the Rules

The backup domains are located at 8chan.se and 8chan.cc. TOR access can be found here, or you can access the TOR portal from the clearnet at Redchannit 3.0.

.se is back up
.moe has intermittent downtime due to DDoS

Archival System Enabled
No More Thread Transfers


8chan.moe is a hobby project with no affiliation whatsoever to the administration of any other "8chan" site, past or present.

(68.26 KB 602x400 coding-with-my-bros.jpg)

made my own ls Anonymous 04/26/2025 (Sat) 20:44:25 Id: 5fa3ed No. 54
Am I leet yet (only supports one argument because minimalism or something like that) (I didn't write argbegin) #include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #include <pwd.h> #include <grp.h> #include <time.h> #include "arg.h" static int show_hidden = 0, big_list = 0; __attribute__((noreturn)) void usage(void) { fprintf(stderr, "Usage: ls [-al]\n"); exit(1); } static int sel(const struct dirent *file) { if(!show_hidden) { if(file->d_name[0] == '.') return 0; } return 1; } int main(int argc, char **argv) { int n; const char *dir; struct dirent **lst; ARGBEGIN { case 'a': show_hidden = 1; break; case 'l': big_list = 1; break; default: usage(); break; } ARGEND
[Expand Post] if(argc == 0) dir = "."; else dir = argv[1]; n = scandir(dir, &lst, sel, alphasort); for(int i = 0; i < n; i++) { if(big_list) { int s; struct stat st; char perm[] = "----------"; struct passwd *user; struct group *group; char date[20], *datefmt; stat(lst[i]->d_name, &st); const struct tm *tm; if(lst[i]->d_type == DT_DIR) perm[0] = 'd'; if(st.st_mode & S_IRUSR) perm[1] = 'r'; if(st.st_mode & S_IWUSR) perm[2] = 'w'; if(st.st_mode & S_IXUSR) perm[3] = 'x'; if(st.st_mode & S_IRGRP) perm[4] = 'r'; if(st.st_mode & S_IWGRP) perm[5] = 'w'; if(st.st_mode & S_IXGRP) perm[6] = 'x'; if(st.st_mode & S_IROTH) perm[7] = 'r'; if(st.st_mode & S_IWOTH) perm[8] = 'w'; if(st.st_mode & S_IXOTH) perm[9] = 'x'; user = getpwuid(st.st_uid); group = getgrgid(st.st_gid); if (time(NULL) > st.st_mtim.tv_sec + (180 * 24 * 60 * 60)) datefmt = "%b %d %Y"; else datefmt = "%b %d %H:%M"; tm = localtime(&st.st_mtim.tv_sec); strftime(date, sizeof(date), datefmt, tm); printf("%s %4u %-8s %-8s %9d %s %s\n", perm, st.st_nlink, user->pw_name, group->gr_name, st.st_size, date, lst[i]->d_name); } else { printf("%s\n", lst[i]->d_name); } } }
Nice memory leak faget


Forms
Delete
Report
Quick Reply
Drag files here to upload or
click here to select them