Skip to content

Commit

Permalink
move randomString() to a separate file, allowing build on macos
Browse files Browse the repository at this point in the history
Signed-off-by: Predrag Rogic <prezha@users.noreply.github.com>
  • Loading branch information
prezha authored and poiana committed Sep 20, 2024
1 parent 93df6eb commit 552829c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
30 changes: 30 additions & 0 deletions events/syscall/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package syscall

import "math/rand/v2"

// randomString generates a random string of the given length.
func randomString(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

bytes := make([]byte, length)

for i := range bytes {
bytes[i] = charset[rand.IntN(len(charset))]
}

return string(bytes)
}
14 changes: 0 additions & 14 deletions events/syscall/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package syscall

import (
"fmt"
"math/rand/v2"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -134,16 +133,3 @@ func createSshDirectoryUnderHome(h events.Helper) (string, func(), error) {
}
}, nil
}

// randomString generates a random string of the given length.
func randomString(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

bytes := make([]byte, length)

for i := range bytes {
bytes[i] = charset[rand.IntN(len(charset))]
}

return string(bytes)
}

0 comments on commit 552829c

Please sign in to comment.