Move into directory
CMake / build (push) Failing after 4s

This commit is contained in:
2025-02-28 11:40:57 +01:00
parent 294389980b
commit e078a1023a
8 changed files with 23 additions and 15 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ FROM git.legonzaur.fr/legonzaur/qotd/builder:latest AS builder
WORKDIR /opt/builder WORKDIR /opt/builder
COPY . . COPY .server .
RUN cmake -B build -DSTATIC_BUILD=true RUN cmake -B build -DSTATIC_BUILD=true
WORKDIR build WORKDIR build
RUN make RUN make
+1 -2
View File
@@ -1,2 +1 @@
Test1 première ligne \n Deuxième ligne
Test2
View File
View File
+21 -12
View File
@@ -5,28 +5,33 @@
#include "quote.h" #include "quote.h"
#include "config.h" #include "config.h"
void getRandomQuote(char quote[2048]) { void getRandomQuote(char quote[2048])
{
int lineCount; int lineCount;
long line; long line;
if ((lineCount = getFileLineCount(QUOTES_FILE)) == -1) { if ((lineCount = getFileLineCount(QUOTES_FILE)) == -1)
{
puts("file does not exist"); puts("file does not exist");
exit(-1); exit(-1);
} }
line = random() % lineCount; line = rand() % lineCount;
getQuote(line, quote); getQuote(line, quote);
} }
void getQuote(long line, char quote[2048]) { void getQuote(long line, char quote[2048])
FILE* list; {
FILE *list;
list = fopen(QUOTES_FILE, "r"); list = fopen(QUOTES_FILE, "r");
/*skip lines*/ /*skip lines*/
while (line > 0) { while (line > 0)
if (fgetc(list) == '\n') { {
if (fgetc(list) == '\n')
{
line--; line--;
} }
} }
@@ -36,18 +41,22 @@ void getQuote(long line, char quote[2048]) {
fclose(list); fclose(list);
} }
int getFileLineCount(char *filename) { int getFileLineCount(char *filename)
{
char c; char c;
int lineCount = 0; int lineCount = 0;
FILE* quotesFile = fopen(filename, "r"); FILE *quotesFile = fopen(filename, "r");
if (quotesFile == NULL) { if (quotesFile == NULL)
{
printf("no quote file found at \"%s\"\n", filename); printf("no quote file found at \"%s\"\n", filename);
return -1; return -1;
} }
while ((c = (char) fgetc(quotesFile)) != EOF) { while ((c = (char)fgetc(quotesFile)) != EOF)
if (c == '\n') { {
if (c == '\n')
{
lineCount++; lineCount++;
} }
} }
View File
View File
View File