/* * Copyright (C) 2006 James Antill * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * email: james@and.org */ /* these functions are higher level abstractions for getting the list of * xattrs from a file/fd */ #include "xattr_file2mem.h" #include "xattr_sc.h" #include static Xattrs *xattr__filefd2mem(const char *fname, int fd, unsigned int flags) { Xattrs *xattrs = NULL; char *list_mem = NULL; ssize_t list_sz = -1; const char *attr = NULL; if (!(xattrs = xattr_make())) return (NULL); if (!(list_mem = xattr_sc_listxattrs(fname, fd, flags, &list_sz))) { if (list_sz == -1) goto fail; return (xattrs); } attr = list_mem; while (list_sz > 0) { size_t len = strlen(attr); ssize_t val_sz = 0; char *val_mem = NULL; if (!(val_mem = xattr_sc_getxattrs(fname, fd, attr, flags, &val_sz))) { if (!val_sz) goto next_attr; goto fail; } xattr_add(xattrs, attr, val_mem, val_sz); XATTR_SC_RET_FREE(val); next_attr: attr += len + 1; list_sz -= len + 1; } XATTR_SC_RET_FREE(list_mem); return (xattrs); fail: XATTR_SC_RET_FREE(list_mem); xattr_free(xattrs); return (NULL); } Xattrs *xattr_file2mem(const char *fname, unsigned int flags) { return (xattr__filefd2mem(fname, -1, flags)); } Xattrs *xattr_fd2mem(int fd) { return (xattr__filefd2mem(NULL, fd, 0)); }