Skip to content

Instantly share code, notes, and snippets.

View devendranaga's full-sized avatar
🍈

Dev devendranaga

🍈
  • Bangalore
View GitHub Profile
@devendranaga
devendranaga / main.cpp
Created January 17, 2023 18:15 — forked from grejdi/main.cpp
Using openssl to encrypt and decrypt a message with public/private key.
using namespace std;
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <iostream>
#include <string>
int main()
{

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@devendranaga
devendranaga / README.md
Last active February 8, 2019 02:30 — forked from gburd/README.md
Hardening C code at compile time

Hardening C code

format

Adds the -Wformat -Wformat-security -Werror=format-security compiler options. At present, this warns about calls to printf and scanf functions where the format string is not a string literal and there are no format arguments, as in printf(foo). This may be a security hole if the format string came from untrusted input and contains %n.

-Wformat is usually added with the -Wformat=2 option to be more stricter.

stackprotector

@devendranaga
devendranaga / timespec_diff.c
Created August 26, 2017 03:33 — forked from diabloneo/timespec_diff.c
Calculate diff of two struct timespec
#include <time.h>
void timespec_diff(struct timespec *start, struct timespec *stop,
struct timespec *result)
{
if ((stop->tv_nsec - start->tv_nsec) < 0) {
result->tv_sec = stop->tv_sec - start->tv_sec - 1;
result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000;
} else {
result->tv_sec = stop->tv_sec - start->tv_sec;