Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3239136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:56:04+00:00 2026-05-17T17:56:04+00:00

My sysopen fails: sysopen(DEV, /dev/ttyS0, O_NONBLOCK|O_RDONLY) returns 1, which is a success! Then, why

  • 0

My sysopen fails:

sysopen(DEV, "/dev/ttyS0", O_NONBLOCK|O_RDONLY)

returns 1, which is a success! Then, why does $! have the error “Illegal seek” in it (where it is undef before the call)

before sysopen $!:
after sysopen $!: Illegal seek

EDIT:
Here is the full script: (using the actual O_NONBLOCK|O_RDONLY value 2048)

 #!/usr/bin/perl -w
 use Device::SerialPort;
 my $ob;

 $ob = new Device::SerialPort("/dev/ttyS0");

 print $!, "\n";
 $! = 0;

 my $ret = sysopen(DEV, "/dev/ttyS0", 2048);

 print $!, "\n";
 $! = 0;

 print "ret from sysopen: ", $ret, "\n";
 #my $dev = <DEV>;

which prints out:
./filehandle.pl
Illegal seek
Illegal seek
ret from sysopen: 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:56:05+00:00Added an answer on May 17, 2026 at 5:56 pm

    That’s how the C errno variable works. To quote from man errno:

    Its value is significant only when
    the return value
    of the call indicated an error (i.e., -1 from most system
    calls; -1 or NULL from most library functions); a function
    that succeeds is allowed to change errno.

    $! is just Perl’s interface to errno, and has the same behavior:

    This means that the value of $! is
    meaningful only immediately after a
    failure

    You must check the return value of sysopen to determine whether it failed. If it failed, $! will tell you why it failed, but you can’t use $! to determine whether it failed (unless the particular function you’re using is documented to set $! to 0 on success. Most don’t, including sysopen).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following Perl script outputs SUCCESS as you'd expect: use Fcntl qw(:DEFAULT :flock); sysopen(LF,
The following PHP code does exactly what I want to do. The problem is
I have a Delphi application that connects to an oracle database. When I try
I have noticed that considerably amount of questions in SO, relating to Python, are
I'm trying to write some simple test code as a demonstration of hooking the
Are the programs written on schedulers ,thread library , process management, memory management, et
In APUE section 8.3 fork function , about file sharing between parent and child
I'm in the process of cleaning up an Oracle database application. In this application,
I'm trying to fix an intermittent bug in git-svn . The problem is happening
i'm trying to make new system calls in kernel 2.6.21 and one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.