فهرست منبع

Merge branch 'optind-reset' into 'master'

Handle getopt reinitialization

See merge request redox-os/relibc!174
Jeremy Soller 6 سال پیش
والد
کامیت
51b2e630b9
1فایلهای تغییر یافته به همراه6 افزوده شده و 0 حذف شده
  1. 6 0
      src/header/getopt/mod.rs

+ 6 - 0
src/header/getopt/mod.rs

@@ -30,6 +30,12 @@ pub unsafe extern "C" fn getopt_long(
     // if optarg is not set, we still don't want the previous value leaking
     optarg = ptr::null_mut();
 
+    // handle reinitialization request
+    if optind == 0 {
+        optind = 1;
+        CURRENT_OPT = ptr::null_mut();
+    }
+
     if CURRENT_OPT.is_null() || *CURRENT_OPT == 0 {
         if optind >= argc {
             -1