File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed
internal/users/localentries Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change @@ -8,18 +8,13 @@ package localentries
8
8
#include <pwd.h>
9
9
#include <grp.h>
10
10
11
- // Copy a NULL-terminated char** into a new array and return length .
12
- char **copy_strv (char **strv, int *out_len ) {
11
+ // Return the length of a NULL-terminated char** array.
12
+ int strv_len (char **strv) {
13
13
int n = 0;
14
14
while (strv && strv[n]) n++;
15
-
16
- *out_len = n;
17
- char **out = calloc(n + 1, sizeof(char*));
18
- for (int i = 0; i < n; i++) {
19
- out[i] = strv[i];
20
- }
21
- return out;
15
+ return n;
22
16
}
17
+
23
18
*/
24
19
import "C"
25
20
@@ -90,13 +85,11 @@ func strvToSlice(strv **C.char) []string {
90
85
if strv == nil {
91
86
return nil
92
87
}
93
- var n C.int
94
- tmp := C .copy_strv (strv , & n )
95
- defer C .free (unsafe .Pointer (tmp ))
88
+ n := C .strv_len (strv )
96
89
97
90
out := make ([]string , int (n ))
98
91
for i := 0 ; i < int (n ); i ++ {
99
- p := * (* * C .char )(unsafe .Add (unsafe .Pointer (tmp ), uintptr (i )* unsafe .Sizeof (* tmp )))
92
+ p := * (* * C .char )(unsafe .Add (unsafe .Pointer (strv ), uintptr (i )* unsafe .Sizeof (* strv )))
100
93
out [i ] = C .GoString (p )
101
94
}
102
95
return out
You can’t perform that action at this time.
0 commit comments