From: Decibels <decibelshelp@charter.net>
To: john.carter@tait.co.nz
Cc: gcc-help@gcc.gnu.org
Subject: [Fwd: Re: Stdprn in GCC]
Date: Wed, 23 Oct 2002 15:21:00 -0000 [thread overview]
Message-ID: <3DB7205C.6060607@charter.net> (raw)
John Carter wrote:
>On Tue, 22 Oct 2002, David wrote:
>
>Hint 1: Clip out a small piece of code you having a problem with and send
>it and the error message you are having difficulty with to the group.
>Makes it a lot easy to give a good answer.
>
>You could do things like...
>FILE * stdprn;
>main() {
> stdprn = fopen( "/dev/lp0", "w");
>
>And it will head for the line printeer port on your machine.
>
>If you want it spooled or sent to a remote printer you have to be more
>sophisticated.
>
>You may have to chmod o+rwx /dev/lp0 for the above simplistic trick to
>work.
>
>
>
Hello, Thanks for the help.
The printer is local, works fine using CUPS. Parallel port printer on
/dev/lp0 --> printer/0
Hope I have provide more information that is helpful. Really trying to
learn.
Here is the code at bottom. Actually it is from Sams Teach Yourself C in
21 Days.
print_it.c, page 26.
If I compile it as seen I get only one error: `stdprn' undeclared (first
use in this function).
Note: Should I also have 'console line printer' enabled in the kernel,
seems to
be only for kernel messages. Otherwise printer works fine.
Using your example above I was able to change the code and get it to
compile fine.
But if I put below in the varible declaration section in main() AND in the
function varible declaration section it will compile,
_____________________________
FILE * stdprn;
stdprn = fopen( "/dev/lp0", "w");
_____________________________
but strace shows seg fault of:
open("/dev/lp0", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EBUSY (Device or
resource busy)
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
/dev/lp0 does point to my printer:
/dev/lp0 -> printers/0
If I do the same with main(), but in the function put
FILE * stdprn; in the varible declaration section and put
stdprn = fopen(....); in the function block I get a seg fault with
a different error. Both are closer than have gotten before.
open("/dev/lp0", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
open("print_it.c", O_RDONLY) = 4
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
trying the 'chmod o=rwx /dev/lp0 didn't seem to work for root
or user, just with the user I get the device busy error.
/* print_it.c from book as is */
#include <stdlib.h>
#include <stdio.h>
void do_heading(char *filename);
int line =0, page = 0;
int main( int argv, char *argc[] )
{
char buffer[256];
FILE *fp;
if( argv <2 )
{
fprintf(stderr, "\nProper Usage is: ");
fprintf(stderr, "\n\nprint_it filename.ext\n" );
return(1);
}
if (( fp = fopen( argc[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!", argc[1]);
return(1);
}
page = 0;
line = 1;
do_heading( argc[1] );
while( fgets( buffer, 256, fp ) != NULL )
{
if( line % 55 == 0 )
do_heading( argc[1] );
fprintf( stdprn, "%4d:\t%s", line++, buffer );
}
fprintf( stdprn, "\f" );
fclose(fp);
return 0;
}
/* Start function */
void do_heading( char *filename )
{
page++;
if( page > 1)
fprintf( stdprn, "\f");
fprintf( stdprn, "Page: %d, %s\n\n", page, filename );
}
Thanks, Dave
reply other threads:[~2002-10-23 22:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3DB7205C.6060607@charter.net \
--to=decibelshelp@charter.net \
--cc=gcc-help@gcc.gnu.org \
--cc=john.carter@tait.co.nz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).