mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
36 lines
799 B
C++
36 lines
799 B
C++
#include "io_utils.h"
|
|
#include "atom.h"
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
|
|
#define BUFFER_SIZE 8192
|
|
|
|
using namespace std;
|
|
|
|
int io_utils_read(string path, string* output) {
|
|
int fd = open(path.c_str(), O_RDONLY);
|
|
if (fd <= 0)
|
|
return 0;
|
|
|
|
char buffer[BUFFER_SIZE];
|
|
unsigned int bytesRead = 0;
|
|
unsigned int totalRead = 0;
|
|
while ((bytesRead = read(fd, buffer, BUFFER_SIZE)) > 0) {
|
|
output->append(buffer, 0, bytesRead);
|
|
totalRead += bytesRead;
|
|
}
|
|
close(fd);
|
|
return totalRead;
|
|
}
|
|
|
|
string io_utils_real_app_path(string relativePath) {
|
|
string path = AppPath() + relativePath;
|
|
char* realPath = realpath(path.c_str(), NULL);
|
|
if (realPath != NULL) {
|
|
string realAppPath(realPath);
|
|
free(realPath);
|
|
return realAppPath;
|
|
} else
|
|
return "";
|
|
} |