Skip to content

Commit

Permalink
Premiere partie de ls + getLine
Browse files Browse the repository at this point in the history
  • Loading branch information
JOSSO victor committed Jan 11, 2022
1 parent c285dc9 commit f7010a3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/saturnd_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ void set_taskid(TASK* task, uint64_t* next_id);
void set_next_id(uint64_t* next_id, char* path);
char* my_cat(char* start, char* end);

/// List tasks

void listTasks(int clyde);

/// Execution

void ensure_directory_exists(const char *path);
Expand Down
5 changes: 5 additions & 0 deletions src/saturnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ int main(int argc, char **argv){
free(demande);
goto exit_succes;
break;
case CLIENT_REQUEST_LIST_TASKS:
int clyde = open_rep();
listTasks(clyde);
close(clyde);
break;
case CLIENT_REQUEST_REMOVE_TASK:
id_buf = malloc(sizeof(u_int64_t));
read(bonny, id_buf, sizeof(u_int64_t));
Expand Down
37 changes: 37 additions & 0 deletions src/saturnd_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
#include "../include/saturnd.h"



int getLine(int fd, char * buffer, int max_length){
int r = read(fd, buffer, max_length);
for (int i = 0; i < r; i ++){
if (*(buffer + i) == '\n'){
break;
}
}

*(buffer + i) = 0;
lseek(fd, (i - r + 2), SEEK_CUR);
return i;
}


/// Create task


Expand Down Expand Up @@ -161,6 +176,28 @@ void set_next_id(uint64_t* next_id, char* path) {
}


/// List tasks

void listTasks(int clyde){
struct stat buffer;
if (stat("daemon_dir/timings.txt", &buffer) < 0){
uint16_t reptype = htobe(SERVER_REPLY_OK);
uint32_t nbtasks = 0
clyde.write(reptype);
clyde.write(nbtasks);
return;
}
int timings = open("daemon_dir/timings.txt", O_RDONLY);
flock(timings, LOCK_EX);
int max_length = 256;
char * buffer = malloc(max_length);
uint32_t nbtasks = 0;
while (getLine(fd, buffer, max_length) != 0){

}
}


/// Structure helpers

void ensure_directory_exists(const char *path){
Expand Down

0 comments on commit f7010a3

Please sign in to comment.