This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use kinfo_getfile to implement fdwalk on FreeBSD.


On 11/30/2018 10:15 PM, Tom Tromey wrote:

> John> +#ifdef HAVE_KINFO_GETFILE
> John> +  gdb::unique_xmalloc_ptr<struct kinfo_file> fdtbl;
> John> +  int nfd;
> John> +  fdtbl.reset (kinfo_getfile (getpid (), &nfd));
> 
> I think this should be combined with the declaration; no need to call
> reset.
If you want, you can also use the array-version of unique_ptr
and eliminate some variables:

  int nfd;
  gdb::unique_xmalloc_ptr<struct kinfo_file[]> fdtbl
   (kinfo_getfile (getpid (), &nfd));
  if (fdtbl != NULL)
    {
      for (int i = 0; i < nfd; i++)
	{
	  if (fdtbl[i]->kf_fd >= 0)
	    {
	      int result = func (arg, fdtbl[i]->kf_fd);
	      if (result != 0)
		return result;
            }
        }
      return 0;
    }

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]