473,748 Members | 4,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: programi parsing question

Scott Lurndal wrote:
>if((fd = open(_PATH_UTMP , O_RDONLY)) < 0)
The open system call is defined to return '-1' on failure, not any
negative number. So the above check is incorrect. This can
cause problems with mmap, lseek and other system calls whose return
values, if declared or cast as signed, while legal are negative.

mmap() should always be checked against MAP_FAILED, and lseek return
should always be compared with the expected value (i.e. the offset
arg for SEEK_SET, and the expected offset for the other SEEK_* variants).
Would it also cause a problem if your file descriptors go "around the horn", and
exceed some platform-specific limit, such as 0x80000000? They would "go
negative" when expressed as signed integers...
It's good practice to always test for the defined return code
(which in most cases is -1, not < 0).
Does some relatively standard .h file define a good constant there?

--
Phlip
Aug 7 '08
40 2494
On Aug 7, 3:00 pm, Phlip <phlip2...@gmai l.comwrote:
CBFalconer wrote:
Please don't delete attributions for quoted material.

If they are not important to understand one post, alone, they are still
accessible in modern newsreaders' threading systems. Nobody is stealing anyone's
verbiage.

Just don't remove them. Not removing something takes less time than
removing something.
Aug 7 '08 #11
Phlip wrote:
vi******@gmail. com wrote:
>Also note that _PATH_UTMP is an invalid identifier in standard C,
since it's reserved for the implementation.

Yet open() _is_ the implementation. It's just not (apparently) in
the narrowest C Standard.
No, open() is not in ANY C implementation.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt >
<http://c-faq.com/ (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf(C99)
<http://cbfalconer.home .att.net/download/n869_txt.bz2(C9 9, txt)
<http://www.dinkumware. com/c99.aspx (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net/wiki/C_community:com p.lang.c:Introd uction>

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Aug 7 '08 #12
Phlip wrote:
CBFalconer wrote:
>Please don't delete attributions for quoted material.

If they are not important to understand one post, alone, they
are still accessible in modern newsreaders' threading systems.
Nobody is stealing anyone's verbiage.
Among other things, they identify the writer. This enables the
reader to evaluate the accuracy. It is also easier to leave them
than to remove them.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Aug 7 '08 #13
vi******@gmail. com writes:
On Aug 7, 3:00 pm, Phlip <phlip2...@gmai l.comwrote:
>CBFalconer wrote:
Please don't delete attributions for quoted material.

If they are not important to understand one post, alone, they are still
accessible in modern newsreaders' threading systems. Nobody is stealing anyone's
verbiage.


Just don't remove them. Not removing something takes less time than
removing something.
And wading through unnecessary lengthy repetition to find the new
comments can take more time. Use some common sense. If you dont have a
threaded news reader then get one.
Aug 7 '08 #14
Phlip <ph*******@gmai l.comwrites:
CBFalconer wrote:
>Please don't delete attributions for quoted material.

If they are not important to understand one post, alone, they are
still accessible in modern newsreaders' threading systems. Nobody is
stealing anyone's verbiage.
Please leave the attribution lines alone anyway. I use a threaded
newsreader, but it's much easier to see the attribution line in the
article itself than to traverse up to the parent article (*if* it's
still on the server) and then figure out how to get back to the
article I was reading (non-trivial, since there can be multiple
responses).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 7 '08 #15
CBFalconer <cb********@yah oo.comwrites:
Phlip wrote:
>vi******@gmail. com wrote:
>>Also note that _PATH_UTMP is an invalid identifier in standard C,
since it's reserved for the implementation.

Yet open() _is_ the implementation. It's just not (apparently) in
the narrowest C Standard.

No, open() is not in ANY C implementation.
[...]

Yes, it certainly is in many C implementations . It's not defined by
the C standard, but it's allowed as an extension.

C99 4p6:

A conforming implementation may have extensions (including
additional library functions), provided they do not alter the
behavior of any strictly conforming program.

open() is one of these "additional library functions".

Your apparent belief that anything not defined by the ISO C standard
is not C is clearly contradicted by the ISO C standard itself.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 7 '08 #16
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
>CBFalconer <cb********@yah oo.comwrites:
>Phlip wrote:
>>vi******@gmail. com wrote:

Also note that _PATH_UTMP is an invalid identifier in standard C,
since it's reserved for the implementation.

Yet open() _is_ the implementation. It's just not (apparently) in
the narrowest C Standard.

No, open() is not in ANY C implementation.
[...]

Yes, it certainly is in many C implementations . It's not defined by
the C standard, but it's allowed as an extension.
In the minds of the purists, no, open() is not C and code that uses it
is not C. They often refer to these as "C-like languages".

In a group that is so tightly controlled by dogma, I think it is
imporant for you guys to get together and agree on such things, so as to
be able to present a united front to us peons.

Aug 7 '08 #17
On 7 Aug 2008 at 3:08, Phlip wrote:
Scott Lurndal wrote:
>>if((fd = open(_PATH_UTMP , O_RDONLY)) < 0)
>It's good practice to always test for the defined return code
(which in most cases is -1, not < 0).

Does some relatively standard .h file define a good constant there?
No.

Many, many standard functions - everything from readdir() to socket() to
fcntl() - follow the convention that on error they return -1 and set
errno appropriately. This isn't going to change any time soon. Checking
against -1 is therefore completely idiomatic, and a special constant
would be quite unnecessary.

Aug 7 '08 #18
Keith Thompson wrote:
CBFalconer <cb********@yah oo.comwrites:
>Phlip wrote:
>>vi******@gmail. com wrote:

Also note that _PATH_UTMP is an invalid identifier in standard C,
since it's reserved for the implementation.

Yet open() _is_ the implementation. It's just not (apparently) in
the narrowest C Standard.

No, open() is not in ANY C implementation.
[...]

Yes, it certainly is in many C implementations . It's not defined by
the C standard, but it's allowed as an extension.
Why does everyone misinterpret my concern here? It must be what I
wrote. At any point, my point is that there is usually NO reason
to use open, when fopen is guaranteed to be documented and
available.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Aug 7 '08 #19
CBFalconer <cb********@yah oo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yah oo.comwrites:
>>Phlip wrote:
vi******@gmail. com wrote:

Also note that _PATH_UTMP is an invalid identifier in standard C,
since it's reserved for the implementation.

Yet open() _is_ the implementation. It's just not (apparently) in
the narrowest C Standard.

No, open() is not in ANY C implementation.
[...]

Yes, it certainly is in many C implementations . It's not defined by
the C standard, but it's allowed as an extension.

Why does everyone misinterpret my concern here? It must be what I
wrote. At any point, my point is that there is usually NO reason
to use open, when fopen is guaranteed to be documented and
available.
You said that "open() is not in ANY C implementation" . That is simply
not true, as I explained. It's a common extension. It's not topical,
but that doesn't make it nonexistent or non-C.

<OT>
And there *are* sometimes valid reasons to use open(), which (assuming
we're talking about the POSIX open() function) has some features that
fopen() does not. With your qualification that there's *usually* no
reason to use open, you're probably right, but of course that's
off-topic.
</OT>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 8 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2180
by: Todd Moyer | last post by:
I would like to use Python to parse a *python-like* data description language. That is, it would have it's own keywords, but would have a syntax like Python. For instance: Ob1 ('A'): Ob2 ('B'): Ob3 ('D') Ob3 ('E') Ob2 ('C')
4
2308
by: silviu | last post by:
I have the following XML string that I want to parse using the SAX parser. If I remove the portion of the XML string between the <audit> and </audit> tags the SAX is parsing correctly. Otherwise SAX wouldn't do the parsing. What's wrong with this string (between <audit> and </audit> tags)? I am using SAX/Xerces 2.3.0 on Sun 8. Thanks in advance of any help. Nick Roman <?xml version="1.0" encoding="UTF-8"?> <lyr3:L3Transaction...
16
2906
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after the preload has been completed.
6
2121
by: Ulrich Vollenbruch | last post by:
Hi all! since I'am used to work with matlab for a long time and now have to work with c/c++, I have again some problems with the usage of strings, pointers and arrays. So please excuse my basic question: I want to parse a string like "3.12" to get two integers 3 and 12. I wanted to use the function STRTOK() I wrote a main- and a subfunction like: main() {
13
1986
by: 31337one | last post by:
Hello everyone, I am writing an application that uses a command line interface. It will be configurable by passing arguments on the command line. The program is going to run in windows and linux. I was wondering what most linux/windows tools use to parse arguments. Example: ls -a or ls --help
5
5516
by: bmichel | last post by:
Hey, What I'm doing is the following: - Load XML data a file - Parsing the XML data - Printing some parsed content The problem is that the script execution is stopping before all the content is parsed and printed. Maybe the PHP is out of memory after a while. That would make sense
6
5943
by: jackwootton | last post by:
Hello everyone, I understand that XML can be parsed using JavaScript using the XML Document object. However, it is possible to parse XHTML using JavaScript? I currently listen for DOMMutation events, when the events occur I access the node which was inserted or removed (event.target). There is only ever about 5 lines of XHTML nested in the node, however it would be silly for me to parse it manually using methods like hasChildNodes...
0
1512
by: Ole Nielsby | last post by:
(sorry, wrong button, here is the real post:) I'm working on a C++ parser which is to be used for various code analysis and transformation tools. (It's part of my PILS programming system which will be released as opensource in a not too distant future.) I want to do the parsing using a homebrew recursive-descent- parser-generator system (PILS Kvernbitr) which can produce
13
4511
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
13
209
by: CBFalconer | last post by:
fjblurt@yahoo.com wrote: Considering the crosspost, I won't complain about using the non-standard open in place of fopen. However it is inappropriate on comp.programming. I have renamed the two functions. I consider fooA superior. I disapprove of initialization code more complex than a simple value, such as 0, and discourage even that. fooB must generate a call to open, so it must generate code for that. That code is hidden from
0
8987
marktang
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...
0
8826
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,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8239
agi2029
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...
1
6793
isladogs
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...
0
6073
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();...
1
3303
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
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.