Xref: utzoo unix-pc.general:1710 comp.sys.att:4792 Path: utzoo!utgpu!watmath!uunet!husc6!ukma!uflorida!haven!umbc3!alex From: alex@umbc3.UMD.EDU (Alex S. Crain) Newsgroups: unix-pc.general,comp.sys.att Subject: Re: syslocal(2) on 3b1 sick? Keywords: real time clock, perror(2) Message-ID: <1370@umbc3.UMD.EDU> Date: 23 Nov 88 17:51:51 GMT References: <130@zebra.UUCP> Reply-To: alex@umbc3.UMD.EDU (Alex S. Crain) Organization: University of Maryland, Baltimore County Lines: 38 In article <130@zebra.UUCP> vern@zebra.UUCP (Vernon C. Hoxie) writes: > > I'm trying to write a program to reset the clock on the 3b1. >First, I want to be able to read the clock to see if things work. >This has to be done in the quickest time possible, so I am trying the >syslocal(2) call special to the 3b1. It has the form: > int syslocal(cmd, [, arg] >From the manual (ugh) and the syslocal.h file, I get the command to be >"SYSL_RDRTC" and the argument to be of struct rtc *x_rtc. Now: > int x = syslocal(SYSL_RDRTC, x_rtc); >gives x = -1. So I added perror("Error id"); as the next instruction >and got a "Bad address" response. syslocal wants the address of a structure, not a pointer, so the correct calling format would be: rtc x_rtc; int x = syslocal(SYSL_RDRTC, &x_rtc); This is not terribly obvious, but makes sence if you think about it long enough, keeping in mind that C uses call-by-value argument passing. > How does a system function provide a bad address. Oh! This is >an AT&T machine (:>). This is a common mistake, and is more a characteristic of C and Unix documentation than the vendor. rtx *x_rtc implies "the address of a structure" without being specific about where that address comes from. The natural response is to use a pointer in that situation, and expect the system call to return an address via the pointer. But a second glance shows that that would be impossible, because of call-by-value, and the correct method is to pass the address of an existing structure. -- :alex. Systems Programmer nerwin!alex@umbc3.umd.edu UMBC alex@umbc3.umd.edu