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 2467 rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Keith Thompson <ks***@mib.orgw rote:
>rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Keith Thompson <ks***@mib.orgw rote: CBFalconer <cb********@yah oo.comwrites:
Phlip wrote: 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".
Not so; a strictly conforming program may itself define open().
Of course, but how does that disagree with what I wrote?
It means that open() may not exist for any strictly-C program.
Of course. Again, how does that disagree with what I wrote?
What a C implementation _may_ do is declaring open() in a non-Standard
header, since #including such a header renders a program not strictly
conforming anyway.
Right. On POSIX systems, open() is declared in <fcntl.h>.
So open() is not actually in the _C_ implementation, but in the _POSIX_
implementation.
Which is (or at least may be) part of the C implementation. It's an
*extension*. It's an additional library function that doesn't alter
the behavior of any strictly conforming program. It is therefore
something that a conforming C implementation is allowed to have.
--
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" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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')
|
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...
|
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.
|
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() {
|
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
| |
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
|
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...
|
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
|
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:
|
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
|
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: 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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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
| |