Summary Day33

1. 文件管理

1,1 fcntl  函数

(1)F_SETLKW

功能与F_SETLK类似,所不同的是加不上锁并不是返回失败而是等待,直到可以加上该锁为止

(2)F_GETLK

表示试图将第三个参数描述的锁加到第一的参数指定的文件上如果能加上锁但不会去加,而是

将该锁的类型改为F_UNLCK;如果不能加上锁,则将文件中已经存在的锁信息通过第三个参数带出来,

并且将给文件进行加锁的进程号设置到第三个参数的l_pid中

1.2 stat/fstat函数

#include <sys/types.h>

#include <sys/stat.h>

#include <unisth.h>

int stat(const char *path, struct stat *buf);

int fstat(int fd, struct stat *buf);

int lstat (const char *path, stuct stat *buf);

第一个参数:文件的路劲/文件的描述符

第二个参数:结构体指针,结构体变量的地址

struct stat {

...

mode_t st_mode;//文件的类型和权限

off_t
st_size;//文件的大小

time_t 
st_mtime;//文件的最后一次修改时间

...

};

函数的功能:主要用于获取文件的详细信息

类型查找:gcc/cc  -E xxx.c -o xxx.i ,在xxx.i中查找

mode_t
undigned int

off_t
long int

time_t
long int

扩展:

#include <time.h>

char *ctime(const time_t *timep);

=>主要用于将整数类型的时间转换为字符串类型的时间

struct tm *location(const time_t *timpe);

=>主要用于将整数类型转换成结构体类型

struct tm {

int tm_sec; //秒数

int tm_min;//分钟

int tm_hour;//小时

Int tm_mady;//日

int tm_mon;//月+1

int tm_year;//年+1900

int tm_wday;//星期+1

int tm_yday;//年中的天数

int tm_isdst;//夏令时

};

1.3 access函数

#include <unistd.h>

int access(const char *pathname, int mode);

第一个参数:文件的路劲是否存在;

第二个参数:操作模式

函数的功能:

主要用于判断文件是否存在以及是否拥有指定的权限

1.4 chmod和truncate

#include <sys/stat.h>

int chmod(const char*path, mode_t mode);

int fchmode(int fd, mode_t mode);

第一个参数:文件的路劲、文件描述符

第二个参数:文件新权限如:0644

函数的功能:主要用于修改文件的权限

#include <unistd.h>

#include <sys/types.h>

int truccate(const char *path, off_t  length);

int ftrucate(int fd, off_t length);

第一个参数:文件的路劲、文件的描述符

第二个参数:文件的最新大小

函数的 功能:主要用于将指定文件大小截取指定大小

1.6 mmap/munmap函数

2. 目录管理

2.1 opendir()函数.

#Include <sys/type.h>

#Include <dirent.h>

DIR *opendir(const char *name);

DIR *fdopendir(int fd);

函数的功能:

主要用于打开参数指定的目录,成功返回指针,失败返回NULL

2.2 readdir函数

#include <dirent.h>

struct sirent *readdir(DIR *dirp);

函数功能:主要用于读取参数指定的目录中内容,成功返回结构体指针,失败返回NULL

2.3 closedir 函数

#include <sys/types.h>

#Include <dirent.h>

int closedir (DIR *dirp)

函数的功能:主要用于关闭参数指定目录

2.4 getcwd函数

#Include <unistd.h>

char *getcwd(char *buf, size_t size);

函数功能:

主要用于获取当前工作目录的绝对路径存放到buf中,buf的大小是size个字节

成功返回buf,失败返回NULL

时间: 2024-08-09 10:26:03

Summary Day33的相关文章

【HTML5】summary交互元素

1.源码 <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"/> <title>交互元素summary的使用</title> <style type="text/css"> body{ padding:5px; font-size:14px; } summary{ font-weight:bold; } </style>

HDU 4989 Summary(数学题暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 Problem Description Small W is playing a summary game. Firstly, He takes N numbers. Secondly he takes out every pair of them and add this two numbers, thus he can get N*(N - 1)/2 new numbers. Thirdl

228. Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 这个题目不难,首先对原序列进行排序,然后要注意对特殊情况的处理.同时,要掌握string类的几个重要成员函数: to_string():将数字转换为

Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary

Learning to Compare Image Patches via Convolutional Neural Networks ---  Reading Summary 2017.03.08 Target: this paper attempt to learn a geneal similarity function for comparing image patches from image data directly. There are several ways in which

三个不常用的HTML元素:&lt;details&gt;、&lt;summary&gt;、&lt;dialog&gt;

前面的话 HTML5不仅新增了语义型区块级元素及表单类元素,也新增了一些其他的功能性元素,这些元素由于浏览器支持等各种原因,并没有被广泛使用 文档描述 <details>主要用于描述文档或文档某个部分的细节,与<summary>配合使用可以为<details>定义标题.标题是可见的,用户点击标题时,显示出details [注意]这两个标签只有chrome和opera支持 <details> 该标签仅有一个open属性,用来定义details是否可见(默认为不

[LeetCode]228.Summary Ranges

题目 Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 代码 /*--------------------------------------- * 日期:2015-08-04 * 作者:SJF01

Java for LeetCode 228 Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 解题思路: JAVA实现如下: public List<String> summaryRanges(int[] nums) { List

Summary Ranges —— LeetCode

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 题目大意:给一个有序数组,返回连续的区间范围. public class Solution { public List<String>

Summary: Binary Search

Iterative ways: 1 int binarySearch (int[] a, int x) { 2 int low = 0; 3 int high = a.length - 1; 4 int mid; 5 6 while (low <= high) { 7 mid = (low + high) / 2; 8 if (a[mid] < x) { 9 low = mid + 1; 10 } 11 else if (a[mid] > x) { 12 high = mid - 1;