summaryrefslogtreecommitdiff
path: root/UICaboodle
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2008-12-10 12:34:44 +0000
committerJay Freeman (saurik) <saurik@saurik.com>2010-09-30 07:09:14 +0000
commit0adc554ba6925144bab4bcd29fd2371a032cb458 (patch)
treeaeecf3ac4832e7dbecc8a5f69f8990ffb7ea1074 /UICaboodle
parent59c011d87e67a2b7a44bf70576c7fa10e85698bc (diff)
Finished implementing Storage.
Diffstat (limited to 'UICaboodle')
-rw-r--r--UICaboodle/BrowserView.m29
1 files changed, 25 insertions, 4 deletions
diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m
index cb16bc8..93e253b 100644
--- a/UICaboodle/BrowserView.m
+++ b/UICaboodle/BrowserView.m
@@ -240,8 +240,22 @@
- (NSNumber *) du:(NSString *)path {
NSNumber *value(nil);
- /* XXX: omfg this is stupid */
- if (FILE *du = popen([[@"du -s " stringByAppendingString:path] UTF8String], "r")) {
+ int fds[2];
+ _assert(pipe(fds) != -1);
+
+ pid_t pid(ExecFork());
+ if (pid == 0) {
+ _assert(dup2(fds[1], 1) != -1);
+ _assert(close(fds[0]) != -1);
+ _assert(close(fds[1]) != -1);
+ execlp("du", "du", "-s", [path UTF8String], NULL);
+ exit(1);
+ _assert(false);
+ }
+
+ _assert(close(fds[1]) != -1);
+
+ if (FILE *du = fdopen(fds[0], "r")) {
char line[1024];
while (fgets(line, sizeof(line), du) != NULL) {
size_t length(strlen(line));
@@ -253,8 +267,15 @@
}
}
- pclose(du);
- }
+ fclose(du);
+ } else _assert(close(fds[0]));
+
+ int status;
+ wait:
+ if (waitpid(pid, &status, 0) == -1)
+ if (errno == EINTR)
+ goto wait;
+ else _assert(false);
return value;
}