hi all,
i am writing a code in which i have a char buffer "cwdir[]"
which hold the current working directory by calling the function
getcwd(). later i change the directory to "/" as i have to make my
code Deamon. and later again i want to run some other executable
available at the path holded by the "cwdir[]" using the system()
system call. presently i concatenate program name (to be executed) to
the "cwdir[]" and use system(chdir)to run the program.
do we have any facility to automate this process as i need to run
many other programs also using the system() system call for ex as we
can use the ## symbol to cancatenate in macro ...
--shri
Nov 14 '05
37 8548
In article <8b************ **************@ posting.google. com>, ku****@wizard.n et (James Kuyper) writes: mw*****@newsguy .com (Michael Wojcik) wrote in message news:<c0******* **@enews1.newsg uy.com>... Presumably in at least some cases they could be provided by the implementation, and in such a case programs using them would not invoke UB, correct? You need to be careful when you read the standard, it contains many pieces of technical jargon which are defined by the standard itself to mean something not quite the same as the ordinary english definition. This is one example. "undefined behavior" doesn't mean "behavior that is undefined"; it's a piece of technical jargon used by the C standard, which roughly means "behavior that is not defined by the C standard".
Right. I understood that...
The behavior of such code remains UB even if the implementation chooses to provide it's own definition. UB includes, as one of it's literal infinity of possibilities, behaving exactly as the implementation has defined it to behave.
....but missed this bit when I glanced over the Standard before posting
that message. I somehow got the impression that if the implementation
provided additional str* functions (with external linkage), a program
running under that implementation could invoke them without causing UB.
Which doesn't make much sense, now that I think about it.
(Thanks also to Dan for posting a similar correction.)
--
Michael Wojcik mi************@ microfocus.com
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-- David Bonde
Brian Inglis <Br**********@S ystematicSw.Inv alid> writes: On Fri, 13 Feb 2004 17:12:51 GMT in comp.std.c, Sean Burke <fo****@mystery .org> wrote:
Maurizio Loreti <ml*@foobar.i t> writes:
Da*****@cern.ch (Dan Pop) writes:
> In <x7************ @bolo.xenadyne. com> Sean Burke <fo****@mystery .org> writes: > > >Since you mention security (e.g. buffer overflows), > >it's worth adding that strcpy, strcat have long since > >been deprecated in favor of strlcpy, strlcat. You mispelled n as noted below. On the contrary, any C program using these identifiers with external > linkage invokes undefined behaviour.
Maybe Mr. Burke misspelled "strncpy" and "strncat", mentioned in ISO/IEC 9899:1999 under 7.21.2.4 and 7.21.3.2 ? Their prototypes (in <string.h>) are
char *strncpy(char * restrict, const char * restrict, size_t); char *strncat(char * restrict, const char * restrict, size_t);
No, I meant strlcpy/strlcat, and I find them to be better than the strn* calls. I'm astonished to learn that they aren't yet standardised.
You must be one of those Pascal types who like to access strings as character arrays with indices, instead of pointers as K&R intended. You wouldn't have liked BCPL, B, or NB either! ;^>
The BSD string functions strl{cat,cpy} are unlikely to be standardised as they aren't supported by many libraries, and don't fit with any of the current string handling functions, except strspn() and strcspn(), which are also not heavily advertised or used, as their names are confusing, nondescriptive, unobvious, and they too return counts instead of pointers.
In any case, I prefer to check my string lengths before I do anything with strcpy(); strncpy()'s handy for clearing previous junk from buffers; never need strcat(), as I like to know where I am, and going to be in a buffer. Avoids buffer overflows, heap and stack overwrites, SIGSEGV, ACCVIO, and other unpleasantries, don't ya know.
I'm not sure why you've revived this long-dormant thread.
As far as factual matters go, I recall that the upshot of
the discussion was that:
1. strcpy/strcat have not been formally deprecated in the
C standard
2. strlcpy/strlcat have not been incorporated into the
C standard
As far as matters of preference go, if you find strncpy/ncat
adequate for your needs, that's great. I agree that strlen()
alone is sufficient to avoid overflows with strcpy/cat, as
long as you are careful.
I find that code using strlcpy/lcat is cleaner and less
susceptible to error, but YMMV.
Oh, and as for strspn, strcspn - I find these are very useful
functions, but it's another example of the power of idiom in
programming. It took me a long time to notice that I could
this, for example:
if (strspn(argv[i], "-0123456789") != strlen(argv[i]))
fprintf(stderr, "The argument \"%s\" must be a decimal integer.\n", argv[i]);
-SEan
Brian Inglis wrote:
.... snip ... The BSD string functions strl{cat,cpy} are unlikely to be standardised as they aren't supported by many libraries, and don't fit with any of the current string handling functions, except strspn() and strcspn(), which are also not heavily advertised or used, as their names are confusing, nondescriptive, unobvious, and they too return counts instead of pointers.
Which (return values) is precisely why they should be used in
preference to the already available standard routines. They
greatly reduce the prevalence of errors. They are also easily
implemented with purely standard C and no library dependencies, so
there is no reason to eschew them. For one implementation (put in
public domain) see:
<http://cbfalconer.home .att.net/download/strlcpy.zip>
For justifications for their use, etc, see:
<http://www.courtesan.c om/todd/papers/strlcpy.html>
If your system has these routines, congratulations . If not, feel
free to mount mine. In either case using them will reduce your
error rate.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Sean Burke <fo****@mystery .org> writes:
[...] Oh, and as for strspn, strcspn - I find these are very useful functions, but it's another example of the power of idiom in programming. It took me a long time to notice that I could this, for example:
if (strspn(argv[i], "-0123456789") != strlen(argv[i])) fprintf(stderr, "The argument \"%s\" must be a decimal integer.\n", argv[i]);
[code reformatted to fit screen]
That's fine if you consider "3-2", "---", and "" to be decimal integers.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
# > if (strspn(argv[i], "-0123456789") != strlen(argv[i]))
# > fprintf(stderr,
# > "The argument \"%s\" must be a decimal integer.\n",
# > argv[i]);
#
# [code reformatted to fit screen]
#
# That's fine if you consider "3-2", "---", and "" to be decimal integers.
if (strtol(p,&q,0) , p==q) not an integer
else if (*q) integer followed by something else
else an integer
--
Derk Gwen http://derkgwen.250fre e.com/html/index.html
We found a loophole; they can't keep us out anymore.
Derk Gwen <de******@HotPO P.com> writes: # > if (strspn(argv[i], "-0123456789") != strlen(argv[i])) # > fprintf(stderr, # > "The argument \"%s\" must be a decimal integer.\n", # > argv[i]); # # [code reformatted to fit screen] # # That's fine if you consider "3-2", "---", and "" to be decimal integers.
if (strtol(p,&q,0) , p==q) not an integer else if (*q) integer followed by something else else an integer
Anyone who knows how to use strtol doesn't need advice from me. :-)
But how many people just pass the argument to atoi() and let any
problems manifest themselves further along?
I think the method I illustrated has the virtue of being a
"pretty good" filter, while also being much more widely
applicable than strtol().
Suppose I want to accept an IP address, but I want to ensure
that it's not a domain name:
if (strspn(argv[i], ".012345678 9") != strlen(argv[i]))
fprintf(stderr, "Arg \"%s\" must be an numeric IP address.\n", argv[i]);
Sure, "...0" would pass this filter, but the chief goal is
to reject "foo.bar.co m". Yes, I could use inet_addr() instead,
but what does inet_addr() do with "9.37.190.192.i n-addr.arpa"?
Certainly, regcomp/regexec provide a filtering method that can
be both precise and very general. But strspn/cspn() provide a
useful balance of precision and convenience.
-SEan
Derk Gwen <de******@HotPO P.com> writes: # > if (strspn(argv[i], "-0123456789") != strlen(argv[i])) # > fprintf(stderr, # > "The argument \"%s\" must be a decimal integer.\n", # > argv[i]); # # [code reformatted to fit screen] # # That's fine if you consider "3-2", "---", and "" to be decimal integers.
if (strtol(p,&q,0) , p==q) not an integer else if (*q) integer followed by something else else an integer
Anyone who knows how to use strtol doesn't need advice from me. :-)
But how many people just pass the argument to atoi() and let any
problems manifest themselves further along?
I think the method I illustrated has the virtue of being a
"pretty good" filter, while also being much more widely
applicable than strtol().
Suppose I want to accept an IP address, but I want to ensure
that it's not a domain name:
if (strspn(argv[i], ".012345678 9") != strlen(argv[i]))
fprintf(stderr, "Arg \"%s\" must be an numeric IP address.\n", argv[i]);
Sure, "...0" would pass this filter, but the chief goal is
to reject "foo.bar.co m". Yes, I could use inet_addr() instead,
but what does inet_addr() do with "9.37.190.192.i n-addr.arpa"?
Certainly, regcomp/regexec provide a filtering method that can
be both precise and very general. But strspn/cspn() provide a
useful balance of precision and convenience.
-SEan
>>> Sean Burke wrote:
SB> Sure, "...0" would pass this filter, but the chief goal is
SB> to reject "foo.bar.co m". Yes, I could use inet_addr() instead,
SB> but what does inet_addr() do with "9.37.190.192.i n-addr.arpa"?
$ host 127.0.0.1
1.0.0.127.IN-ADDR.ARPA domain name pointer localhost
$ ping 1.0.0.127.in-addr.arpa
ping: cannot resolve 1.0.0.127.in-addr.arpa: No address associated with name
Feel the difference between asking A and PTR ;)
-netch- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jonas Galvez |
last post by:
Is it true that joining the string elements of a list is faster than
concatenating them via the '+' operator?
"".join()
vs
'a'+'b'+'c'
If so, can anyone explain why?
|
by: hagai26 |
last post by:
I am looking for the best and efficient way to replace the first word
in a str, like this:
"aa to become" -> "/aa/ to become"
I know I can use spilt and than join them
but I can also use regular expressions
and I sure there is a lot ways, but I need realy efficient one
|
by: John Ford |
last post by:
For simple string concatenation, is there a difference between...
Dim s As String
s += "add this to string"
....and...
Dim s As String
s = String.Concat(s, "add this to string")
|
by: Justin M. Keyes |
last post by:
Hi,
Please read carefully before assuming that this is the same old
question about string concatenation in C#!
It is well-known that the following concatenation produces multiple
immutable String objects for each statement:
String a = "a";
a += "b";
|
by: Mark A. Sam |
last post by:
Hello,
I am having a problem with imputting into a string variable:
Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDealer,
txtOtherCustType, chkStandardBags, chkCustomBags,txtOtherBags) " + _
"VALUES ('" + txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text
+ "','" + txtEmail.Text + "','" + txtComment.Text + "','" +
| |
by: genc_ymeri |
last post by:
Hi over there,
Propably this subject is discussed over and over several times. I did google
it too but I was a little bit surprised what I read on internet when it
comes 'when to use what'.
Most of articles I read from different experts and programmers tell me that
their "gut feelings" for using stringBuilder instead of string concatenation
is when the number of string concatunation is more then N ( N varies between
3 to max 15 from...
|
by: Richard Lewis Haggard |
last post by:
I thought that the whole point of StringBuilder was that it was supposed to
be a faster way of building strings than string. However, I just put
together a simple little application to do a comparative analysis between
the two and, surprisingly, string seems to out perform StringBuilder by a
significant amount. A string concatenation takes not quite twice as long
using StringBuilder than it does with a string. This doesn't sound right to...
|
by: Larry Hastings |
last post by:
This is such a long posting that I've broken it out into sections.
Note that while developing this patch I discovered a Subtle Bug
in CPython, which I have discussed in its own section below.
____________
THE OVERVIEW
I don't remember where I picked it up, but I remember reading years
ago that the simple, obvious Python approach for string concatenation:
x = "a" + "b"
|
by: =?Utf-8?B?RWxlbmE=?= |
last post by:
I am surprised to discover that c# automatically converts an integer to a
string when concatenating with the "+" operator. I thought c# was supposed
to be very strict about types. Doesn't it seem like c# is breaking its own
rules?
This works:
int b = 32;
string a = "ABC " + b;
Result: a = "ABC 32"
|
by: raylopez99 |
last post by:
StringBuilder better and faster than string for adding many strings.
Look at the below. It's amazing how much faster StringBuilder is than
string.
The last loop below is telling: for adding 200000 strings of 8 char
each, string took over 25 minutes while StringBuilder took 40
milliseconds!
Can anybody explain such a radical difference?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |