LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2017, 11:26 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 1,031

Rep: Reputation: 45
I can't find "errno"


I have been trying to find why a nasm sys_open followed by a sys_write do not work (pure nasm 64 in Debian 7). I know the handle or FD is returned in register RAX at the conclusion of the open or an error code of -1 if it did not work. The info also tells me that I should find the variable ERRNO to find what error has taken place but I just cannot find how to do this (the file was successfully opened with 0 byte but I cannot repeat what I did). RAX returns -1 after the unsuccessful OPEN (it did return -2 -17 in previous tries.)

I can use code that worked in other cases but it is a bit pointless if I do not have a clear understanding of what I am doing, hence my desire to solve the error problem rather than solving the buggy code (mode-permissions). I found a list of the errors and their meaning. I know very little about C programming.

Can anyone give a hint?

Thank you for your help.
 
Old 10-12-2017, 12:49 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,277

Rep: Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994
On system-call level there is no errno. If EAX/RAX register contains a value between -4095 and -1 then it is an error code. You can take it's 2-complement value (-EAX/-RAX) to get the positive EWHATEVER error code from errno.h
 
2 members found this post helpful.
Old 10-13-2017, 06:45 AM   #3
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 1,031

Original Poster
Rep: Reputation: 45
Thank you for the answer.
So having had rax return -1, -2 and -17 (as explained in my 1st post) I found the 2 complement results as follows:
-1 = 11 = 3 = error code 3 = #define ESRCH 3 /* No such process */
-2 = 110 = 6 = error code 6 = #define ENXIO 6 /* No such device or address */
-17 = 101111 = 47 = error code 47 = #define EL3RST 47 /* Level 3 reset */

This cannot be correct. I am sure the problem is only one of access and permissions, what is wrong? I am no expert at 2 complements.

Last edited by rblampain; 10-13-2017 at 07:17 AM.
 
Old 10-13-2017, 07:59 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,277

Rep: Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994
It's easier than that:
Code:
-1 => 1 => EPERM
-2 => 2 => ENOENT
-17 => 17 => EEXIST
 
Old 10-13-2017, 08:28 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,515
Blog Entries: 4

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
To negate a number in two's complement, invert all the bits then add one.

Example:
Code:
+1     = 00000001

invert = 11111110
add-1  = 11111111

-1     = 11111111

invert = 00000000
add-1  = 00000001

+1     = 00000001
 
Old 10-13-2017, 08:39 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,277

Rep: Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994Reputation: 994
(Guess I should have written 'absolute value'. Sadly, my English is rather poor.)
 
1 members found this post helpful.
Old 10-13-2017, 10:19 PM   #7
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 1,031

Original Poster
Rep: Reputation: 45
Thank you for the clarification.

Quote:
(Guess I should have written 'absolute value'. Sadly, my English is rather poor.)
Nothing wrong with it, I thought it was your mother-tongue until you hinted it may not be. (It is not mine either)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] "net rpc" "failed to connect to ipc$ share on" or "unable to find a suitable server" larieu Linux - General 0 11-09-2014 12:45 AM
Fedora 16 Yum [Errno 14] curl#5 - "Couldn't resolve proxy" manqox Fedora 4 04-26-2012 10:37 AM
[SOLVED] GCC unable to find "errno" when compiling on Ubuntu farrukh_arshad Programming 2 12-15-2010 10:42 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration