remove path max len limit

This commit is contained in:
springzfx
2020-05-26 23:04:12 +08:00
parent 4fea0d39a2
commit 1d29828d1b
4 changed files with 28 additions and 20 deletions

View File

@@ -1,7 +1,5 @@
#include "common.h"
#include <fstream>
#include <limits.h>
#include <linux/limits.h>
#include <regex>
#include <sys/stat.h>
#include <unistd.h>
@@ -54,7 +52,6 @@ vector<int> bash_pidof(const string &path) {
FILE *fp = popen(to_str("pidof ", path).c_str(), "r");
if (!fp) return pids;
int pid;
char buf[64];
while (fscanf(fp, "%d", &pid) != EOF) { pids.push_back(pid); }
pclose(fp);
return pids;
@@ -64,8 +61,8 @@ string bash_which(const string &name) {
stringstream buffer;
FILE *fp = popen(to_str("which ", name).c_str(), "r");
if (!fp) return "";
char buf[64];
while (fgets(buf, 64, fp) != NULL) { buffer << buf; }
char buf[READ_SIZE_MAX];
while (fgets(buf, READ_SIZE_MAX, fp) != NULL) { buffer << buf; }
pclose(fp);
string s = buffer.str();
s.pop_back(); // remove newline character
@@ -76,8 +73,8 @@ string bash_readlink(const string &path) {
stringstream buffer;
FILE *fp = popen(to_str("readlink -e ", path).c_str(), "r");
if (!fp) return "";
char buf[64];
while (fgets(buf, 64, fp) != NULL) { buffer << buf; }
char buf[READ_SIZE_MAX];
while (fgets(buf, READ_SIZE_MAX, fp) != NULL) { buffer << buf; }
pclose(fp);
string s = buffer.str();
s.pop_back(); // remove newline character