/* * 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 */ /* Sort an Xattr list */ #define _GNU_SOURCE 1 /* make sure we get strverscmp */ #include "xattr_sort.h" #include void xattr_qsort(Xattrs *xattrs, int (*qsorter)(const void *, const void *)) { qsort(xattrs->ents, xattrs->num, sizeof(Xattr_node), qsorter); } int xattr_sc_qsort_strcmp_key(const void *c1, const void *c2) { const Xattr_node *x1 = c1; const Xattr_node *x2 = c2; return (strcmp(x1->key, x2->key)); } int xattr_sc_qsort_strverscmp_key(const void *c1, const void *c2) { const Xattr_node *x1 = c1; const Xattr_node *x2 = c2; return (strverscmp(x1->key, x2->key)); } int xattr_sc_qsort_strnonscmp_key(const void *c1, const void *c2) { const Xattr_node *x1 = c1; const Xattr_node *x2 = c2; const char *key1 = NULL; const char *key2 = NULL; int ret = 0; key1 = strchr(x1->key, '.') + 1; key2 = strchr(x2->key, '.') + 1; ret = strcmp(key1, key2); if (!ret) return (strcmp(x1->key, x2->key)); return (ret); }