1 /* $NetBSD: argv_attr_print.c,v 1.3 2022/10/08 16:12:50 christos Exp $ */ 2 3 /*++ 4 /* NAME 5 /* argv_attr_print 6 /* SUMMARY 7 /* write ARGV to stream 8 /* SYNOPSIS 9 /* #include <argv_attr.h> 10 /* 11 /* int argv_attr_print(print_fn, stream, flags, ptr) 12 /* ATTR_PRINT_COMMON_FN print_fn; 13 /* VSTREAM *stream; 14 /* int flags; 15 /* void *ptr; 16 /* DESCRIPTION 17 /* argv_attr_print() writes an ARGV to the named stream using 18 /* the specified attribute print routine. argv_attr_print() is meant 19 /* to be passed as a call-back to attr_print(), thusly: 20 /* 21 /* ... SEND_ATTR_FUNC(argv_attr_print, (const void *) argv), ... 22 /* DIAGNOSTICS 23 /* Fatal: out of memory. 24 /* 25 /* The result value is zero in case of success, non-zero 26 /* otherwise. 27 /* LICENSE 28 /* .ad 29 /* .fi 30 /* The Secure Mailer license must be distributed with this software. 31 /* AUTHOR(S) 32 /* Wietse Venema 33 /* Google, Inc. 34 /* 111 8th Avenue 35 /* New York, NY 10011, USA 36 /*--*/ 37 38 /* 39 * System library. 40 */ 41 #include <sys_defs.h> 42 43 /* 44 * Utility library. 45 */ 46 #include <argv.h> 47 #include <argv_attr.h> 48 #include <attr.h> 49 #include <vstream.h> 50 #include <msg.h> 51 52 /* argv_attr_print - write ARGV to stream */ 53 54 int argv_attr_print(ATTR_PRINT_COMMON_FN print_fn, VSTREAM *fp, 55 int flags, const void *ptr) 56 { 57 ARGV *argv = (ARGV *) ptr; 58 int n; 59 int ret; 60 int argc = argv ? argv->argc : 0; 61 62 ret = print_fn(fp, flags | ATTR_FLAG_MORE, 63 SEND_ATTR_INT(ARGV_ATTR_SIZE, argc), 64 ATTR_TYPE_END); 65 if (msg_verbose) 66 msg_info("argv_attr_print count=%d", argc); 67 for (n = 0; ret == 0 && n < argc; n++) 68 ret = print_fn(fp, flags | ATTR_FLAG_MORE, 69 SEND_ATTR_STR(ARGV_ATTR_VALUE, argv->argv[n]), 70 ATTR_TYPE_END); 71 if (msg_verbose) 72 msg_info("argv_attr_print ret=%d", ret); 73 /* Do not flush the stream. */ 74 return (ret); 75 } 76