Skip to content

Commit

Permalink
Object 101
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jan 4, 2025
1 parent 496bd93 commit ce5fd42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 1 addition & 19 deletions lua/fittencode/http/curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ function M.get(url, options)
Process.spawn(executables.curl, args, options)
end

-- libuv command line length limit
-- * win32 `CreateProcess` 32767
-- * unix `fork` 128 KB to 2 MB (getconf ARG_MAX)
local max_arg_length

local function arg_max()
if max_arg_length ~= nil then
return max_arg_length
end
if Fn.is_windows() then
max_arg_length = 32767
else
local _, sys = pcall(tonumber, vim.fn.system('getconf ARG_MAX'))
max_arg_length = sys or (128 * 1024)
end
return max_arg_length
end

local function _post(url, options)
local args = {
url,
Expand All @@ -89,7 +71,7 @@ local function _post(url, options)
Process.spawn(executables.curl, args, options)
return
end
if not Fn.is_windows() and #options.body <= arg_max() - 2 * vim.fn.strlen(table.concat(args, ' ')) then
if not Fn.is_windows() and #options.body <= Process.arg_max() - 2 * vim.fn.strlen(table.concat(args, ' ')) then
add_data(args, options.body, options.binaray, false)
Process.spawn(executables.curl, args, options)
else
Expand Down
18 changes: 18 additions & 0 deletions lua/fittencode/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,22 @@ function M.spawn(exe, args, options)
end
end

-- libuv command line length limit
-- * win32 `CreateProcess` 32767
-- * unix `fork` 128 KB to 2 MB (getconf ARG_MAX)
local ARG_MAX

function M.arg_max()
if ARG_MAX ~= nil then
return ARG_MAX
end
if Fn.is_windows() then
ARG_MAX = 32767
else
local _, sys = pcall(tonumber, vim.fn.system('getconf ARG_MAX'))
ARG_MAX = sys or (128 * 1024)
end
return ARG_MAX
end

return M

0 comments on commit ce5fd42

Please sign in to comment.