Sponsored Content
Top Forums Programming does snprintf guarantee null termination? Post 302196001 by shamrock on Friday 16th of May 2008 11:40:11 AM
Old 05-16-2008
I would rely on the manpage of snprintf() on your system instead of on a certain someone. You can write a small code snippet to verify if snprintf() provides that functionality.
 

7 More Discussions You Might Find Interesting

1. Solaris

problem with sprintf snprintf in Solaris

******************************** Following is not the real issue. The issue is with popen. Plz continue forward with the thread to get a better picture. ******************************** Hi, I am working on a customised ftp application. In it we have used sprintf to store a UNIX command... (7 Replies)
Discussion started by: diganta
7 Replies

2. Shell Programming and Scripting

random script termination

I'm writing a script to archive data. First, the files are all rsync'd to the archive directory via NFS mounts(I know not the most efficient, but the only choice in this situation), then I use md5sum to validate the transfers. During execution of the script, it will exit for no apparent reason. It... (6 Replies)
Discussion started by: mph
6 Replies

3. Shell Programming and Scripting

Perl script to search sprintf and replace with snprintf

Dear all, I am new to perl script and would need some help for my 1st script. I wrote a script to search sprintf(buf,"%s", sourcestring) and replace with snprintf(buf, sizeof(buf),"%s", sourcestring). As snprintf() requires an extra argument, so it is not a simple search-and-replace. I need to... (1 Reply)
Discussion started by: ChaMeN
1 Replies

4. Shell Programming and Scripting

search sprintf and replace with snprintf

Hi, anyone knows the perl search-and-replace expression for strcpy (char * destination, const char * source ); to strncpy ( char * destination, const char * source, size_t num ); ? the first and second arguments are the same (destination and source), the difference being that strncpy... (1 Reply)
Discussion started by: ChaMeN
1 Replies

5. Shell Programming and Scripting

guarantee to start before restart...

Hi All, is there a way or script that i can check my AIX 5.3 OS will restart before i made restart? is there a script that can check all the startup files are ok before restarting. it is because i was stuck last time when i restart my PC because some startup files were missing:o. (2 Replies)
Discussion started by: malcomex999
2 Replies

6. Shell Programming and Scripting

Problem with ssh termination...

hi all, i have a situation where i run ssh command from a unix machine to execute few scripts on 2 other unix machines. my problem is, the scripts that i run will start few commands on the 2 servers and will quit....i am able to quit from the script but i have to give ctrl+c (on the... (10 Replies)
Discussion started by: niteesh_!7
10 Replies

7. AIX

A question about scsi termination

http://ep.yimg.com/ay/iercomputer/ibm-39j5022-ultra320-scsi-adapter-dual-channel-pci-x-fc5736-3.gif I have bought this controller. Simple and fast question: I will put on this controller a external LTO tape,which is terminated with a terminator. I have to put another terminator on PCI-controller... (1 Reply)
Discussion started by: Linusolaradm1
1 Replies
STRFROMD(3)						     Linux Programmer's Manual						       STRFROMD(3)

NAME
strfromd, strfromf, strfroml - convert a floating-point value into a string SYNOPSIS
#include <stdlib.h> int strfromd(char *restrict str, size_t n, const char *restrict format, double fp); int strfromf(char *restrict str, size_t n, const char *restrict format, float fp); int strfroml(char *restrict str, size_t n, const char *restrict format, long double fp); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): strfromd(), strfromf(), strfroml(): __STDC_WANT_IEC_60559_BFP_EXT__ DESCRIPTION
These functions convert a floating-point value, fp, into a string of characters, str, with a configurable format string. At most n charac- ters are stored into str. The terminating null character ('') is written if and only if n is sufficiently large, otherwise the written string is truncated at n characters. The strfromd(), strfromf(), and strfroml() functions are equivalent to snprintf(str, n, format, fp); except for the format string. Format of the format string The format string must start with the character '%'. This is followed by an optional precision which starts with the period character (.), followed by an optional decimal integer. If no integer is specified after the period character, a precision of zero is used. Finally, the format string should have one of the conversion specifiers a, A, e, E, f, F, g, or G. The conversion specifier is applied based on the floating-point type indicated by the function suffix. Therefore, unlike snprintf(), the format string does not have a length modifier character. See snprintf(3) for a detailed description of these conversion specifiers. The implementation conforms to the C99 standard on conversion of NaN and infinity values: If fp is a NaN, +NaN, or -NaN, and f (or a, e, g) is the conversion specifier, the conversion is to "nan", "nan", or "-nan", respec- tively. If F (or A, E, G) is the conversion specifier, the conversion is to "NAN" or "-NAN". Likewise if fp is infinity, it is converted to [-]inf or [-]INF. A malformed format string results in undefined behavior. RETURN VALUE
The strfromd(), strfromf(), and strfroml() functions return the number of characters that would have been written in str if n had enough space, not counting the terminating null character. Thus, a return value of n or greater means that the output was truncated. VERSIONS
The strfromd(), strfromf(), and strfroml() functions are available in glibc since version 2.25. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7) and the POSIX Safety Concepts section in GNU C Library manual. +------------+----------------------------------+----------------+ |Interface | Attribute | Value | +------------+----------------------------------+----------------+ | | Thread safety | MT-Safe locale | |strfromd(), +----------------------------------+----------------+ |strfromf(), | Asynchronous signal safety | AS-Unsafe heap | |strfroml() +----------------------------------+----------------+ | | Asynchronous cancellation safety | AC-Unsafe mem | +------------+----------------------------------+----------------+ Note: these attributes are preliminary. CONFORMING TO
C99, ISO/IEC TS 18661-1. NOTES
The strfromd(), strfromf(), and strfroml() functions take account of the LC_NUMERIC category of the current locale. EXAMPLES
To convert the value 12.1 as a float type to a string using decimal notation, resulting in "12.100000": #define __STDC_WANT_IEC_60559_BFP_EXT__ #include <stdlib.h> int ssize = 10; char s[ssize]; strfromf(s, ssize, "%f", 12.1); To convert the value 12.3456 as a float type to a string using decimal notation with two digits of precision, resulting in "12.35": #define __STDC_WANT_IEC_60559_BFP_EXT__ #include <stdlib.h> int ssize = 10; char s[ssize]; strfromf(s, ssize, "%.2f", 12.3456); To convert the value 12.345e19 as a double type to a string using scientific notation with zero digits of precision, resulting in "1E+20": #define __STDC_WANT_IEC_60559_BFP_EXT__ #include <stdlib.h> int ssize = 10; char s[ssize]; strfromd(s, ssize, "%.E", 12.345e19); SEE ALSO
atof(3), snprintf(3), strtod(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2017-09-15 STRFROMD(3)
All times are GMT -4. The time now is 10:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy