On Tue, Jul 24, 2012 at 4:45 PM, Roland Mainz <roland.ma...@nrubsig.org> wrote: > On Tue, Jul 24, 2012 at 11:51 AM, Simon Toedt <simon.to...@gmail.com> wrote: >> I'm looking for code examples which show how I can allocate C strings >> using sfio string streams. Has anyone an example how I can get the >> sfio equivalent of strdup() for "aaaa", "bbbbbb" and "cccccccc" and a >> malloc(256), get pointers back to the strings and allocated memory in >> the sfio stream and finally deallocate the whole memory after all work >> has been done? > > Example: > -- snip -- > #include <sfio.h> > #include <stk.h> > #include <stdio.h> > #include <stdlib.h> > > static > const char *sfstrdup(Sfio_t *str, const char *s) > { > ssize_t pos=stktell(str); > sfputr(str, s, 0); > return stkptr(str, pos); > } > > int main(int ac, char *av[]) > { > Sfio_t *str= sfstropen(); > const char *s; > > printf("tell=%ld\n", (long)stktell(str)); > > s=sfstrdup(str, "hello"); > printf("|%s|, tell=%ld\n", s, (long)stktell(str)); > > s=sfstrdup(str, "world"); > printf("|%s|, tell=%ld\n", s, (long)stktell(str)); > > sfclose(str); > > return EXIT_SUCCESS; > } > -- snip --
... which reminds me (again): libast needs _example_ code. Simple, plain, braindead example code which exactly demonstrates _one_ libast/sfio function. I'll add that to my ToDo list. ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) roland.ma...@nrubsig.org \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 3992797 (;O/ \/ \O;) _______________________________________________ ast-developers mailing list ast-developers@research.att.com https://mailman.research.att.com/mailman/listinfo/ast-developers