⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0305-0309.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:




<HTML>

<HEAD>

<TITLE>Maximum RPM (RPM):A Guide to the RPM Library API:EarthWeb Inc.-</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311054 //-->

<!-- TITLE=Maximum RPM (RPM)//-->

<!-- AUTHOR=Edward Bailey//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=21 //-->

<!-- PAGES=0305-0336 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="../ch20/0304-0304.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0310-0313.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-305"><P>Page 305</P></A>







<H3><A NAME="ch21_ 1">

Chapter 21

</A></H3>



<H2>



A Guide to the RPM <BR>Library API



</H2>





<A NAME="PAGENUM-306"><P>Page 306</P></A>





<P>In this chapter, we'll explore the functions used internally by RPM. These functions are

available for anyone to use, making it possible to add RPM functionality to new and existing

programs. Rather than continually refer to &quot;the RPM library&quot; throughout this chapter, we'll

use the name of the library's main include file&#151;rpmlib.

</P>



<H3><A NAME="ch21_ 2">

21.1. An Overview of rpmlib

</A></H3>



<P>A number of files make up rpmlib. First and foremost, of course, is the rpmlib library,

librpm.a. This library contains all the functions required to implement all the basic functions

contained in RPM.

</P>



<P>The remaining files define the various data structures, parameters, and symbols used by rpmlib:

</P>



<UL>

<LI>         rpmlib.h

<LI>         dbindex.h

<LI>         header.h

</UL>



<P>In general, rpmlib.h will always be required. When using rpmlib's header-related

functions, header.h will be required, while the database-related functions will require

dbindex.h. As each function is described in this chapter, we'll provide the function's prototype as well as the <BR>

#include statements the function requires.

</P>



<H3><A NAME="ch21_ 3">

21.2. rpmlib Functions

</A></H3>



<P>There are more than 60 different functions in rpmlib. The tasks they perform range from

low-level database record traversal to high-level package manipulation. We've grouped the

functions into different categories for easy reference.

</P>



<H4><A NAME="ch21_ 4">

21.2.1. Error Handling

</A></H4>



<P>The functions in this section perform rpmlib's basic error handling. All error handling

centers on the use of specific status codes. The status codes are defined in

rpmlib.h and are of the form RPMERR_xxx, where xxx is the name of the error.

</P>



<H4><A NAME="ch21_ 5">

21.2.1.1. rpmErrorCode()&#151;Return Error Code

</A></H4>



<P>This function returns the error code set by the last rpmlib function that failed. It should

only be used in an error callback function defined by

rpmErrorSetCallBack():

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



int  rpmErrorCode(void);



</PRE>

<!-- END CODE SNIP //--><A NAME="PAGENUM-307"><P>Page 307</P></A>



<H4>

21.2.1.2. rpmErrorString()&#151;Return Error String

</H4>



<P>This function returns the error string set by the last rpmlib function that failed. It should

only be used in an error callback function defined by

rpmErrorSetCallBack():

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



char  *rpmErrorString(void);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 6">

21.2.1.3. rpmErrorSetCallback()&#151;Set Error CallBack Function

</A></H4>



<P>This function sets the current error callback function to the error callback function passed

to it. The previous error callback function is returned:

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



rpmErrorCallBackType   rpmErrorSetCallback(rpmErrorCallBackType);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 7">

21.2.2. Getting Package Information

</A></H4>



<P>The functions described in this section are used to obtain information about a package file.

</P>



<P>Note that most information is returned in the form of a

Header structure. This data structure is widely used throughout rpmlib. We will discuss more header-related functions in

sections 21.2.13 and 21.2.14.

</P>



<H4><A NAME="ch21_ 8">

21.2.2.1. rpmReadPackageInfo()&#151;Read Package Information

</A></H4>



<P>Given an open package on fd, read in the header

and signature:

</P>



<!-- CODE //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;

#include  &lt;rpm/header.h&gt;



int  rpmReadPackageInfo(int fd,

                          Header * signatures,

                         Header * hdr);

</PRE>

<!-- END CODE //-->



<P>This function operates as expected, with both socket and pipe file descriptors passed as

fd. It is safe to use on nonseekable fds. When the function returns,

fd is left positioned at the start of the package's archive section.

</P>



<P>If either signatures or hdr is NULL, information for the

NULL parameter will not be passed back to the caller.

Otherwise, signatures and hdr will return the package's signatures and

header, respectively.

</P>



<P>This function returns the following status values:

</P>

<BLOCKQUOTE>

0&#151;Success<BR>

1&#151;Bad magic numbers found in package<BR>

2&#151;Other error<BR>

</BLOCKQUOTE>



<A NAME="PAGENUM-308"><P>Page 308</P></A>





<H4><A NAME="ch21_ 9">

21.2.2.2. rpmReadPackageHeader()&#151;Read Package Header

</A></H4>



<P>Given an open package on fd, read in the header:

</P>



<!-- CODE //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;

#include  &lt;rpm/header.h&gt;



int  rpmReadPackageHeader(int fd,

                         Header * hdr,

                          int * isSource,

                         int * major,

                         int * minor);

</PRE>

<!-- END CODE //-->



<P>This function operates as expected, with both socket and pipe file descriptors passed as

fd. It is safe on nonseekable fds. When the function returns,

fd is left positioned at the start of the package's archive section.

</P>



<P>If hdr, isSource, major, or minor is NULL, information for the

NULL parameter(s) will not be passed back to the caller. Otherwise, they will return the package's header

(hdr), information on whether the package is a source package file

(isSource), and the package format's major and minor

revision number (major and minor, respectively).

</P>



<P>This function returns the following status values:</P>



<BLOCKQUOTE>

0&#151;Success<BR>

1&#151;Bad magic numbers found in package<BR>

2&#151;Other error<BR>

</BLOCKQUOTE>



<H4><A NAME="ch21_ 10">

21.2.3. Variable Manipulation

</A></H4>



<P>The following functions are used to get, set, and interpret RPM's internal variables. The

variables are set according to various pieces of system information, as well as from

rpmrc files. They control various aspects of RPM's operation.

</P>



<P>The variables have symbolic names in the form

RPMVAR_xxx, where xxx is the name of the variable. All variable names are defined in

rpmlib.h.

</P>



<H4><A NAME="ch21_ 11">

21.2.3.1. rpmGetVar()&#151;Return Value of RPM Variable

</A></H4>



<P>This function returns the value of the variable

specified in var:

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



char  *rpmGetVar(int var);

</PRE>

<!-- END CODE SNIP //-->



<P>On error, the function returns NULL.

</P>



<A NAME="PAGENUM-309"><P>Page 309</P></A>



<H4><A NAME="ch21_ 12">

21.2.3.2. rpmGetBooleanVar()&#151;Return Boolean Value of RPM Variable

</A></H4>



<P>This function looks up the variable specified in

var and returns 0 or 1, depending on the

variable's value:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



int  rpmGetBooleanVar(int var);

</PRE>

<!-- END CODE SNIP //-->



<P>On error, the function returns 0.

</P>



<H4><A NAME="ch21_ 13">

21.2.3.3. rpmSetVar()&#151;Set Value of RPM Variable

</A></H4>



<P>This function sets the variable specified in

var to the value passed in val. It is also possible

for val to be NULL:

</P>



<!-- CODE SNIP //-->

<PRE>

#include   &lt;rpm/rpmlib.h&gt;



void  rpmSetVar(int var,

               char *val);

</PRE>

<!-- END CODE SNIP //-->



<H4><A NAME="ch21_ 14">

21.2.4. rpmrc-Related Information

</A></H4>



<P>The functions in this section are all related to

rpmrc information&#151;the rpmrc files as well as

the variables set from those files. This information also includes the architecture and operating

system information based on rpmrc file entries.

</P>



<H4><A NAME="ch21_ 15">

21.2.4.1. rpmReadConfigFiles()&#151;Read rpmrc Files

</A></H4>



<P>This function:

</P>



<!-- CODE SNIP //-->

<PRE>

#include  &lt;rpm/rpmlib.h&gt;



int  rpmReadConfigFiles(char * file,

                         char * arch,

                        char * os,

                          int building);

</PRE>

<!-- END CODE SNIP //-->



<P>reads rpmrc files according to the following rules:

</P>



<UL>

<LI>          Always read

/usr/lib/rpmrc.

<LI>          If file is specified, read it.

<LI>          If file is not specified,

read /etc/rpmrc and ~/.rpmrc.

</UL>



<P>Every rpmrc file entry is used with rpmSetVar() to set the appropriate RPM variable. Part of

the normal rpmrc file processing also includes setting the architecture and operating system

variables for the system executing this function. These default settings can be overridden by

entering architecture and/or operating system information in

arch and os, respectively. This information will still go through the normal

rpmrc translation process.

</P>



<P><CENTER>

<a href="../ch20/0304-0304.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0310-0313.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -