Ext
 All Files Functions
Macros | Functions
utils.h File Reference

Contains some useful methods. More...

#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <stdbool.h>

Go to the source code of this file.

Macros

#define buffer_length   1024
 

Functions

int buffered_write (char **buffer, size_t *buffer_size, char *data, size_t size)
 
int read_while (int fd, char *buffer, size_t to_read)
 Properly reading from memory. More...
 
int write_while (int fd, const char *buffer, size_t to_write)
 Properly writing to memory. More...
 
char * parse_path (const char *path, char *current_file_name)
 
bool split_path (const char *path, char *parent_path, char *dirname)
 
void read_command_from_stdin (char *command_buffer, size_t buffer_size)
 Read line from stdin. More...
 
char * parse_command (char *command_buffer, char *command)
 Parse command Parse command to command and args. Put command to arg command and return position of first arg. More...
 
ssize_t get_file_size (const char *path_to_file)
 Get size of file. More...
 

Detailed Description

Contains some useful methods.

Author
yaishenka
Date
13.03.2021

Definition in file utils.h.

Function Documentation

int buffered_write ( char **  buffer,
size_t *  buffer_size,
char *  data,
size_t  size 
)

Realloc buffer to accommodate data and write data to it

Parameters
buffer
data
size
Returns
Author
yaishenka
Date
10.03.2021

Definition at line 10 of file utils.c.

ssize_t get_file_size ( const char *  path_to_file)

Get size of file.

Parameters
path_to_file
Returns
size of file if all ok; -1 otherwise;

Definition at line 145 of file utils.c.

char* parse_command ( char *  command_buffer,
char *  command 
)

Parse command Parse command to command and args. Put command to arg command and return position of first arg.

Parameters
command_buffer
command
Returns
return position of first arg (first symbol after space)

Definition at line 131 of file utils.c.

void read_command_from_stdin ( char *  command_buffer,
size_t  buffer_size 
)

Read line from stdin.

Parameters
command_buffer
buffer_size

Definition at line 125 of file utils.c.

int read_while ( int  fd,
char *  buffer,
size_t  to_read 
)

Properly reading from memory.

Parameters
fd
buffer
to_read
Returns

Definition at line 23 of file utils.c.

int write_while ( int  fd,
const char *  buffer,
size_t  to_write 
)

Properly writing to memory.

Parameters
fd
buffer
to_write
Returns

Definition at line 38 of file utils.c.