+/**
+ * Determine the number of leading characters in s that do not match characters in a
+ * @param s A pointer to the string to analyse
+ * @param a A pointer to an array of characters that do not match the prefix
+ * @return The number of not matching characters
+ */
+
+size_t strcspn(const char *s, const char *a)
+{
+ int i, j;
+ int al = strlen(a);
+ for (i = 0; s[i] != 0; i++) {
+ int found = 0;
+ for (j = 0; j < al; j++) {
+ if (s[i] == a[j]) {
+ found = 1;
+ break;
+ }
+ }
+ if (found)
+ break;
+ }
+ return i;
+}
+
+/**
+ * Extract first token in string str that is delimited by a character in tokens.
+ * Destroys str and eliminates the token delimiter.
+ * @param str A pointer to the string to tokenize.
+ * @param delim A pointer to an array of characters that delimit the token
+ * @param ptr A pointer to a string pointer to keep state of the tokenizer
+ * @return Pointer to token
+ */
+
+char* strtok_r(char *str, const char *delim, char **ptr)
+{
+ /* start new tokenizing job or continue existing one? */
+ if (str == NULL)
+ str = *ptr;
+
+ /* skip over prefix delimiters */
+ char *start = str + strspn(str, delim);
+
+ /* find first delimiter character */
+ char *end = start + strcspn(start, delim);
+ end[0] = '\0';
+
+ *ptr = end+1;
+ return start;
+}
+
+static char **strtok_global;
+
+/**
+ * Extract first token in string str that is delimited by a character in tokens.
+ * Destroys str, eliminates the token delimiter and uses global state.
+ * @param str A pointer to the string to tokenize.
+ * @param delim A pointer to an array of characters that delimit the token
+ * @return Pointer to token
+ */
+
+char* strtok(char *str, const char *delim)
+{
+ return strtok_r(str, delim, strtok_global);
+}
+
+/**
+ * Print error message and error number
+ * @param s Error message to print
+ */
+void perror(const char *s)
+{
+ printf("%s: %d\n", s?s:"(none)", errno);
+}