On 12/10/16 09:51, Daniel Richard G. wrote:
> +#elif __MVS__
> +  /* 
> https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/rtwgetp.htm
>  */
> +  char *p = "?";
> +  pid_t pid = getpid ();
> +  int token;
> +  W_PSPROC buf;
> +  memset (&buf, 0, sizeof(buf));
> +  buf.ps_cmdptr    = (char *) malloc (buf.ps_cmdlen    = PS_CMDBLEN_LONG);
> +  buf.ps_conttyptr = (char *) malloc (buf.ps_conttylen = PS_CONTTYBLEN);
> +  buf.ps_pathptr   = (char *) malloc (buf.ps_pathlen   = PS_PATHBLEN);
> +  if (buf.ps_cmdptr && buf.ps_conttyptr && buf.ps_pathptr)
> +    {
> +      for (token = 0; token >= 0;
> +           token = w_getpsent (token, &buf, sizeof(buf)))
> +        {
> +          if (token > 0 && buf.ps_pid == pid)
> +            {
> +              p = strdup (last_component (buf.ps_pathptr));

You only want to strdup once.
So you could use a static to track that as is done in the AIX case.

> +              break;
> +            }
> +        }
> +    }
> +  if (buf.ps_cmdptr)    free (buf.ps_cmdptr);
> +  if (buf.ps_conttyptr) free (buf.ps_conttyptr);
> +  if (buf.ps_pathptr)   free (buf.ps_pathptr);
> +  return p;

You can call free(NULL), so the last 3 ifs are redundant.

thanks!
Pádraig

Reply via email to