English 中文(简体)
什么时候能够使一夫一妻无效?
原标题:When can argv[0] have null?
  • 时间:2010-05-08 13:03:05
  •  标签:
  • c
  • argv

我理解的是,从指挥线向主(主(主)提出的论点是,增(机)的最低价值为1,而机(0)总是有方案名称及其路线。

如果在指挥线提供论据,那么Argc的数值将大于1,而Argv1至argv[argc-1]则有这些论点。

http://publications.gbdirect.co.uk/c_book/ Chapter10/arguments_to_main.html” rel=“noreferer”>。

argv[0]将包含有节目名称的插图,如果无法提供,则无序号<>。

如今,如何和何时能使遗嘱失效? 我指的是方案名称及其途径总是可以提供,以便何时可以取消?

撰稿人说,“如果没有”但何时和如何不可能提供方案名称?

最佳回答

编号exec 电话: 姓名可执行<>/em> 电话,可单独安排,然后由法国国家航天中心提供。

但这一引文实际上来自ISO标准(可能已经过时),该标准涵盖范围很广的执行环境,从最小的微观控制器到最新的z10企业级。

其中许多嵌入式系统将处于可执行的名称毫无意义的情况下。

根据最新的C1x草案:

<代码>argc 不得否定。

数值<代码>argv [argc]应为无效点。

如果<代码>argc的价值大于0,则各阵列成员通过<代码>argv[0] 而[argc-1] 包容性应载有指示数,在方案启动之前,由东道环境给予这些指示数。

这意味着,如果<代码>argc为零(而且可以是),则“NUL”。

但是,即便在<代码>argc上,not 页: 1

如果<代码>argc值大于零,则由<代码>argv[0]<>>>>标明的符号代表方案名称;argv[0][0],如果方案名称无法从东道环境获得,即为无效。 如果<代码>argc的数值大于1,则由<代码>argvl标明。 通过<代码>argv[argc-1],代表方案参数。

因此,在标准中没有要求提供方案名称。 我看到一些方案在这种价值上采用多种选择:

  • no value at all (for supposed security).
  • a blatant lie (such as sleep for a malicious piece of code).
  • the actual program name (such as sleep).
  • a slightly modified one (such as -ksh for the login shell).
  • a descriptive name (e.g., progname - a program for something).
问题回答

www.un.org/Depts/DGACM/index_spanish.htm 缩略语

#define _XOPEN_SOURCE 700
#include <unistd.h>

int main(void) {
    char *argv[] = {NULL};
    char *envp[] = {NULL};
    execve("callee.out", argv, envp);
}

页: 1

#include <stdio.h>

int main(int argc, char **argv) {
    if (argc == 0 && argv[0] == NULL)
        puts("yup");
}

然后:

gcc -ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic -o caller.out 注
gcc -ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic -o callee.out 页: 1
./caller.out

产出:

yup

www.un.org/Depts/DGACM/index_spanish.htm 用空洞理由清单检验现有方案

这里是一条走一条道路的包 wrap,它作为毫无动力的指挥:

电话:1.c

#include <unistd.h>
#include <stdio.h>

int main(int argc, char**argv) {
    char *empty[] = {NULL};
    execve(argv[1], empty, empty);

}

样本使用:

./caller-any.out /bin/ls

GNU 核心工具,如<代码>ls 但是,如以下网址所示,对<代码>argv[0]NUL进行了核对:。 为什么外部系统在没有任何有利论点的情况下使用“/bin/sh”而不是“/bin/ls”?ls输出:

A NULL argv[0] was passed through an exec system call.
Aborted (core dumped)

在乌班图19.04试验。

有可能想象方案没有名称的平台,或许该守则只是在启动时装满。 在这些问题上,我可以认为是民族解放军。 《标准》当然允许零的增量价值,并说“财富”应为“民族解放军”。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...