lseek() 应该返回文件描述符的位置.
该文件说:
成功完成后,lseek()将返回从文件开头以字节为单位的结果偏移位置.否则,返回值-1,并设置errno以指示错误.
麻烦的是,这甚至不起作用:
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
printf("size off_t: %i\n", sizeof(off_t));
off_t pos;
pos = lseek(file, (off_t)0, SEEK_CUR);
printf("pos: %lli\n", pos);
// same result for SEEK_SET and SEEK_END
pos = lseek(file, (off_t)2352, SEEK_CUR);
printf("pos: %lli\n", pos);
Run Code Online (Sandbox Code Playgroud)
这给了我:
size off_t: 8 pos: 0 pos: 0
为什么是这样?是否有使用原始I/O功能查找当前偏移的替代方法?(read,open,lseek,...)
编辑1:
我试图让这个例子更简单.
errno==49 (EADDRNOTAVAIL)当我尝试bind()在G5(大端PowerPC)上运行Mac OS X的UDP- 到127.0.0.1:47346 时,我得到了.有什么东西阻止我这样做吗?我尝试过其他地址和端口(192.168.1.2和端口47346)但没有成功.
这是我的sockaddr_in的gdb打印输出:
$1 = {
sin_len = 0 '\0',
sin_family = 2 '\002',
sin_port = 47346,
sin_addr = {
s_addr = 3232235778
},
sin_zero = "???\000\000??"
}
Run Code Online (Sandbox Code Playgroud) 我在mac OS X 10.11上面临这个问题 - 即.一些kext已经接管了我的设备,我不能声称它libusb.有可能找出哪一个?这是有问题的设备:
$ system_profiler SPUSBDataType
[...]
mEDBG CMSIS-DAP:
Product ID: 0x2145
Vendor ID: 0x03eb (Atmel Corporation)
Version: 10.00
Serial Number: ATML2323040200017792
Speed: Up to 12 Mb/sec
Manufacturer: ATMEL
Location ID: 0x14130000 / 13
Current Available (mA): 1000
Current Required (mA): 100
Extra Operating Current (mA): 0
Run Code Online (Sandbox Code Playgroud) 如何从文件权限中删除"@"字符?
Mac/OSX计算机的文件权限中的" @ "用于显示使用此文件设置扩展属性.
chmod 755 galaxy-ansible.yml但没有帮助.echo | chmod -E galaxy-ansible.yml,没有帮助(即使使用sudo).xattr -d galaxy-ansible.yml,这也没有帮助(即使使用sudo).我甚至以root用户身份执行了上述操作,仍然是'@'字符不会远离文件的权限.
[arun@MacBook-Pro-2 ~/aks/anisble] $ ls -l@ galaxy-ansible.yml
-rwxr-xr-x@ 1 arun staff 270 Dec 22 12:31 galaxy-ansible.yml
com.apple.quarantine 67
Run Code Online (Sandbox Code Playgroud)
我的〜/ aks文件夹被映射到CentOS流浪者盒子,如果我在流浪盒上,ls -l那么就不会给我'@'(因为它不是Max/OSX机器):
-rwxr-xr-x. 1 vagrant vagrant 270 Dec 22 00:12 galaxy-ansible.yml
Run Code Online (Sandbox Code Playgroud)
在我的Mac/OSX机器上,还有其他.yml文件,但那些文件权限中没有'@',所以我试图从galaxy-ansible.yml文件中删除'@'(在Mac机器上).
现在整个角色/ ..文件夹的任何文件夹/文件都有'@'字符.
-rwxr-xr-x@ 1 arun staff 1132 Dec 21 17:12 README.md
drwxr-xr-x@ 3 arun staff 102 Dec 21 17:12 defaults …Run Code Online (Sandbox Code Playgroud) 我要疯了吗?我在 x86_64 上运行它。
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC);
sleep(1);
printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC);
sleep(1);
printf("Clock: %f\n", clock() / (double)CLOCKS_PER_SEC);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这打印
时钟:0.002880
时钟:0.002968
时钟:0.003019
它显然在线路上等待了一秒钟sleep(1),但输出显然是错误的。
如果这不起作用,是否有可移植的 C 替代方案?
我正在学习汇编,我创建了一个简单的退出程序。
.section __DATA, __data
.section __TEXT, __text
.globl _main
_main:
movl $0x2000001, %eax #System call exit, offset by 0x00000
movl $1, %ebx #Exit Return code
syscall #Wakes up kernal to run the systen call
Run Code Online (Sandbox Code Playgroud)
运行文件后如何回显 $?返回 0
组装和链接命令:
as exit.asm -o exit.o
ld exit.o -e _main -o exit
./exit
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在 iOS 中使用命名管道,但在 Swift 中似乎基本上相同的代码会失败,而在 ObjectiveC 中却可以工作。
在 Swift 中,用于写入的 FileHandle 返回 nil,或者如果我使用 FileHandle(forWritingAt: URL) API,它会抛出 Permission Denied。在 Objective C 中,数据通过管道成功发送并记录。
这两个中的路径完全相同。Objective C 示例中的数据也是“hello”.data(using: .utf8),尽管传递到了函数中。
迅速
do {
try FileManager.default.removeItem(at: url)
} catch let error {
print("error deleting", error)
}
mkfifo(url.path, 0777)
DispatchQueue.main.async {
let fileHandle = FileHandle(forWritingAtPath: url.path)
fileHandle?.write("hello".data(using: .utf8)!)
}
let fileHandle = FileHandle(forReadingAtPath: url.path)
if let data = fileHandle?.availableData {
print(String(data: data, encoding: .utf8))
}
Run Code Online (Sandbox Code Playgroud)
目标C
remove(path.UTF8String);
mkfifo(path.UTF8String, 0777);
dispatch_async(dispatch_get_main_queue(), ^{
NSFileHandle *fileHandle=[NSFileHandle fileHandleForWritingAtPath: path];
[fileHandle writeData:data]; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下方法从 linux 编译:
GOOS=darwin GOARCH=386 CGO_ENABLED=0 go build .
Run Code Online (Sandbox Code Playgroud)
但它抛出错误:
cmd/go: unsupported GOOS/GOARCH pair darwin/386
Run Code Online (Sandbox Code Playgroud)
我到处看,但似乎应该支持 darwin/386
(编译 windows/386 和 linux/386 工作正常)
(编译 darwin/amd64 工作正常)
(我什至在 Windows 上试过,但错误是一样的)
我错过了什么?