librnr  1.14.5
RoadNarrows Robotics Common Library 1
win.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Common Library 1
4 //
5 // Library: librnr
6 //
7 // File: win.c
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2010-03-24 10:19:36 -0600 (Wed, 24 Mar 2010) $
12  * $Rev: 307 $
13  *
14  * \brief Windows functions for linux.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \pkgcopyright{2005-2018,RoadNarrows LLC.,http://www.roadnarrows.com}
19  */
20 // Permission is hereby granted, without written agreement and without
21 // license or royalty fees, to use, copy, modify, and distribute this
22 // software and its documentation for any purpose, provided that
23 // (1) The above copyright notice and the following two paragraphs
24 // appear in all copies of the source code and (2) redistributions
25 // including binaries reproduces these notices in the supporting
26 // documentation. Substantial modifications to this software may be
27 // copyrighted by their authors and need not follow the licensing terms
28 // described here, provided that the new terms are clearly indicated in
29 // all files where they apply.
30 //
31 // IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
32 // OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
33 // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
34 // DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
35 // EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
36 // THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
39 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
40 // FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
41 // "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
42 // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
43 //
44 ////////////////////////////////////////////////////////////////////////////////
45 
46 #include "rnr/rnrconfig.h"
47 #include "rnr/new.h"
48 
49 #if !defined(__windows__)
50 
51 #include <sys/types.h>
52 #include <stdio.h>
53 #include <string.h>
54 
55 /*!
56  * \brief Copy source string to destinations string. At most n bytes will be
57  * copied. The destination string is guaranteed to be null terminated.
58  *
59  * \param dest Pointer to destination string.
60  * \param n Maximum number of bytes to copy.
61  * \param src Pointer to source string.
62  *
63  * \return Return pointer to destination string.
64  */
65 char *strcpy_s(char *dest, size_t n, const char *src)
66 {
67  strncpy(dest, src, (size_t)n);
68  dest[n-1] = 0;
69  return dest;
70 }
71 
72 /*!
73  * \brief Format print to string up to n-1 characters. String is
74  * guaranteed to be null terminated.
75  *
76  * \param str Destination string buffer.
77  * \param n Size of string buffer.
78  * \param format Standard printf formatting string.
79  * \param ... Variable argument list.
80  *
81  * \return Number of characters printed.
82  */
83 int sprintf_s(char *str, size_t n, const char *format, ...)
84 {
85  va_list ap;
86  int nPrinted;
87 
88  va_start(ap, format);
89  nPrinted = vsnprintf(str, (size_t)n, format, ap);
90  va_end(ap);
91  str[n-1] = 0;
92  return nPrinted;
93 }
94 
95 #endif // __windows__
Memory allocation and deallocation declarations.
int sprintf_s(char *str, size_t n, const char *format,...)
Format print to string up to n-1 characters. String is guaranteed to be null terminated.
Definition: win.c:83
RoadNarrows Robotics common configuration file.
char * strcpy_s(char *dest, size_t n, const char *src)
Copy source string to destinations string. At most n bytes will be copied. The destination string is ...
Definition: win.c:65