Permalink
Browse files

file.h: windows doesn't have F_GETFL.

  • Loading branch information...
orangea committed Jan 9, 2011
1 parent 7eec281 commit 866fb04ba5bd4ba7d6c0baf9926d02fd5b68579e
Showing with 7 additions and 0 deletions.
  1. +7 −0 core/file.c
View
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
+#include <sys/stat.h>
#include "potion.h"
#include "internal.h"
#include "table.h"
@@ -56,7 +57,13 @@ PN potion_file_with_fd(Potion *P, PN cl, PN self, PN fd) {
struct PNFile *file = (struct PNFile *)potion_object_new(P, PN_NIL, PN_VTABLE(PN_TFILE));
file->fd = PN_INT(fd);
file->path = PN_NIL;
+#ifdef F_GETFL
file->mode = fcntl(file->fd, F_GETFL) | O_ACCMODE;
+#else
+ struct stat st;
+ if (fstat(file->fd, &st) == -1) perror("fstat");
+ file->mode = st.st_mode;
+#endif
return (PN)file;
}

0 comments on commit 866fb04

Please sign in to comment.