[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getprogname() for IBM z/OS
From: |
Pádraig Brady |
Subject: |
Re: getprogname() for IBM z/OS |
Date: |
Wed, 12 Oct 2016 11:04:55 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
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