pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

As per the man page, pstat_getdisk() call returns the number of instances, which could be 0 upon successful completion, otherwise a value of -1 is returned.

Please have a look at this sample program ->

#include <stdio.h>
#include <sys/pstat.h>

int main()
{
int j = 0, ret;
struct pst_diskinfo sDiskData;

while(1)
{
ret = pstat_getdisk(&sDiskData, sizeof(sDiskData), 1, j);
if(ret<0)
{
printf("\nReturned with code %d \n",ret);
break;
}
printf("\n Ret Code : %d , Device Name : %s%d",ret,sDiskData.psd_drv_name.psd_name,sDiskData.psd_instance);
j++;
}
return 0;
}

On HP-UX 11.11 and 11.23, the call pstat_getdisk() returns series of �1�s then single �0� and finally �-1� and the program terminates successfully.

On HP-UX 11.31 the call pstat_getdisk() returns series of �1�s followed by series of �0�s and never returns �-1�, so the same program never terminates.

The workaround would be to replace the condition
if(ret<0)
with
if(ret==0)

But, will this call always returns �1�s followed by �0�s or there can be a case in which the call will return �0� in between?

In another way, can we get an invalid index in between or all the valid disks are in sequence only?

I think it's maybe the other way around. 11.31 is working correctly. Anyway. pstat_getdisk is supposed to return -1 on error and return the number of instances processed. You do know you could set the index to start, and get, say, 40 disks with one call?

Read the docset for pstat here (the man pages are, um, not helpful sometimes)
http://docs.hp.com/en/1216/pstat_whitepaper.pdf

Thanks a lot for your valuable comment.
I need to query this call with 1 element only and I have to process the output.
So is it for sure that pstat_getdisk() always returns 0 at the end of the list only and not in between?
Can we break the loop on if(ret <= 0) condition?