Safe C String Libraryを使ってみる

フツーに使える。よいかも…

#include <stdio.h>
#include "safestr.h"

int main() {
  safestr_t str;

  str = safestr_create("hello, world", 0);
  printf("%s\n", str);

  safestr_append(&str, SAFESTR_TEMP(". hello, safestr."));
  printf("%s\n", str);

  safestr_replace(&str, SAFESTR_TEMP("."), SAFESTR_TEMP(";"));
  printf("%s\n", str);

  safestr_free(str);

  return 0;
}


~/work$ gcc foo.c -lsafestr -lxxl -o foo
~/work$ ./foo.exe
hello, world
hello, world. hello, safestr.
hello, world; hello, safestr;