1N/A/*
1N/A * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A * Copyright (c) 1990, 1993
1N/A * The Regents of the University of California. All rights reserved.
1N/A *
1N/A * This code is derived from software contributed to Berkeley by
1N/A * Chris Torek.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_RCSID("@(#)$Id: sscanf.c,v 1.25 2002/02/01 02:28:00 ca Exp $")
1N/A#include <string.h>
1N/A#include <sm/varargs.h>
1N/A#include <sm/io.h>
1N/A#include "local.h"
1N/A
1N/A/*
1N/A** SM_EOFREAD -- dummy read function for faked file below
1N/A**
1N/A** Parameters:
1N/A** fp -- file pointer
1N/A** buf -- location to place read data
1N/A** len -- number of bytes to read
1N/A**
1N/A** Returns:
1N/A** 0 (zero) always
1N/A*/
1N/A
1N/Astatic ssize_t
1N/Asm_eofread __P((
1N/A SM_FILE_T *fp,
1N/A char *buf,
1N/A size_t len));
1N/A
1N/A/* ARGSUSED0 */
1N/Astatic ssize_t
1N/Asm_eofread(fp, buf, len)
1N/A SM_FILE_T *fp;
1N/A char *buf;
1N/A size_t len;
1N/A{
1N/A return 0;
1N/A}
1N/A
1N/A/*
1N/A** SM_IO_SSCANF -- scan a string to find data units
1N/A**
1N/A** Parameters:
1N/A** str -- strings containing data
1N/A** fmt -- format directive for finding data units
1N/A** ... -- memory locations to place format found data units
1N/A**
1N/A** Returns:
1N/A** Failure: SM_IO_EOF
1N/A** Success: number of data units found
1N/A**
1N/A** Side Effects:
1N/A** Attempts to strlen() 'str'; if not a '\0' terminated string
1N/A** then the call may SEGV/fail.
1N/A** Faking the string 'str' as a file.
1N/A*/
1N/A
1N/Aint
1N/A#if SM_VA_STD
1N/Asm_io_sscanf(const char *str, char const *fmt, ...)
1N/A#else /* SM_VA_STD */
1N/Asm_io_sscanf(str, fmt, va_alist)
1N/A const char *str;
1N/A char *fmt;
1N/A va_dcl
1N/A#endif /* SM_VA_STD */
1N/A{
1N/A int ret;
1N/A SM_FILE_T fake;
1N/A SM_VA_LOCAL_DECL
1N/A
1N/A fake.sm_magic = SmFileMagic;
1N/A fake.f_flags = SMRD;
1N/A fake.f_bf.smb_base = fake.f_p = (unsigned char *) str;
1N/A fake.f_bf.smb_size = fake.f_r = strlen(str);
1N/A fake.f_file = -1;
1N/A fake.f_read = sm_eofread;
1N/A fake.f_write = NULL;
1N/A fake.f_close = NULL;
1N/A fake.f_open = NULL;
1N/A fake.f_seek = NULL;
1N/A fake.f_setinfo = fake.f_getinfo = NULL;
1N/A fake.f_type = "sm_io_sscanf:fake";
1N/A fake.f_flushfp = NULL;
1N/A fake.f_ub.smb_base = NULL;
1N/A fake.f_timeout = SM_TIME_FOREVER;
1N/A fake.f_timeoutstate = SM_TIME_BLOCK;
1N/A SM_VA_START(ap, fmt);
1N/A ret = sm_vfscanf(&fake, SM_TIME_FOREVER, fmt, ap);
1N/A SM_VA_END(ap);
1N/A return ret;
1N/A}