libprocstat.c (416ba5c74546f32a993436a99516d35008e9f384) | libprocstat.c (14bdbaf2e40a827e84f6c2fe27b1f8229767f03c) |
---|---|
1/*- 2 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org> 3 * Copyright (c) 1988, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 753 unchanged lines hidden (view full) --- 762 */ 763 764 /* Pass 1: count items */ 765 cnt = 0; 766 bp = buf; 767 eb = buf + len; 768 while (bp < eb) { 769 kf = (struct kinfo_file *)(uintptr_t)bp; | 1/*- 2 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org> 3 * Copyright (c) 1988, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 753 unchanged lines hidden (view full) --- 762 */ 763 764 /* Pass 1: count items */ 765 cnt = 0; 766 bp = buf; 767 eb = buf + len; 768 while (bp < eb) { 769 kf = (struct kinfo_file *)(uintptr_t)bp; |
770 if (kf->kf_structsize == 0) 771 break; |
|
770 bp += kf->kf_structsize; 771 cnt++; 772 } 773 774 kif = calloc(cnt, sizeof(*kif)); 775 if (kif == NULL) { 776 free(buf); 777 return (NULL); 778 } 779 bp = buf; 780 eb = buf + len; 781 kp = kif; 782 /* Pass 2: unpack */ 783 while (bp < eb) { 784 kf = (struct kinfo_file *)(uintptr_t)bp; | 772 bp += kf->kf_structsize; 773 cnt++; 774 } 775 776 kif = calloc(cnt, sizeof(*kif)); 777 if (kif == NULL) { 778 free(buf); 779 return (NULL); 780 } 781 bp = buf; 782 eb = buf + len; 783 kp = kif; 784 /* Pass 2: unpack */ 785 while (bp < eb) { 786 kf = (struct kinfo_file *)(uintptr_t)bp; |
787 if (kf->kf_structsize == 0) 788 break; |
|
785 /* Copy/expand into pre-zeroed buffer */ 786 memcpy(kp, kf, kf->kf_structsize); 787 /* Advance to next packed record */ 788 bp += kf->kf_structsize; 789 /* Set field size to fixed length, advance */ 790 kp->kf_structsize = sizeof(*kp); 791 kp++; 792 } --- 1737 unchanged lines hidden --- | 789 /* Copy/expand into pre-zeroed buffer */ 790 memcpy(kp, kf, kf->kf_structsize); 791 /* Advance to next packed record */ 792 bp += kf->kf_structsize; 793 /* Set field size to fixed length, advance */ 794 kp->kf_structsize = sizeof(*kp); 795 kp++; 796 } --- 1737 unchanged lines hidden --- |