Skip to content

Commit 6e731c8

Browse files
Refactored write methods
1 parent 45eae78 commit 6e731c8

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/common/caching.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void writeCacheFile(FFinstance* instance, const char* moduleName, const c
3131
FFstrbuf path;
3232
ffStrbufInitA(&path, 64);
3333
getCacheFilePath(instance, moduleName, extension, &path);
34-
ffWriteFileContent(path.chars, content);
34+
ffWriteFileBuffer(path.chars, content);
3535
ffStrbufDestroy(&path);
3636
}
3737

src/common/io.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
#include <termios.h>
77
#include <poll.h>
88

9-
bool ffWriteFDContent(int fd, const FFstrbuf* content)
10-
{
11-
return write(fd, content->chars, content->length) != -1;
12-
}
13-
149
static void createSubfolders(const char* fileName)
1510
{
1611
FFstrbuf path;
@@ -27,7 +22,17 @@ static void createSubfolders(const char* fileName)
2722
ffStrbufDestroy(&path);
2823
}
2924

30-
bool ffWriteFileContent(const char* fileName, const FFstrbuf* content)
25+
bool ffWriteFDData(int fd, size_t dataSize, const void* data)
26+
{
27+
return write(fd, data, dataSize) != -1;
28+
}
29+
30+
bool ffWriteFDBuffer(int fd, const FFstrbuf* content)
31+
{
32+
return ffWriteFDData(fd, content->length, content->chars);
33+
}
34+
35+
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
3136
{
3237
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC;
3338
int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
@@ -41,13 +46,18 @@ bool ffWriteFileContent(const char* fileName, const FFstrbuf* content)
4146
return false;
4247
}
4348

44-
bool ret = ffWriteFDContent(fd, content);
49+
bool ret = ffWriteFDData(fd, dataSize, data);
4550

4651
close(fd);
4752

4853
return ret;
4954
}
5055

56+
bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer)
57+
{
58+
return ffWriteFileData(fileName, buffer->length, buffer->chars);
59+
}
60+
5161
void ffAppendFDContent(int fd, FFstrbuf* buffer)
5262
{
5363
ssize_t readed = 0;

src/fastfetch.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,14 @@ void ffListFeatures();
413413
void ffStartDetectionThreads(FFinstance* instance);
414414

415415
//common/io.c
416+
bool ffWriteFDData(int fd, size_t dataSize, const void* data);
417+
bool ffWriteFDBuffer(int fd, const FFstrbuf* content);
418+
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
419+
bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer);
420+
416421
void ffAppendFDContent(int fd, FFstrbuf* buffer);
417422
bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer); //returns true if open() succeeds. This is used to differentiate between <file not found> and <empty file>
418423
bool ffGetFileContent(const char* fileName, FFstrbuf* buffer);
419-
bool ffWriteFDContent(int fd, const FFstrbuf* content);
420-
bool ffWriteFileContent(const char* fileName, const FFstrbuf* buffer);
421424

422425
bool ffFileExists(const char* fileName, mode_t mode);
423426
void ffSuppressIO(bool suppress); // Not thread safe!

src/logo/image/image.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void writeCacheStrbuf(FFLogoRequestData* requestData, const FFstrbuf* val
9494
{
9595
uint32_t cacheDirLength = requestData->cacheDir.length;
9696
ffStrbufAppendS(&requestData->cacheDir, cacheFileName);
97-
ffWriteFileContent(requestData->cacheDir.chars, value);
97+
ffWriteFileBuffer(requestData->cacheDir.chars, value);
9898
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
9999
}
100100

@@ -127,7 +127,7 @@ static void printImagePixels(FFinstance* instance, FFLogoRequestData* requestDat
127127
//Write result to stdout
128128
ffPrintCharTimes(' ', instance->config.logoPaddingLeft);
129129
fflush(stdout);
130-
ffWriteFDContent(STDOUT_FILENO, result);
130+
ffWriteFDBuffer(STDOUT_FILENO, result);
131131

132132
//Go to upper left corner
133133
fputs("\033[9999999D", stdout);

0 commit comments

Comments
 (0)