nice try

Posted by kAworu Thu, 15 Oct 2009 21:13:00 GMT
/*
 * hcreate() / hsearch() / hdestroy()
 *
 * SysV/XPG4 hash table functions.
 *
 * Implementation done based on NetBSD manual page and Solaris manual page,
 * plus my own personal experience about how they're supposed to work.
 *
 * I tried to look at Knuth (as cited by the Solaris manual page), but
 * nobody had a copy in the office, so...
 */

http://kaworu.ch/files/hcreate.c

Posted in | aucun comments |

C'est pas moi m'sieur l'agent!

Posted by kAworu Mon, 08 Jun 2009 14:22:00 GMT

Non. C’est pas moi qui l’ai écris. Les mouchoir sont distribués à la sortie, merci.

...
      if (!(c = *++needle))
        goto foundneedle;
      ++needle;
      goto jin;

      for (;;)
        {
          {
            chartype a;
            if (0)
            jin:{
                if ((a = *++haystack) == c)
                  goto crest;
              }
            else
              a = *++haystack;
...

Posted in | 1 comment |

malloc(u);

Posted by kAworu Wed, 06 May 2009 10:23:00 GMT
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct foo {
    int garbage[42];
    char *name;
};

int
main(int argc, char *argv[])
{
    struct foo *f;
    size_t s;

    if (argc < 2)
        return (EXIT_FAILURE);

    s = (strlen(argv[1]) + 1) * sizeof(char);
    f = malloc(sizeof(struct foo) + s);
    if (f == NULL)
        return (EXIT_FAILURE);
    f->name = &f[1];
    strlcpy(f->name, argv[1], s);

    (void)printf("What you say?\n%s\n", f->name);

    free(f);
    return (EXIT_SUCCESS);
}

Posted in | 2 comments |

Older posts: 1 2