delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/06/16/00:21:31

From: "Richard E. Stone" <restone AT skypoint DOT com>
To: <djgpp-workers AT delorie DOT com>
Subject: RE: stpncpy
Date: Thu, 15 Jun 2000 23:16:58 -0500
Message-ID: <LPBBINFBCBNBLIBJHPBGAEILCAAA.restone@skypoint.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
In-Reply-To: <200006081919.PAA07949@envy.delorie.com>
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

This is a multi-part message in MIME format.

------=_NextPart_000_0000_01BFD71F.CDA58CC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

OK, I'll give it a go.  I don't have the latest CVS versions (or even
know what CVS is), but I have djlsr203.zip and (given what needs to be
done) that should be good enough.  If it isn't, just forget it and I can
add stpncpy to my copy of libc.a each time I upgrade.

It seems that two files need to be added and two need to be changed.

One file needed is the source for stpncpy (attached as stpncpy.c).
This is based on the code in strncpy.c and stpcpy.c found in djlsr203.zip.

The other file to be added is stpncpy.txh, which is attached and based
on the file stpcpy.txh found in djlsr203.zip.

The string.h file needs to be updated with a line about stpncpy.
I updated my string.h and it is attached.

The makefile in src\libc\compat\string needs to have a line added
(it seems) so that it looks like the makefile attached.

All the files listed here would be in src\libc\compat\string except
for string.h.

Again, if this doesn't "fit into the system" then just drop it.

Thanks.

--- Richard Stone

> -----Original Message-----
> From: DJ Delorie [mailto:dj AT delorie DOT com]
> Sent: Thursday, June 08, 2000 2:19 PM
> To: restone AT skypoint DOT com
> Subject: stpncpy
> 
> 
> 
> Thanks for the donation!
> 
> The reason we don't have stpncpy is because nobody has added it yet.
> For functions not required by standards, it's difficult to know that
> they're needed, so we rely on people mentioning them and adding them.
> 
> If you'd like to submit a patch to add that, please do.  Remember that
> such a patch would need to include a change to string.h and a
> documentation file (*.txh).  Patches should be sent to
> djgpp-workers AT delorie DOT com and should be made relative to the latest
> CVS versions of the files.
> 
> Thanks,
> DJ
> 
------=_NextPart_000_0000_01BFD71F.CDA58CC0
Content-Type: application/octet-stream;
	name="STPNCPY.C"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="STPNCPY.C"

/* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
#include <string.h>

char *
stpncpy(char *dst, const char *src, size_t n)
{
  if (!dst || !src)
    return 0;

  if (n != 0) {
    do {
      if ((*dst++ = *src++) == 0)
      {
	dst += n - 1;
	do {
	  *--dst = 0;
	} while (--n != 0);
	break;
      }
    } while (--n != 0);
  }
  return dst;
}

------=_NextPart_000_0000_01BFD71F.CDA58CC0
Content-Type: application/octet-stream;
	name="STPNCPY.TXH"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="STPNCPY.TXH"

@node stpncpy, string
@subheading Syntax

@example
#include <string.h>

char *stpncpy(char *_dest, const char *_src, size_t _n);
@end example

@subheading Description

Copies exactly @var{_n} characters from @var{_src} to @var{_dest}.
If need be, @var{_dest} is padded with zeros to make @var{_n} characters.
Like @code{strncpy} (@pxref{strncpy}), but return value different.

@subheading Return Value

Returns a pointer to the character following the last nonzero written.

@subheading Portability

@portability !ansi, !posix


------=_NextPart_000_0000_01BFD71F.CDA58CC0
Content-Type: application/octet-stream;
	name="STRING.H"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="STRING.H"

/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#ifndef __dj_include_string_h_
#define __dj_include_string_h_

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __dj_ENFORCE_ANSI_FREESTANDING

#include <sys/djtypes.h>
    
/* Some programs think they know better... */
#undef NULL

#define NULL 0
__DJ_size_t
#undef __DJ_size_t
#define __DJ_size_t

void *	memchr(const void *_s, int _c, size_t _n);
int	memcmp(const void *_s1, const void *_s2, size_t _n);
void *	memcpy(void *_dest, const void *_src, size_t _n);
void *	memmove(void *_s1, const void *_s2, size_t _n);
void *	memset(void *_s, int _c, size_t _n);
char *	strcat(char *_s1, const char *_s2);
char *	strchr(const char *_s, int _c);
int	strcmp(const char *_s1, const char *_s2);
int	strcoll(const char *_s1, const char *_s2);
char *	strcpy(char *_s1, const char *_s2);
size_t	strcspn(const char *_s1, const char *_s2);
char *	strerror(int _errcode);
size_t	strlen(const char *_s);
char *	strncat(char *_s1, const char *_s2, size_t _n);
int	strncmp(const char *_s1, const char *_s2, size_t _n);
char *	strncpy(char *_s1, const char *_s2, size_t _n);
char *	strpbrk(const char *_s1, const char *_s2);
char *	strrchr(const char *_s, int _c);
size_t	strspn(const char *_s1, const char *_s2);
char *	strstr(const char *_s1, const char *_s2);
char *	strtok(char *_s1, const char *_s2);
size_t	strxfrm(char *_s1, const char *_s2, size_t _n);

#ifndef __STRICT_ANSI__

#ifndef _POSIX_SOURCE

#include <sys/movedata.h>

int	bcmp(const void *_ptr1, const void *_ptr2, int _length);
void *	bcopy(const void *_a, void *_b, size_t _len);
void *	bzero(void *ptr, size_t _len);
int	ffs(int _mask);
char *  index(const char *_string, int _c);
void *	memccpy(void *_to, const void *_from, int c, size_t n);
int	memicmp(const void *_s1, const void *_s2, size_t _n);
char *  rindex(const char *_string, int _c);
char *	stpcpy(char *_dest, const char *_src);
char *	stpncpy(char *_dest, const char *_src, size_t _n);
char *	strdup(const char *_s);
char *	strlwr(char *_s);
int	strcasecmp(const char *_s1, const char *_s2);
int	stricmp(const char *_s1, const char *_s2);
int	strncasecmp(const char *_s1, const char *_s2, size_t _n);
int	strnicmp(const char *_s1, const char *_s2, size_t _n);
char *	strsep(char **_stringp, const char *_delim);
char *	strupr(char *_s);

#endif /* !_POSIX_SOURCE */
#endif /* !__STRICT_ANSI__ */
#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */

#ifndef __dj_ENFORCE_FUNCTION_CALLS
#endif /* !__dj_ENFORCE_FUNCTION_CALLS */

#ifdef __cplusplus
}
#endif

#endif /* !__dj_include_string_h_ */

------=_NextPart_000_0000_01BFD71F.CDA58CC0
Content-Type: application/octet-stream;
	name="MAKEFILE"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="MAKEFILE"

# Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details
# Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
TOP=../..

SRC += ffs.S
SRC += memccpy.c
SRC += memicmp.c
SRC += stpcpy.c
SRC += stpncpy.c
SRC += strcasec.S
SRC += strdup.c
SRC += stricmp.c
SRC += strlwr.c
SRC += strncase.S
SRC += strnicmp.c
SRC += strsep.c
SRC += strupr.c

include $(TOP)/../makefile.inc

------=_NextPart_000_0000_01BFD71F.CDA58CC0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019