Bläddra i källkod

feat: add std{in,out,err} macro def.

greatbridf 2 år sedan
förälder
incheckning
1446211242
3 ändrade filer med 10 tillägg och 3 borttagningar
  1. 7 0
      gblibc/include/unistd.h
  2. 1 1
      user-space-program/init.c
  3. 2 2
      user-space-program/sh.c

+ 7 - 0
gblibc/include/unistd.h

@@ -3,6 +3,13 @@
 
 #include <sys/types.h>
 
+#undef STDOUT_FILENO
+#undef STDIN_FILENO
+#undef STDERR_FILENO
+#define STDOUT_FILENO (0)
+#define STDIN_FILENO (0)
+#define STDERR_FILENO (0)
+
 #ifdef __cplusplus
 extern "C" {
 #endif

+ 1 - 1
user-space-program/init.c

@@ -3,7 +3,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 
-#define print(str) write(0, str, strlen(str))
+#define print(str) write(STDERR_FILENO, str, strlen(str))
 
 int main(int argc, char** argv)
 {

+ 2 - 2
user-space-program/sh.c

@@ -3,7 +3,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#define print(str) write(0, str, strlen(str))
+#define print(str) write(STDOUT_FILENO, str, strlen(str))
 
 // struct cmd {
 //     enum {
@@ -56,7 +56,7 @@ int main(int argc, const char** argv)
     print("sh # ");
 
     for (;;) {
-        int n = read(0, buf, sizeof(buf));
+        int n = read(STDIN_FILENO, buf, sizeof(buf));
 
         char token[1024] = {};
         char* args[128] = { token, 0 };