> -----Original Message-----
> From: IBM Mainframe Discussion List
> [mailto:[email protected]] On Behalf Of Charles Mills
> Sent: Thursday, December 03, 2009 9:08 AM
> To: [email protected]
> Subject: Re: Is there a good mailing list or forum for
> mainframe C/C++ specifically?
>
> I'm new to C++ so there are going to be a LOT of them. <g>
>
> The question of the moment is "is there no 'safe' string copy library
> routine such as strcpy_s? I don't see it in the doc."
>
> Charles
Out of curiousity, I looked at the MSDN article for strcpy_s. Basically, it
copies the bytes from one area to another, but only if the entire source will
fit in the destination area (the size of which is passed in the strcpy_s parm
list). If there is any "problem", then the destination is not modified at all.
I don't see any such in z/OS C, but you could "roll your own". I'd likely use
memcpy(). Something like:
#define _X_OPEN
#include <string.h>
#include <errno.h>
int strcpy_s(char *dest, size_t elements, const char *source) {
size_t src_len;
if (dest == NULL) return EINVAL;
if (source == NULL) return EINVAL;
if (elements == 0) return ERANGE;
src_len=strlen(source)+1; /* add 1 to include \0 terminator */
if (src_len > elements) return ERANGE;
memcpy(dest,source,src_len);
return 0;
}
--
John McKown
Systems Engineer IV
IT
Administrative Services Group
HealthMarkets(r)
9151 Boulevard 26 * N. Richland Hills * TX 76010
(817) 255-3225 phone * (817)-961-6183 cell
[email protected] * www.HealthMarkets.com
Confidentiality Notice: This e-mail message may contain confidential or
proprietary information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message.
HealthMarkets(r) is the brand name for products underwritten and issued by the
insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance
Company(r), Mid-West National Life Insurance Company of TennesseeSM and The
MEGA Life and Health Insurance Company.SM
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html