-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start Guide
Pablo R. edited this page Sep 29, 2025
·
2 revisions
- C99 compatible compiler (gcc, clang, MSVC)
- GNU Make (Linux/macOS) or compatible build system
- Standard C library
-
Clone the repository:
git clone https://github.com/murapadev/strap.git cd strap
-
Build the library:
make
This creates
libstrap.a
in the project directory. -
Install system-wide (optional):
sudo make install
This installs:
- Header:
/usr/local/include/strap.h
- Library:
/usr/local/lib/libstrap.a
- Header:
If you installed STRAP system-wide:
#include <strap.h>
Compile with:
gcc -o myprogram myprogram.c -lstrap
If using STRAP locally in your project:
#include "path/to/strap.h"
Compile with:
gcc -o myprogram myprogram.c -L/path/to/strap -lstrap
Create a file called hello_strap.c
:
#include <stdio.h>
#include <stdlib.h>
#include "strap.h"
int main(void) {
printf("Enter your name: ");
// Safe line reading
char *name = afgets(stdin);
if (!name) {
fprintf(stderr, "Error reading input\n");
return 1;
}
// Trim whitespace
char *trimmed_name = strtrim(name);
// Create greeting
char *greeting = strjoin_va(" ", "Hello,", trimmed_name, "!", NULL);
printf("%s\n", greeting);
// Cleanup
free(name);
free(trimmed_name);
free(greeting);
return 0;
}
Compile and run:
gcc -I. -L. -o hello_strap hello_strap.c -lstrap
./hello_strap
STRAP provides unified error reporting for all operations. When a function fails, it sets a thread-local error code that you can query:
#include <stdio.h>
#include "strap.h"
int main(void) {
// This will fail and set an error
char *result = strtrim(NULL);
if (!result) {
// Get the error code and message
strap_error_t err = strap_last_error();
fprintf(stderr, "STRAP error: %s\n", strap_error_string(err));
return 1;
}
// Clear error state if needed
strap_clear_error();
free(result);
return 0;
}
#include <stdio.h>
#include "strap.h"
void read_config(const char *filename) {
FILE *fp = fopen(filename, "r");
if (!fp) return;
char *line;
while ((line = afgets(fp)) != NULL) {
char *trimmed = strtrim(line);
if (trimmed[0] != '#' && trimmed[0] != '\0') {
printf("Config line: %s\n", trimmed);
}
free(line);
free(trimmed);
}
fclose(fp);
}
#include "strap.h"
char *build_path(const char *base, const char *file) {
return strjoin_va("/", base, file, NULL);
}
int main(void) {
char *config_path = build_path("/etc/myapp", "config.ini");
printf("Config at: %s\n", config_path);
free(config_path);
return 0;
}
#include <sys/time.h>
#include "strap.h"
void benchmark_operation(void) {
struct timeval start, end, diff;
gettimeofday(&start, NULL);
// Your operation here
for (int i = 0; i < 1000000; i++) {
// Some work
}
gettimeofday(&end, NULL);
diff = timeval_sub(end, start);
printf("Operation took %.6f seconds\n", timeval_to_seconds(diff));
}
Run the included tests to verify everything works:
cd tests
gcc -I.. -L.. -o test_strap test_strap.c -lstrap
./test_strap
You should see:
strtrim tests passed
strtrim_inplace tests passed
strjoin tests passed
strjoin_va tests passed
timeval tests passed
All tests passed!
STRAP includes micro-benchmarks to test performance:
make bench
./benchmarks/strap_bench
This will run performance tests for various string and time operations.
- Explore the API Reference for detailed function documentation
- Check out the examples/ directory for more complex usage patterns
- Read the Contributing Guide if you want to contribute to STRAP
"strap.h: No such file or directory"
- Make sure you're including the correct path
- Verify the header file exists in your include path
"undefined reference to 'afgets'"
- Ensure you're linking with
-lstrap
- Check that
libstrap.a
is in your library path
Build fails on Windows
- Use MinGW or MSYS2 for Windows builds
- The CI includes Windows build instructions
- Check the GitHub Issues for known problems
- Create a new issue if you encounter a bug
- See CONTRIBUTING.md for more support options