Exemple #1
0
/*
 * Attempt to generate libmagic-style file class if missing from header:
 * we can easily generate this for symlinks and other special types.
 * Always return malloced strings to simplify life in fileclassTag().
 */
static char *makeFClass(rpmfi fi)
{
    char *fclass = NULL;
    const char *hc = rpmfiFClass(fi);

    if (hc != NULL && hc[0] != '\0') {
	fclass = xstrdup(hc);
    } else {
	switch (rpmfiFMode(fi) & S_IFMT) {
	case S_IFBLK:
	    fclass = xstrdup("block special");
	    break;
	case S_IFCHR:
	    fclass = xstrdup("character special");
	    break;
	case S_IFDIR:
	    fclass = xstrdup("directory");
	    break;
	case S_IFIFO:
	    fclass = xstrdup("fifo (named pipe)");
	    break;
	case S_IFSOCK:
	    fclass = xstrdup("socket");
	    break;
	case S_IFLNK:
	    fclass = rstrscat(NULL, "symbolic link to `",
			      rpmfiFLink(fi), "'", NULL);
	    break;
	}
    }

    return (fclass != NULL) ? fclass : xstrdup("");
}
Exemple #2
0
static PyObject *
rpmfi_FClass(rpmfiObject * s, PyObject * unused)
{
    const char * FClass;

    if ((FClass = rpmfiFClass(s->fi)) == NULL)
	FClass = "";
    return Py_BuildValue("s", FClass);
}
Exemple #3
0
static PyObject *
rpmfi_FClass(rpmfiObject * s)
{
    const char * FClass;

    if ((FClass = rpmfiFClass(s->fi)) == NULL)
	FClass = "";
    return Py_BuildValue("s", xstrdup(FClass));
}
Exemple #4
0
static VALUE
rpmfi_FClass_get(VALUE s)
{
    rpmfi fi = rpmfi_ptr(s);
    const char * FClass = rpmfiFClass(fi);
    char * t;
    VALUE v;
if (_debug)
fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, fi);
    if (FClass == NULL) FClass = "";
    /* XXX spot fix for known embedded single quotes. */
    t = xstrdup(FClass);
    if (!strncmp(t, "symbolic link to `", sizeof("symbolic link to `")-1))
	t[sizeof("symbolic link")-1] = '\0';
    v = rb_str_new2(FClass);
    t = _free(t);
    return v;
}