rsLQR  0.1
utils.h File Reference

Provides basic functions like powers of 2 and reading files to a string. More...

#include <stdbool.h>

Go to the source code of this file.

Functions

bool IsPowerOfTwo (int x)
 Determines if the input integer is a power of 2.
 
void ndlqr_LinAlgTimeStart ()
 
void ndlqr_LinAlgTimeStop ()
 
int LogOfTwo (int x)
 Efficient computation of log2(x) for integers.
 
int ReadFile (const char *filename, char **out, int *len)
 Read the contents of a file into a heap-allocated char array. More...
 

Detailed Description

Provides basic functions like powers of 2 and reading files to a string.

Author
Brian Jackson (bjack.nosp@m.205@.nosp@m.gmail.nosp@m..com)
Version
0.1
Date
2022-01-30

Function Documentation

◆ ReadFile()

int ReadFile ( const char *  filename,
char **  out,
int *  len 
)

Read the contents of a file into a heap-allocated char array.

It is the user's responsibility to call free on out after the string data is allocated.

Example

The following example reads

const char* filename = "mydata.txt"
char* data = NULL;
int len;
int out = ReadFile(filename, &data, &len);
free(data);
Parameters
filenameName of the file to read.
outPointer to the array (pointer) to the heap-allocated string data.
lenLength of the string data.
Returns
int 0 if successful, -1 otherwise.
ReadFile
int ReadFile(const char *filename, char **out, int *len)
Read the contents of a file into a heap-allocated char array.
Definition: utils.c:17