vmstrdup.c 799 B

12345678910111213141516171819202122232425262728293031
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #include <stddef.h>
  11. #include <string.h>
  12. #include <vmalloc/vmalloc.h>
  13. /*
  14. * return a copy of s using vmalloc
  15. */
  16. char *vmstrdup(Vmalloc_t * v, const char *s)
  17. {
  18. size_t len = strlen(s) + 1;
  19. char *t = vmalloc(v, len);
  20. if (t == NULL) {
  21. return NULL;
  22. }
  23. memcpy(t, s, len);
  24. return t;
  25. }