[Linux-programlama] Re: yivli getpwuid_r() kullanımı

---------

New Message Reply About this list Date view Thread view Subject view Author view Attachment view

From: Volkan YAZICI (yazicivo@ttnet.net.tr)
Date: Sun 15 Jan 2006 - 00:09:31 EET


On Jan 14 10:43, Cafer Şimşek wrote:
> Volkan YAZICI <yazicivo@ttnet.net.tr> writes:
> > gret = getpwuid_r(proc_id, &old_pw, buf, sz, &new_pw);
>
> bu satırda bir sorun olabilir mi?. new_pw için ayrılmış bir alan
> yok.

Hayır var.
  new_pw için alan: old_pw
  new_pw'nin içindeki veri için alan: buf

> Emin değilim ama genelde parametre olarak adres geçilen
> fonksiyonlar kendileri bellek tahsisi yapmazlar. Tanımlama işini;
>
> struct passwd *new_pw = (struct passwd*) malloc(sizeof(struct passwd));
>
> şeklinde yapıp işiniz bitince de free() yapsanız daha mantıklı olmaz
> mı?

getpwuid_r() manual sayfasından:

  int getpwuid_r(uid_t uid, struct passwd *pwbuf,
                 char *buf, size_t buflen, struct passwd **pwbufp);

  The getpwnam_r() and getpwuid_r() functions find the same
  information, but store the retrieved passwd structure in the
  space pointed to by pwbuf. This passwd structure contains pointers
  to strings, and these strings are stored in the buffer buf of
  size buflen. A pointer to the result (in case of success) or NULL
  (in case no entry was found or an error occurred) is stored in
  *pwbufp.

Bildişim kadarı ile getpwuid_r() fonksiyonu, bulduğu passwd yapısını,
bizim gösterdiğimiz alan olan pwdbuf'a koyuyor. ("... store the
retrieved passwd structure in the space pointed to by pwbuf.") Ve
new_pw işaretçişi old_pw'yi işaret edecek şekilde ayarlanıyor.
(A pointer to the result (in case of success) or NULL (in case no
entry was found or an error occurred) is stored in *pwbufp.)

Ama ben gene de sizin önerinizi deneyip:

    struct passwd *new_pw;

    [new_pw = malloc(sizeof(struct passwd))]
    ret = getpwuid_r(proc_id, &old_pw, buf, sz, &new_pw);
    if (ret)
        fprintf(stderr, "getpwuid_r() failed! ret = %d\n", ret);
    [free(new_pw);]

kombinasyonlarını denedim. Yine bir sonuç alamadım.

İyi çalışmalar.

_______________________________________________
Linux-programlama mailing list
Linux-programlama@liste.linux.org.tr
http://liste.linux.org.tr/mailman/listinfo/linux-programlama


New Message Reply About this list Date view Thread view Subject view Author view Attachment view

---------

Bu arsiv hypermail 2.1.2 tarafindan uretilmistir.