From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18258 invoked by alias); 23 Oct 2002 22:21:13 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 18249 invoked from network); 23 Oct 2002 22:21:11 -0000 Received: from unknown (HELO dc-mx11.cluster1.charter.net) (209.225.8.21) by sources.redhat.com with SMTP; 23 Oct 2002 22:21:11 -0000 Received: from [24.207.216.8] (HELO charter.net) by dc-mx11.cluster1.charter.net (CommuniGate Pro SMTP 3.5.9) with ESMTP id 13264052; Wed, 23 Oct 2002 18:21:11 -0400 Message-ID: <3DB7205C.6060607@charter.net> Date: Wed, 23 Oct 2002 15:21:00 -0000 From: Decibels User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021021 X-Accept-Language: en-us, en MIME-Version: 1.0 To: john.carter@tait.co.nz CC: gcc-help@gcc.gnu.org Subject: [Fwd: Re: Stdprn in GCC] Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2002-10/txt/msg00299.txt.bz2 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 #include 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