@@ -548,7 +548,8 @@ pub const ChildProcess = struct {
548
548
549
549
var it = mem .tokenize (PATH , ";" );
550
550
retry : while (it .next ()) | search_path | {
551
- var ext_it = mem .tokenize (PATHEXT , ";" );
551
+ var ext_it = Chain (OneItemIterator ([]u8 ), @typeOf (mem .tokenize ).ReturnType ).init (
552
+ OneItemIterator ([]u8 ).init ("" ), mem .tokenize (PATHEXT , ";" ));
552
553
while (ext_it .next ()) | app_ext | {
553
554
const app_basename = try mem .concat (self .allocator , u8 , [_ ][]const u8 {app_name [0.. app_name .len - 1 ], app_ext });
554
555
defer self .allocator .free (app_basename );
@@ -768,3 +769,47 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap)
768
769
i += 1 ;
769
770
return allocator .shrink (result , i );
770
771
}
772
+
773
+ // TODO: does this already exist somewhere?
774
+ fn Chain (comptime T : type , comptime U : type ) type {
775
+ return struct {
776
+ t : T ,
777
+ u : U ,
778
+ onU : bool ,
779
+ pub fn init (t : T , u : U ) @This () {
780
+ return @This () {
781
+ .t = t ,
782
+ .u = u ,
783
+ .onU = false ,
784
+ };
785
+ }
786
+ pub fn next (self : * @This ()) @typeOf (T .next ).ReturnType {
787
+ if (! self .onU ) {
788
+ if (self .t .next ()) | tvalue | {
789
+ return tvalue ;
790
+ }
791
+ self .onU = true ;
792
+ }
793
+ return self .u .next ();
794
+ }
795
+ };
796
+ }
797
+
798
+ // TODO: does this already exist?
799
+ fn OneItemIterator (comptime T : type ) type {
800
+ return struct {
801
+ t : ? T ,
802
+ pub fn init (t : T ) @This () {
803
+ return @This () {
804
+ .t = t ,
805
+ };
806
+ }
807
+ pub fn next (self : * @This ()) ? T {
808
+ if (self .t ) | tvalue | {
809
+ self .t = null ;
810
+ return tvalue ;
811
+ }
812
+ return null ;
813
+ }
814
+ };
815
+ }
0 commit comments