新聞中心
Linux C 庫(kù)(libc)是 Linux 系統(tǒng)中的一個(gè)關(guān)鍵組件,為 C 語(yǔ)言程序員提供了許多程序開(kāi)發(fā)的基礎(chǔ)功能。它負(fù)責(zé)與系統(tǒng)內(nèi)核交互,提供對(duì)文件、進(jìn)程、網(wǎng)絡(luò)通信等 I/O 操作的支持,同時(shí)也提供了各種數(shù)據(jù)結(jié)構(gòu)和算法庫(kù)。隨著時(shí)間的推移,Linux C 庫(kù)迭代發(fā)展,不斷提升性能和支持新的功能。本文將介紹 Linux C 庫(kù)的版本演變、特點(diǎn)和使用中需要注意的問(wèn)題。

創(chuàng)新互聯(lián)網(wǎng)站建設(shè)服務(wù)商,為中小企業(yè)提供做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)服務(wù),網(wǎng)站設(shè)計(jì),網(wǎng)站托管運(yùn)營(yíng)等一站式綜合服務(wù)型公司,專(zhuān)業(yè)打造企業(yè)形象網(wǎng)站,讓您在眾多競(jìng)爭(zhēng)對(duì)手中脫穎而出創(chuàng)新互聯(lián)。
linux c 庫(kù)版本演變
最早的 Linux 系統(tǒng)采用的是 Minix libc,該庫(kù)是 Minix 操作系統(tǒng)的一個(gè)變種。Linux 0.01 發(fā)布時(shí),僅自帶源代碼,用戶(hù)可以自行編譯安裝 C 庫(kù)。時(shí)至今日,Linux C 庫(kù)已經(jīng)經(jīng)歷了多個(gè)版本的演變,其中最為知名的版本是 Glibc(GNU libc)。
Glibc 是基于 GNU 項(xiàng)目的開(kāi)源 C 庫(kù),由紅帽公司維護(hù)。該庫(kù)作為現(xiàn)代 Linux 系統(tǒng)的標(biāo)準(zhǔn) C 庫(kù),具有廣泛的應(yīng)用。Glibc 最早發(fā)布于 1992 年,至今已經(jīng)更新到了版本 2.33。Glibc 2.0 在 1997 年發(fā)布,它的特點(diǎn)是提供完整的國(guó)際化方式,支持多語(yǔ)言字符集和本地化,使得 Linux 可以用于全球范圍內(nèi)的應(yīng)用程序開(kāi)發(fā)。此后,Glibc 2.x 系列迭代加入了許多新特性,包括線(xiàn)程安全、初始程序加載器(dynamic linker)和調(diào)試支持等。
除了 Glibc 外,還有其他的 C 庫(kù)版本,比如 uClibc、Musl libc 等。uClibc 最初是為嵌入式系統(tǒng)開(kāi)發(fā)設(shè)計(jì)的 C 庫(kù),它的特點(diǎn)是占用較少的內(nèi)存,適合在資源匱乏的設(shè)備上運(yùn)行。Musl libc 是一個(gè)輕量級(jí)的 C 庫(kù),主要與其他 Linux 系統(tǒng)兼容,但與 Glibc 比較,Musl libc 的體積更小,啟動(dòng)速度更快,并且支持靜態(tài)鏈接。
Linux C 庫(kù)的特點(diǎn)
Linux C 庫(kù)是一個(gè)重要的系統(tǒng)組件,它有以下幾個(gè)特點(diǎn):
1.提供了 C 語(yǔ)言開(kāi)發(fā)的基礎(chǔ)支持
Linux C 庫(kù)為 C 語(yǔ)言開(kāi)發(fā)提供了標(biāo)準(zhǔn)的 I/O、內(nèi)存管理、文件操作、進(jìn)程管理等基礎(chǔ)功能,大大降低了開(kāi)發(fā)者的工作量,提高了生產(chǎn)效率。
2.與系統(tǒng)內(nèi)核緊密配合
Linux C 庫(kù)是用戶(hù)空間與內(nèi)核空間之間的橋梁,負(fù)責(zé)將用戶(hù)程序的請(qǐng)求轉(zhuǎn)換為系統(tǒng)調(diào)用傳遞給內(nèi)核,同時(shí)將內(nèi)核返回的結(jié)果轉(zhuǎn)化為可讀寫(xiě)的格式返回給用戶(hù)程序。因此 Linux C 庫(kù)與內(nèi)核的版本需要保持一致。
3.對(duì)多線(xiàn)程程序提供支持
隨著多核心處理器的普及,支持多線(xiàn)程的程序越來(lái)越受到關(guān)注。Linux C 庫(kù)提供了多線(xiàn)程編程的接口和相關(guān)函數(shù),支持線(xiàn)程同步和互斥,保障了多線(xiàn)程程序的可靠性。
4.具有良好的擴(kuò)展性
Linux C 庫(kù)是開(kāi)源軟件,它可以被自由地修改和擴(kuò)展。用戶(hù)可以根據(jù)需要在庫(kù)中添加自己的函數(shù)和接口,以適應(yīng)自己的應(yīng)用需求。
Linux C 庫(kù)的使用注意事項(xiàng)
雖然 Linux C 庫(kù)為開(kāi)發(fā)者提供了許多便捷的功能和接口,但在使用過(guò)程中還有一些需要注意的問(wèn)題。下面是一些常見(jiàn)的注意事項(xiàng):
1.版本問(wèn)題
Linux C 庫(kù)與系統(tǒng)內(nèi)核密切相關(guān),用戶(hù)應(yīng)該根據(jù)系統(tǒng)內(nèi)核版本來(lái)選擇對(duì)應(yīng)的 C 庫(kù)版本。如果版本不匹配,可能會(huì)導(dǎo)致程序異?;虮罎?。
2.動(dòng)態(tài)鏈接和靜態(tài)鏈接
Linux C 庫(kù)的鏈接方式有兩種:動(dòng)態(tài)鏈接和靜態(tài)鏈接。動(dòng)態(tài)鏈接是在運(yùn)行時(shí)將庫(kù)文件載入內(nèi)存,并與程序動(dòng)態(tài)鏈接。靜態(tài)鏈接則是將庫(kù)文件編譯進(jìn)可執(zhí)行程序中。動(dòng)態(tài)鏈接的優(yōu)點(diǎn)是共享庫(kù),可以減少內(nèi)存的使用,但也有一定的安全風(fēng)險(xiǎn)。靜態(tài)鏈接的優(yōu)點(diǎn)是程序獨(dú)立運(yùn)行,可移植性好,但會(huì)增加可執(zhí)行程序的大小和編譯時(shí)間。
3.編譯選項(xiàng)
Linux C 庫(kù)的編譯選項(xiàng)非常豐富,包括優(yōu)化選項(xiàng)、調(diào)試選項(xiàng)、安全選項(xiàng)等。用戶(hù)應(yīng)該根據(jù)自己的需求選擇適當(dāng)?shù)木幾g選項(xiàng),以確保程序的性能和安全性。
結(jié)論
Linux C 庫(kù)是一個(gè)關(guān)鍵的系統(tǒng)組件,它為 C 語(yǔ)言程序員提供了許多基礎(chǔ)功能和接口。常見(jiàn)的 Linux C 庫(kù)版本有 Glibc、uClibc、Musl libc 等,它們具有不同的特點(diǎn)和優(yōu)缺點(diǎn)。在使用 Linux C 庫(kù)時(shí),用戶(hù)需要注意版本問(wèn)題、鏈接方式、編譯選項(xiàng)等問(wèn)題,以確保程序的正確性、可靠性和性能。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián)為您提供網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù)!
求Linux c版 ini文件解析 庫(kù)或者代碼
下面是一個(gè)VB6的類(lèi)的源代碼,來(lái)自國(guó)外網(wǎng)站的一個(gè)技術(shù)專(zhuān)家,類(lèi)名:CSetting,可以讀寫(xiě)ini配置文件,或者賣(mài)行賣(mài)讀寫(xiě)注冊(cè)表配帶掘置。
Option Explicit
‘Settings interface class
‘Copyright ?Stan Schultes
‘Written for VBPJ Getting Started September, 2023
‘CSetting mode enum
Public Enum csModes
csModeRegistry = 0
csModeINI = 1
End Enum
‘class member variables
Private m_eSaveMode As csModes
‘module-level variables
Private msININame As String’name of .INI file
Private msAppName As String’app name for settings
‘INI setting APIs
Private Declare Function GetPrivateProfileInt Lib “kernel32” Alias “GetPrivateProfileIntA” (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As Long, ByVal FileName As String) As Long
Private Declare Function GetPrivateProfileString Lib “kernel32” Alias “中逗GetPrivateProfileStringA” (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As String, ByVal ReturnedString As String, ByVal StringSize As Long, ByVal FileName As String) As Long
Private Declare Function WritePrivateProfileString Lib “kernel32” Alias “WritePrivateProfileStringA” (ByVal SectionName As String, ByVal KeyName As String, ByVal KeyValue As String, ByVal FileName As String) As Long
‘there is no WritePrivateProfileInt declaration…
‘Error definitions
Private Const mklErrOffset As Long = vbObjectError + 512
Private Const mklErrNotNumeric As Long = mklErrOffset + 1
Private Const mksErrNotNumeric As String = “The setting value returned was not numeric”
Private Const mklErrWriting As Long = mklErrOffset + 2
Private Const mksErrWriting As String = “Error writing Setting “
Private Const mklErrReading As Long = mklErrOffset + 3
Private Const mksErrReading As String = “Error reading Setting “
Public Function Init(Optional ByVal AppPath As String, Optional ByVal AppName As Variant, Optional ByVal Mode As csModes = csModeRegistry)
‘Set up class variables, default to Registry mode
If IsMissing(AppPath) Then
msININame = App.Path
Else
msININame = Trim$(AppPath)
End If
If IsMissing(AppName) Then
msAppName = App.EXEName
Else
msAppName = Trim$(AppName)
End If
‘default to the app’s .exe path
msININame = msININame & “\” & msAppName & “.ini”
‘ msININame = App.Path & “\” & msAppName & “.ini”
SaveMode = Mode
End Function
Public Function GetSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As String) As String
‘returns a string setting
Dim lRet As Long
Dim sBuf As String * 128
On Error GoTo GetSettingStr_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
GetSettingStr = GetSetting(msAppName, Section, KeyName, DefaultValue)
Case Else
lRet = GetPrivateProfileString(Section, KeyName, DefaultValue, sBuf, Len(sBuf), msININame)
GetSettingStr = TrimNull(sBuf)
End Select
GetSettingStr_Exit:
Exit Function
GetSettingStr_Error:
Err.Raise mklErrReading, “CSetting.GetSettingStr”, mksErrReading & “(” & Err & “, ” & Error & “)”
End Function
Public Function GetSettingInt(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As Integer) As Integer
‘returns a numeric setting
Dim sSetting As String
On Error GoTo GetSettingInt_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
sSetting = GetSetting(msAppName, Section, KeyName, CStr(DefaultValue))
‘check if value is numeric
If IsNumeric(sSetting) Then
GetSettingInt = CInt(sSetting)
Else
‘match behavior of .INI return
GetSettingInt = 0
‘or – return error if desired
‘On Error GoTo’disable handler to return error
‘Err.Raise mklErrNotNumeric, “CSetting.GetSettingInt”, mksErrNotNumeric
End If
Case Else
‘returns 0 if not numeric
GetSettingInt = GetPrivateProfileInt(Section, KeyName, DefaultValue, msININame)
End Select
GetSettingInt_Exit:
Exit Function
GetSettingInt_Error:
Err.Raise mklErrReading, “CSetting.GetSettingInt”, mksErrReading & “(” & Err & “, ” & Error & “)”
End Function
Public Sub SaveSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal Setting As String)
‘saves a string setting
Dim lRet As Long
On Error GoTo SaveSettingStr_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
SaveSetting msAppName, Section, KeyName, Setting
Case Else
lRet = WritePrivateProfileString(Section, KeyName, Setting, msININame)
End Select
SaveSettingStr_Exit:
Exit Sub
SaveSettingStr_Error:
Err.Raise mklErrWriting, “CSetting.SaveSettingStr”, mksErrWriting & “(” & Err & “, ” & Error & “)”
End Sub
Public Sub SaveSettingInt(ByVal Section As String, ByVal KeyName As String, Setting As Integer)
‘saves a numeric setting
Dim lRet As Long
On Error GoTo SaveSettingInt_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
SaveSetting msAppName, Section, KeyName, CStr(Setting)
Case Else
lRet = WritePrivateProfileString(Section, KeyName, CStr(Setting), msININame)
End Select
SaveSettingInt_Exit:
Exit Sub
SaveSettingInt_Error:
Err.Raise mklErrWriting, “CSetting.SaveSettingInt”, mksErrWriting & “(” & Err & “, ” & Error & “)”
End Sub
Public Property Let SaveMode(Mode As csModes)
‘sets save mode, see csModes enum
m_eSaveMode = Mode
End Property
Public Property Get SaveMode() As Long
‘returns save mode
SaveMode = CLng(m_eSaveMode)
End Property
Private Function TrimNull(ByVal InString As String) As String
‘trims string at first Null character
Dim lPos As Long
TrimNull = Trim$(InString)
lPos = InStr(TrimNull, vbNullChar)
If lPos > 0 Then TrimNull = Left$(TrimNull, lPos – 1)
End Function
Private Sub Class_Initialize()
msININame = App.Path & “\” & App.EXEName & “.ini”
End Sub
使用方法:
在程序的全局模塊中定義CSetting的類(lèi)實(shí)例變量:(以下定義了兩個(gè),分別讀寫(xiě)ini和注冊(cè)表)
Public SetIni As CSetting ‘讀寫(xiě)ini配置文件參數(shù)’
Public SetReg As CSetting’讀寫(xiě)注冊(cè)表配置參數(shù)
在sub main 中初始化:(其中PATH_EXE是你的程序路徑,放ini文件的路徑)
Set SetIni = New CSetting
SetIni.Init PATH_Exe, App.Title, csModeINI
Set SetReg = New CSetting
SetReg.Init PATH_Exe, App.Title, csModeRegistry
這就可以隨便用了。
dbPassword = SetIni.GetSettingStr(NameDB, “Password”, “111111”)
dbUserID = SetIni.GetSettingStr(NameDB, “UserID”, “123456”)
dbCatalog = SetIni.GetSettingStr(NameDB, “Catalog”, “aaa”)
dbDataSource = SetIni.GetSettingStr(NameDB, “DataSource”, sky)
cnStr= “Provider=SQLOLEDB.1;Password=” & dbPassword & “;Persist Security Info=True;User ID=” & dbUserID & “;Initial Catalog=” & dbCatalog & “;Data Source=” & dbDataSource ‘
其它由你自己補(bǔ)充了。
下面是一個(gè)VB6的類(lèi)的源代碼,來(lái)自國(guó)外網(wǎng)站的一個(gè)技術(shù)專(zhuān)家,類(lèi)名:CSetting,可以讀寫(xiě)ini配置文件,或者賣(mài)行賣(mài)讀寫(xiě)注冊(cè)表配帶掘置。
Option Explicit
‘Settings interface class
‘Copyright ?Stan Schultes
‘Written for VBPJ Getting Started September, 2023
‘CSetting mode enum
Public Enum csModes
csModeRegistry = 0
csModeINI = 1
End Enum
‘class member variables
Private m_eSaveMode As csModes
‘module-level variables
Private msININame As String’name of .INI file
Private msAppName As String’app name for settings
‘INI setting APIs
Private Declare Function GetPrivateProfileInt Lib “kernel32” Alias “GetPrivateProfileIntA” (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As Long, ByVal FileName As String) As Long
Private Declare Function GetPrivateProfileString Lib “kernel32” Alias “中逗GetPrivateProfileStringA” (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As String, ByVal ReturnedString As String, ByVal StringSize As Long, ByVal FileName As String) As Long
Private Declare Function WritePrivateProfileString Lib “kernel32” Alias “WritePrivateProfileStringA” (ByVal SectionName As String, ByVal KeyName As String, ByVal KeyValue As String, ByVal FileName As String) As Long
‘there is no WritePrivateProfileInt declaration…
‘Error definitions
Private Const mklErrOffset As Long = vbObjectError + 512
Private Const mklErrNotNumeric As Long = mklErrOffset + 1
Private Const mksErrNotNumeric As String = “The setting value returned was not numeric”
Private Const mklErrWriting As Long = mklErrOffset + 2
Private Const mksErrWriting As String = “Error writing Setting “
Private Const mklErrReading As Long = mklErrOffset + 3
Private Const mksErrReading As String = “Error reading Setting “
Public Function Init(Optional ByVal AppPath As String, Optional ByVal AppName As Variant, Optional ByVal Mode As csModes = csModeRegistry)
‘Set up class variables, default to Registry mode
If IsMissing(AppPath) Then
msININame = App.Path
Else
msININame = Trim$(AppPath)
End If
If IsMissing(AppName) Then
msAppName = App.EXEName
Else
msAppName = Trim$(AppName)
End If
‘default to the app’s .exe path
msININame = msININame & “\” & msAppName & “.ini”
‘ msININame = App.Path & “\” & msAppName & “.ini”
SaveMode = Mode
End Function
Public Function GetSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As String) As String
‘returns a string setting
Dim lRet As Long
Dim sBuf As String * 128
On Error GoTo GetSettingStr_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
GetSettingStr = GetSetting(msAppName, Section, KeyName, DefaultValue)
Case Else
lRet = GetPrivateProfileString(Section, KeyName, DefaultValue, sBuf, Len(sBuf), msININame)
GetSettingStr = TrimNull(sBuf)
End Select
GetSettingStr_Exit:
Exit Function
GetSettingStr_Error:
Err.Raise mklErrReading, “CSetting.GetSettingStr”, mksErrReading & “(” & Err & “, ” & Error & “)”
End Function
Public Function GetSettingInt(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As Integer) As Integer
‘returns a numeric setting
Dim sSetting As String
On Error GoTo GetSettingInt_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
sSetting = GetSetting(msAppName, Section, KeyName, CStr(DefaultValue))
‘check if value is numeric
If IsNumeric(sSetting) Then
GetSettingInt = CInt(sSetting)
Else
‘match behavior of .INI return
GetSettingInt = 0
‘or – return error if desired
‘On Error GoTo’disable handler to return error
‘Err.Raise mklErrNotNumeric, “CSetting.GetSettingInt”, mksErrNotNumeric
End If
Case Else
‘returns 0 if not numeric
GetSettingInt = GetPrivateProfileInt(Section, KeyName, DefaultValue, msININame)
End Select
GetSettingInt_Exit:
Exit Function
GetSettingInt_Error:
Err.Raise mklErrReading, “CSetting.GetSettingInt”, mksErrReading & “(” & Err & “, ” & Error & “)”
End Function
Public Sub SaveSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal Setting As String)
‘saves a string setting
Dim lRet As Long
On Error GoTo SaveSettingStr_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
SaveSetting msAppName, Section, KeyName, Setting
Case Else
lRet = WritePrivateProfileString(Section, KeyName, Setting, msININame)
End Select
SaveSettingStr_Exit:
Exit Sub
SaveSettingStr_Error:
Err.Raise mklErrWriting, “CSetting.SaveSettingStr”, mksErrWriting & “(” & Err & “, ” & Error & “)”
End Sub
Public Sub SaveSettingInt(ByVal Section As String, ByVal KeyName As String, Setting As Integer)
‘saves a numeric setting
Dim lRet As Long
On Error GoTo SaveSettingInt_Error
If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
SaveSetting msAppName, Section, KeyName, CStr(Setting)
Case Else
lRet = WritePrivateProfileString(Section, KeyName, CStr(Setting), msININame)
End Select
SaveSettingInt_Exit:
Exit Sub
SaveSettingInt_Error:
Err.Raise mklErrWriting, “CSetting.SaveSettingInt”, mksErrWriting & “(” & Err & “, ” & Error & “)”
End Sub
Public Property Let SaveMode(Mode As csModes)
‘sets save mode, see csModes enum
m_eSaveMode = Mode
End Property
Public Property Get SaveMode() As Long
‘returns save mode
SaveMode = CLng(m_eSaveMode)
End Property
Private Function TrimNull(ByVal InString As String) As String
‘trims string at first Null character
Dim lPos As Long
TrimNull = Trim$(InString)
lPos = InStr(TrimNull, vbNullChar)
If lPos > 0 Then TrimNull = Left$(TrimNull, lPos – 1)
End Function
Private Sub Class_Initialize()
msININame = App.Path & “\” & App.EXEName & “.ini”
End Sub
使用方法:
在程序的全局模塊中定義CSetting的類(lèi)實(shí)例變量:(以下定義了兩個(gè),分別讀寫(xiě)ini和注冊(cè)表)
Public SetIni As CSetting ‘讀寫(xiě)ini配置文件參數(shù)’
Public SetReg As CSetting’讀寫(xiě)注冊(cè)表配置參數(shù)
在sub main 中初始化:(其中PATH_EXE是你的程序路徑,放ini文件的路徑)
Set SetIni = New CSetting
SetIni.Init PATH_Exe, App.Title, csModeINI
Set SetReg = New CSetting
SetReg.Init PATH_Exe, App.Title, csModeRegistry
這就可以隨便用了。
dbPassword = SetIni.GetSettingStr(NameDB, “Password”, “111111”)
dbUserID = SetIni.GetSettingStr(NameDB, “UserID”, “123456”)
dbCatalog = SetIni.GetSettingStr(NameDB, “Catalog”, “aaa”)
dbDataSource = SetIni.GetSettingStr(NameDB, “DataSource”, sky)
cnStr= “Provider=SQLOLEDB.1;Password=” & dbPassword & “;Persist Security Info=True;User ID=” & dbUserID & “;Initial Catalog=” & dbCatalog & “;Data Source=” & dbDataSource ‘
其它由你自己補(bǔ)充了。
ini文件的內(nèi)容大致什么樣子?
這兆頌個(gè)要給運(yùn)前分,前面的族悄鄭都答非所問(wèn)
關(guān)于linux c 庫(kù)版本的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
創(chuàng)新互聯(lián)-老牌IDC、云計(jì)算及IT信息化服務(wù)領(lǐng)域的服務(wù)供應(yīng)商,業(yè)務(wù)涵蓋IDC(互聯(lián)網(wǎng)數(shù)據(jù)中心)服務(wù)、云計(jì)算服務(wù)、IT信息化、AI算力租賃平臺(tái)(智算云),軟件開(kāi)發(fā),網(wǎng)站建設(shè),咨詢(xún)熱線(xiàn):028-86922220
分享文章:LinuxC庫(kù)版本探究(linuxc庫(kù)版本)
本文路徑:http://www.dlmjj.cn/article/djoceoe.html


咨詢(xún)
建站咨詢(xún)
