Skip to content

Commit

Permalink
str.h: Add a quick str initialization function
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Jan 19, 2018
1 parent d2527e8 commit bcae687
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions str.h
Expand Up @@ -21,6 +21,8 @@
#ifndef str_h
#define str_h

#include <string.h>

/**
* \file
* \brief Common data type for text variables.
Expand Down Expand Up @@ -54,6 +56,11 @@ typedef struct _str str;

/* str initialization */
#define str_init(_string) {_string, sizeof(_string) - 1}
static inline void init_str(str *dst, char *in)
{
dst->s = in;
dst->len = strlen(in);
}

/* zero-str tests */
#define ZSTR(_s) (!(_s).s || (_s).len == 0)
Expand Down

0 comments on commit bcae687

Please sign in to comment.