error de vala Posix.lstat ()

Tengo este fragmento de código:

using Posix;

int fuseguifs_getattr(string path, Posix.Stat *stbuf)
{
    int res;
    res = Posix.lstat(path, stbuf);
    if (res == -1)
        return -Posix.errno;

    return 0;
}

static int main(string [] args)
{
    Posix.Stat *a;
    fuseguifs_getattr("/home/leon", a);
    return 0;
}

When I'm trying to compile it I get this error:

test.vala:6.26-6.30: error: Argument 2: Cannot convert from
`Posix.Stat' to `Posix.Stat*'
    res = Posix.lstat(path, stbuf);
                            ^^^^^
Compilation failed: 1 error(s), 0 warning(s)

I've tried changing this: fuseguifs_getattr("/home/leon", a); to fuseguifs_getattr("/home/leon", *a);

But then I get an error: "Cannot pass value to reference or output parameter"

I've tried adding "out": res = Posix.lstat(path, out *stbuf);

That gives this error: error: ref and out method arguments can only be used with fields, parameters, local variables, and array element access

I can't change the fuseguifs_getattr method parameters because that's part of how the fuse bindings expect it.

I'm really stuck. Does anyone how I can solve this?

preguntado el 08 de noviembre de 11 a las 18:11

2 Respuestas

Creo que quieres hacer algo como esto:

int fuseguifs_getattr(string path, out Posix.Stat stbuf) {
   int res;
   res = Posix.lstat(path, out stbuf);
   if (res == -1)
      return -Posix.errno;
   return 0;
 }

static int main(string [] args)
{
    Posix.Stat a;
    fuseguifs_getattr("/home/leon", out a);
    return 0;
}

Posix.Stat is a struct that lstat is going to fill. Rather than pass a pointer to that structure, Vala expects you to indicate that it is going to be used as output by lstat usando el out keyword which, like the ref keyword, must be specified on both declaration and use. So, any function definitions which are out, debes especificar out again when you call the function.

respondido 09 nov., 11:01

I can't change the function definition by removing the pointer I believe. The method is defined by fuse: fuse.sourceforge.net/doxygen/… If I remove the pointer from stbuf in the function I get this error: Cannot convert from fuseguifs_getattr' to Fuse.GetAttr' :( - León

The fuse.vapi has a really odd way of coding. It should probably be changed. The way you have done it below is fine given the VAPI. - apmasell

Esto parece solucionarlo:

int fuseguifs_getattr(string path, Posix.Stat *stbuf)
{
    int res;
    Posix.Stat a;
    res = Posix.lstat(path, stbuf);

    if (res == -1) {
        return -Posix.errno;
    }
    *stbuf = a;

    return 0;
}

Would that be the right way to go?

respondido 09 nov., 11:11

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.