985 * This function should write sortkey_width bytes into buf which will
986 * cause memcmp() to sort it properly. (Unlike sprint() above,
987 * however, an extra null byte may overrun the buffer.) The second
988 * argument controls whether the results are sorted in forward or
989 * reverse order.
990 */
991 void (*get_sortkey)(char *, int, scf_walkinfo_t *);
992 };
993
994 static void
995 reverse_bytes(char *buf, size_t len)
996 {
997 int i;
998
999 for (i = 0; i < len; ++i)
1000 buf[i] = ~buf[i];
1001 }
1002
1003 /* CTID */
1004 #define CTID_COLUMN_WIDTH 6
1005
1006 static void
1007 sprint_ctid(char **buf, scf_walkinfo_t *wip)
1008 {
1009 int r;
1010 uint64_t c;
1011 size_t newsize = (*buf ? strlen(*buf) : 0) + CTID_COLUMN_WIDTH + 2;
1012 char *newbuf = safe_malloc(newsize);
1013 int restarter_spec;
1014
1015 /*
1016 * Use the restarter specific get pids routine, if available.
1017 * Only check for non-legacy services (wip->pg == 0).
1018 */
1019 if (wip->pg != NULL) {
1020 r = pg_get_single_val(wip->pg, scf_property_contract,
1021 SCF_TYPE_COUNT, &c, 0, EMPTY_OK | MULTI_OK);
1022 } else {
1023 r = ctids_by_restarter(wip, &c, 0, MULTI_OK, &restarter_spec,
1024 NULL, NULL);
1025 if (restarter_spec == 0) {
1026 /* No restarter specific routine */
1027 r = get_restarter_count_prop(wip->inst,
1028 scf_property_contract, &c, EMPTY_OK | MULTI_OK);
1029 }
1030 }
1031
|
985 * This function should write sortkey_width bytes into buf which will
986 * cause memcmp() to sort it properly. (Unlike sprint() above,
987 * however, an extra null byte may overrun the buffer.) The second
988 * argument controls whether the results are sorted in forward or
989 * reverse order.
990 */
991 void (*get_sortkey)(char *, int, scf_walkinfo_t *);
992 };
993
994 static void
995 reverse_bytes(char *buf, size_t len)
996 {
997 int i;
998
999 for (i = 0; i < len; ++i)
1000 buf[i] = ~buf[i];
1001 }
1002
1003 /* CTID */
1004 #define CTID_COLUMN_WIDTH 6
1005 #define CTID_COLUMN_BUFSIZE 20 /* max ctid_t + space + \0 */
1006
1007 static void
1008 sprint_ctid(char **buf, scf_walkinfo_t *wip)
1009 {
1010 int r;
1011 uint64_t c;
1012 size_t newsize = (*buf ? strlen(*buf) : 0) + CTID_COLUMN_BUFSIZE;
1013 char *newbuf = safe_malloc(newsize);
1014 int restarter_spec;
1015
1016 /*
1017 * Use the restarter specific get pids routine, if available.
1018 * Only check for non-legacy services (wip->pg == 0).
1019 */
1020 if (wip->pg != NULL) {
1021 r = pg_get_single_val(wip->pg, scf_property_contract,
1022 SCF_TYPE_COUNT, &c, 0, EMPTY_OK | MULTI_OK);
1023 } else {
1024 r = ctids_by_restarter(wip, &c, 0, MULTI_OK, &restarter_spec,
1025 NULL, NULL);
1026 if (restarter_spec == 0) {
1027 /* No restarter specific routine */
1028 r = get_restarter_count_prop(wip->inst,
1029 scf_property_contract, &c, EMPTY_OK | MULTI_OK);
1030 }
1031 }
1032
|