LICK
 All Data Structures Files Functions Variables Enumerations Enumerator
Macros | Functions
utils.h File Reference

functions used by multiple boot loader plugins More...

#include <stdio.h>
#include "../lickdir.h"
Include dependency graph for utils.h:

Go to the source code of this file.

Macros

#define LOADER_DESC   "LICK Boot Loader"
 
#define START_LOADER_DESC   "Start LICK Boot Loader"
 
#define ID_LEN   37
 
#define COMMAND_BUFFER_LEN   1024
 

Functions

char * advance_to_newline (char *s)
 returns a pointer to the next newline in a string More...
 
int find_section (const char *haystack, const char *needle, char **start, char **end)
 find the extents of an INI section More...
 
char * after_last_entry (char *sec, char *sec_end, const char *needle)
 find the line after the last needle in an INI section More...
 
char * check_timeout (char *f, char *key, char *sep)
 check the timeout value of an INI file More...
 
int backup_file (const char *f)
 create a backup of a file More...
 
int get_id_from_command_range (const char *c, char *out, char *start, char *end)
 get an ID from a command, between two strings More...
 
int get_id_from_command (const char *c, char *out)
 get an ID from a command More...
 
char * get_bcdedit ()
 get the path to bcdedit.exe More...
 
int apply_fn_to_file (const char *file, char *(*fn)(char *, lickdir_t *), int backup, lickdir_t *lick)
 applies a function to a file More...
 
char * find_drive_with_file (const char *suggested_drive, const char *file)
 find a drive which contains a file More...
 
char * boot_drive (const char *boot_file)
 find the boot drive More...
 

Detailed Description

functions used by multiple boot loader plugins

Function Documentation

char* advance_to_newline ( char *  s)

returns a pointer to the next newline in a string

Parameters
sthe beginning of the string to search in
Returns
a pointer to the first newline, or to the string terminator
char* after_last_entry ( char *  sec,
char *  sec_end,
const char *  needle 
)

find the line after the last needle in an INI section

sec and sec_end can be start and end from find_section

Parameters
secthe beginning of the section
sec_endthe beginning of the next section
needlea needle to determine if something is an entry
int apply_fn_to_file ( const char *  file,
char *(*)(char *, lickdir_t *)  fn,
int  backup,
lickdir_t lick 
)

applies a function to a file

Reads a file and applies the function to the contents. If the return value is a string, optionally backs up the file, then saves the return value in the file. This also ensures the file is saved with the same attributes.

Parameters
filethe file to apply the function on
fnthe function to apply
backupto backup the file or not before saving
lickthe lick environment
Returns
1 on success
int backup_file ( const char *  f)

create a backup of a file

Parameters
fthe file to backup
Returns
1 on success
char* boot_drive ( const char *  boot_file)

find the boot drive

Finds the boot drive of the computer. To help in the search, a path of a file that is expected to be found on the root of the drive should be given.

Parameters
boot_filea path to a file that is expected to be on the boot partition
Returns
a path that must be freed using free on success, NULL on failure
char* check_timeout ( char *  f,
char *  key,
char *  sep 
)

check the timeout value of an INI file

f must be allocated using malloc, and should contain the contents of an INI file. f will be freed in this function

Parameters
fthe file
keythe key of the timeout
septhe string before the start of the timeout
Returns
the INI file. Must be freed using free
char* find_drive_with_file ( const char *  suggested_drive,
const char *  file 
)

find a drive which contains a file

Given a file, such as 'path/to/boot.ini', finds a drive where the file exists. If suggested_drive is given, that drive is checked first.

Parameters
suggested_drivethe drive to first look at. Can be NULL
filethe file to find
Returns
a path that must be freed using free on success, NULL on failure
int find_section ( const char *  haystack,
const char *  needle,
char **  start,
char **  end 
)

find the extents of an INI section

Parameters
[in]haystackthe file
[in]needlethe section header, including brackets
[out]startpoints to first character of section
[out]endpoints to first character of the next section, or '\0'
Returns
1 if the section is found, otherwise 0
char* get_bcdedit ( )

get the path to bcdedit.exe

Returns
path to bcdedit.exe. Must be freed using free
int get_id_from_command ( const char *  c,
char *  out 
)

get an ID from a command

Parameters
cthe command
outthe buffer to put the ID. Must be at least ID_LEN + 1 long
Returns
1 on success, otherwise 0
int get_id_from_command_range ( const char *  c,
char *  out,
char *  start,
char *  end 
)

get an ID from a command, between two strings

Looks for end in the output, then looks backwards to find the start, then looks for the ID between these two points.

Parameters
cthe command
outthe buffer to put the ID. Must be at least ID_LEN + 1 long
startthe string to look after
endthe string to look before
Returns
1 on success, otherwise 0